1 #include <ccan/str_talloc/str_talloc.h>
4 #include <ccan/str_talloc/str_talloc.c>
5 #include <ccan/tap/tap.h>
7 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
9 static const char *substrings[]
10 = { "far", "bar", "baz", "b", "ba", "z", "ar", NULL };
12 int main(int argc, char *argv[])
18 split = strsplit(NULL, "hello world", " ");
19 ok1(talloc_array_length(split) == 4);
20 ok1(!strcmp(split[0], "hello"));
21 ok1(!strcmp(split[1], ""));
22 ok1(!strcmp(split[2], "world"));
23 ok1(split[3] == NULL);
26 split = strsplit(NULL, "hello world", "o ");
27 ok1(talloc_array_length(split) == 6);
28 ok1(!strcmp(split[0], "hell"));
29 ok1(!strcmp(split[1], ""));
30 ok1(!strcmp(split[2], ""));
31 ok1(!strcmp(split[3], "w"));
32 ok1(!strcmp(split[4], "rld"));
33 ok1(split[5] == NULL);
36 split = strsplit(ctx, "hello world", "o ");
37 ok1(talloc_parent(split) == ctx);
40 str = strjoin(NULL, (char **)substrings, ", ");
41 ok1(!strcmp(str, "far, bar, baz, b, ba, z, ar, "));
43 str = strjoin(ctx, (char **)substrings, "");
44 ok1(!strcmp(str, "farbarbazbbazar"));
45 ok1(talloc_parent(str) == ctx);