From 213c029eba0ebd1c354502974e2f64ea02ef74cc Mon Sep 17 00:00:00 2001 From: Marko Kreen Date: Tue, 1 Feb 2011 14:36:34 +0200 Subject: [PATCH] test_string: parse_word_list() tests --- test/test_string.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/test/test_string.c b/test/test_string.c index 8dee0e9..aac18e5 100644 --- a/test/test_string.c +++ b/test/test_string.c @@ -211,6 +211,38 @@ static void test_strlist(void *p) end:; } +static bool sl_add(void *arg, const char *s) +{ + return strlist_append(arg, s); +} + +static const char *wlist(const char *s) +{ + const char *res = "FAIL"; + struct StrList *sl = strlist_new(USUAL_ALLOC); + bool ok = parse_word_list(s, sl_add, sl); + if (ok) { + if (strlist_empty(sl)) + res = "-"; + else + res = lshow(sl); + } + strlist_free(sl); + return res; +} + +static void test_wlist(void *p) +{ + str_check(wlist("1,2,3"), "1,2,3"); + str_check(wlist(" 1 , \n 2 \t , \t3"), "1,2,3"); + str_check(wlist(" 1 "), "1"); + str_check(wlist(" 1 ,"), "1"); + str_check(wlist(", 1 "), "1"); + str_check(wlist("1 2"), "1 2"); + str_check(wlist(" "), ""); +end:; +} + /* * Describe */ @@ -223,6 +255,7 @@ struct testcase_t string_tests[] = { { "basename", test_basename }, { "dirname", test_dirname }, { "strlist", test_strlist }, + { "parse_wordlist", test_wlist }, END_OF_TESTCASES }; -- 2.39.5