summaryrefslogtreecommitdiff
path: root/src/test/test-strv.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-11-27 22:37:52 +0100
committerLennart Poettering <lennart@poettering.net>2013-11-28 18:42:18 +0100
commit70f75a523b16ad495a7791d595ee3eececf75953 (patch)
tree1ee6c3161a45a58ab58ef8627de43394a6c4eef1 /src/test/test-strv.c
parentfb1454005dda75cdab5795285a8607237033d6a8 (diff)
util: fix handling of trailing whitespace in split_quoted()
Inspired by a patch by Lukas Nykryn.
Diffstat (limited to 'src/test/test-strv.c')
-rw-r--r--src/test/test-strv.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/test/test-strv.c b/src/test/test-strv.c
index e46885902b..068e421097 100644
--- a/src/test/test-strv.c
+++ b/src/test/test-strv.c
@@ -143,6 +143,7 @@ static void test_strv_quote_unquote(const char* const *split, const char *quoted
char **t;
p = strv_join_quoted((char **)split);
+ assert_se(p);
printf("-%s- --- -%s-\n", p, quoted); /* fprintf deals with NULL, puts does not */
assert_se(p);
assert_se(streq(p, quoted));
@@ -156,6 +157,20 @@ static void test_strv_quote_unquote(const char* const *split, const char *quoted
}
}
+static void test_strv_quote_unquote2(const char *quoted, const char ** list) {
+ _cleanup_strv_free_ char **s;
+ unsigned i = 0;
+ char **t;
+
+ s = strv_split_quoted(quoted);
+ assert_se(s);
+
+ STRV_FOREACH(t, s)
+ assert_se(streq(list[i++], *t));
+
+ assert_se(list[i] == NULL);
+}
+
static void test_strv_split(void) {
char **s;
unsigned i = 0;
@@ -405,6 +420,18 @@ int main(int argc, char *argv[]) {
test_strv_quote_unquote(input_table_quotes, QUOTES_STRING);
test_strv_quote_unquote(input_table_spaces, SPACES_STRING);
+ test_strv_quote_unquote2(" foo=bar \"waldo\" zzz ", (const char*[]) { "foo=bar", "waldo", "zzz", NULL });
+ test_strv_quote_unquote2("", (const char*[]) { NULL });
+ test_strv_quote_unquote2(" ", (const char*[]) { NULL });
+ test_strv_quote_unquote2(" ", (const char*[]) { NULL });
+ test_strv_quote_unquote2(" x", (const char*[]) { "x", NULL });
+ test_strv_quote_unquote2("x ", (const char*[]) { "x", NULL });
+ test_strv_quote_unquote2(" x ", (const char*[]) { "x", NULL });
+ test_strv_quote_unquote2(" \"x\" ", (const char*[]) { "x", NULL });
+ test_strv_quote_unquote2(" \'x\' ", (const char*[]) { "x", NULL });
+ test_strv_quote_unquote2(" \'x\"\' ", (const char*[]) { "x\"", NULL });
+ test_strv_quote_unquote2(" \"x\'\" ", (const char*[]) { "x\'", NULL });
+
test_strv_split();
test_strv_split_newlines();
test_strv_split_nulstr();