summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2013-03-03 15:53:08 +0100
committerArthur de Jong <arthur@arthurdejong.org>2013-03-03 15:54:15 +0100
commit8655355b399127b7771fab6623de3bcc89984e10 (patch)
treeec63b9d5e633ed40d2ab3791e9e7364c1244b7ac
parent6c05b7607294b943d8d01d9e282a8b2fec8616a9 (diff)
add tests for trimming expressions
-rw-r--r--tests/test_expr.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/tests/test_expr.c b/tests/test_expr.c
index ed86a6c..3f4e157 100644
--- a/tests/test_expr.c
+++ b/tests/test_expr.c
@@ -2,7 +2,7 @@
test_expr.c - simple tests for the expr module
This file is part of the nss-pam-ldapd library.
- Copyright (C) 2009, 2011, 2012 Arthur de Jong
+ Copyright (C) 2009, 2011, 2012, 2013 Arthur de Jong
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -52,6 +52,8 @@ static const char *expanderfn(const char *name, void UNUSED(*expander_attr))
return "";
if (strcmp(name, "null") == 0)
return NULL;
+ if (strcmp(name, "userPassword") == 0)
+ return "{crypt}HASH";
else
return "foobar";
}
@@ -91,6 +93,17 @@ static void test_expr_parse(void)
assertstreq(buffer, "afoobarbfoobarec");
assert(expr_parse("a${test1}b${test2:+${empty:-d$test4}e}c", buffer, sizeof(buffer), expanderfn, NULL) != NULL);
assertstreq(buffer, "afoobarbdfoobarec");
+ /* test ${var#trim} functions */
+ assert(expr_parse("${test1#foo}", buffer, sizeof(buffer), expanderfn, NULL) != NULL);
+ assertstreq(buffer, "bar");
+ assert(expr_parse("${test1#zoo}", buffer, sizeof(buffer), expanderfn, NULL) != NULL);
+ assertstreq(buffer, "foobar");
+ assert(expr_parse("${test1#?oo}", buffer, sizeof(buffer), expanderfn, NULL) != NULL);
+ assertstreq(buffer, "bar");
+ assert(expr_parse("${test1#f\\?o}", buffer, sizeof(buffer), expanderfn, NULL) != NULL);
+ assertstreq(buffer, "foobar");
+ assert(expr_parse("${userPassword#{crypt\\}}", buffer, sizeof(buffer), expanderfn, NULL) != NULL);
+ assertstreq(buffer, "HASH");
/* these are errors */
assert(expr_parse("$&", buffer, sizeof(buffer), expanderfn, NULL) == NULL);
assert(expr_parse("${a", buffer, sizeof(buffer), expanderfn, NULL) == NULL);