X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fstring%2Ftest%2Frun.c;h=089bfd3e4fda6a72be3f157b3a1ca60617b71d0c;hp=fded0e49a3ebde3044ea9270cd02688055a7f0c3;hb=458c48e8b27a2eff90b51610e86a870e103a28ad;hpb=650c775ff00cccd03fc84e7789a03c51d9839004 diff --git a/ccan/string/test/run.c b/ccan/string/test/run.c index fded0e49..089bfd3e 100644 --- a/ccan/string/test/run.c +++ b/ccan/string/test/run.c @@ -1,6 +1,7 @@ +#include "string/string.h" #include #include -#include "string/string.h" +#include "string/string.c" #include "tap/tap.h" /* FIXME: ccanize */ @@ -21,6 +22,8 @@ static char *strdup_rev(const char *s) int main(int argc, char *argv[]) { unsigned int i, j, n; + char **split; + void *ctx; char *strings[ARRAY_SIZE(substrings) * ARRAY_SIZE(substrings)]; n = 0; @@ -33,7 +36,7 @@ int main(int argc, char *argv[]) } } - plan_tests(n * n * 5); + plan_tests(n * n * 5 + 16); for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { unsigned int k, identical = 0; @@ -73,5 +76,34 @@ int main(int argc, char *argv[]) } } } + + split = strsplit(NULL, "hello world", " ", &n); + ok1(n == 3); + ok1(streq(split[0], "hello")); + ok1(streq(split[1], "")); + ok1(streq(split[2], "world")); + ok1(split[3] == NULL); + talloc_free(split); + + split = strsplit(NULL, "hello world", " ", NULL); + ok1(streq(split[0], "hello")); + ok1(streq(split[1], "")); + ok1(streq(split[2], "world")); + ok1(split[3] == NULL); + talloc_free(split); + + split = strsplit(NULL, "hello world", "o ", NULL); + ok1(streq(split[0], "hell")); + ok1(streq(split[1], "")); + ok1(streq(split[2], "")); + ok1(streq(split[3], "w")); + ok1(streq(split[4], "rld")); + ok1(split[5] == NULL); + + ctx = split; + split = strsplit(ctx, "hello world", "o ", NULL); + ok1(talloc_parent(split) == ctx); + talloc_free(ctx); + return exit_status(); }