1 #include <ccan/str_talloc/str_talloc.h>
4 #include <ccan/str_talloc/str_talloc.c>
5 #include <ccan/tap/tap.h>
8 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
10 static char *substrings[] = { "far", "bar", "baz", "b", "ba", "z", "ar", NULL };
12 int main(int argc, char *argv[])
19 split = strsplit(NULL, "hello world", " ", &n);
21 ok1(!strcmp(split[0], "hello"));
22 ok1(!strcmp(split[1], ""));
23 ok1(!strcmp(split[2], "world"));
24 ok1(split[3] == NULL);
27 split = strsplit(NULL, "hello world", " ", NULL);
28 ok1(!strcmp(split[0], "hello"));
29 ok1(!strcmp(split[1], ""));
30 ok1(!strcmp(split[2], "world"));
31 ok1(split[3] == NULL);
34 split = strsplit(NULL, "hello world", "o ", NULL);
35 ok1(!strcmp(split[0], "hell"));
36 ok1(!strcmp(split[1], ""));
37 ok1(!strcmp(split[2], ""));
38 ok1(!strcmp(split[3], "w"));
39 ok1(!strcmp(split[4], "rld"));
40 ok1(split[5] == NULL);
43 split = strsplit(ctx, "hello world", "o ", NULL);
44 ok1(talloc_parent(split) == ctx);
47 str = strjoin(NULL, substrings, ", ");
48 ok1(!strcmp(str, "far, bar, baz, b, ba, z, ar, "));
50 str = strjoin(ctx, substrings, "");
51 ok1(!strcmp(str, "farbarbazbbazar"));
52 ok1(talloc_parent(str) == ctx);