From: Timo Sirainen Date: Mon, 17 Mar 2014 14:57:36 +0000 (+0200) Subject: test-var-expand: Added more unit tests for %variable offsets/lengths. X-Git-Tag: 2.2.13.rc1~203 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1bc529e36d36f9a525c6af023ae014ebc6cdb440;p=thirdparty%2Fdovecot%2Fcore.git test-var-expand: Added more unit tests for %variable offsets/lengths. --- diff --git a/src/lib/test-var-expand.c b/src/lib/test-var-expand.c index 52fbf5fabb..5521e6a642 100644 --- a/src/lib/test-var-expand.c +++ b/src/lib/test-var-expand.c @@ -16,6 +16,33 @@ struct var_get_key_range_test { unsigned int idx, size; }; +static void test_var_expand_ranges(void) +{ + static struct var_expand_test tests[] = { + { "%v", "value1234" }, + { "%3v", "val" }, + { "%3.2v", "ue" }, + { "%3.-2v", "ue12" }, + { "%-3.2v", "23" }, + { "%0.-1v", "value123" }, + { "%-4.-1v", "123" } + }; + static struct var_expand_table table[] = { + { 'v', "value1234", NULL }, + { '\0', NULL, NULL } + }; + string_t *str = t_str_new(128); + unsigned int i; + + test_begin("var_expand"); + for (i = 0; i < N_ELEMENTS(tests); i++) { + str_truncate(str, 0); + var_expand(str, tests[i].in, table); + test_assert(strcmp(tests[i].out, str_c(str)) == 0); + } + test_end(); +} + static void test_var_expand_builtin(void) { static struct var_expand_test tests[] = { @@ -75,6 +102,7 @@ static void test_var_get_key_range(void) void test_var_expand(void) { + test_var_expand_ranges(); test_var_expand_builtin(); test_var_get_key_range(); }