Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorGiovanni Mascellani <mascellani@poisson.phc.unipi.it>2016-05-30 13:33:10 +0200
committerArthur de Jong <arthur@arthurdejong.org>2016-06-03 11:19:07 +0200
commit2ba95606dd95f68d423942b51e0e5b8d3d9ec145 (patch)
tree2bcf50013606e5d2d11bb2509fa30b6ead14bb71 /tests
parent3a4860cd1d7175e7723307c31aeda68c24ef2309 (diff)
Support substituting expresions of type ${var:offset:length}
Diffstat (limited to 'tests')
-rw-r--r--tests/test_expr.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/test_expr.c b/tests/test_expr.c
index 3f4e157..536341a 100644
--- a/tests/test_expr.c
+++ b/tests/test_expr.c
@@ -3,6 +3,7 @@
This file is part of the nss-pam-ldapd library.
Copyright (C) 2009, 2011, 2012, 2013 Arthur de Jong
+ Copyright (c) 2016 Giovanni Mascellani
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -104,6 +105,21 @@ static void test_expr_parse(void)
assertstreq(buffer, "foobar");
assert(expr_parse("${userPassword#{crypt\\}}", buffer, sizeof(buffer), expanderfn, NULL) != NULL);
assertstreq(buffer, "HASH");
+ /* test ${var:offset:length} */
+ assert(expr_parse("${test1:0:6}", buffer, sizeof(buffer), expanderfn, NULL) != NULL);
+ assertstreq(buffer, "foobar");
+ assert(expr_parse("${test1:0:10}", buffer, sizeof(buffer), expanderfn, NULL) != NULL);
+ assertstreq(buffer, "foobar");
+ assert(expr_parse("${test1:0:3}", buffer, sizeof(buffer), expanderfn, NULL) != NULL);
+ assertstreq(buffer, "foo");
+ assert(expr_parse("${test1:3:0}", buffer, sizeof(buffer), expanderfn, NULL) != NULL);
+ assertstreq(buffer, "");
+ assert(expr_parse("${test1:3:6}", buffer, sizeof(buffer), expanderfn, NULL) != NULL);
+ assertstreq(buffer, "bar");
+ assert(expr_parse("${test1:7:0}", buffer, sizeof(buffer), expanderfn, NULL) != NULL);
+ assertstreq(buffer, "");
+ assert(expr_parse("${test1:7:3}", buffer, sizeof(buffer), expanderfn, NULL) != NULL);
+ assertstreq(buffer, "");
/* these are errors */
assert(expr_parse("$&", buffer, sizeof(buffer), expanderfn, NULL) == NULL);
assert(expr_parse("${a", buffer, sizeof(buffer), expanderfn, NULL) == NULL);