]> git.ozlabs.org Git - ccan/blob - ccan/str_talloc/test/run.c
6da48bd0bc98f2c5fceb776012e08c5c1372b8b1
[ccan] / ccan / str_talloc / test / run.c
1 #include "str_talloc/str_talloc.h"
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include "str_talloc/str_talloc.c"
5 #include "tap/tap.h"
6
7 /* FIXME: ccanize */
8 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
9
10 int main(int argc, char *argv[])
11 {
12         unsigned int i, j, n;
13
14         plan_tests(19);
15         split = strsplit(NULL, "hello  world", " ", &n);
16         ok1(n == 3);
17         ok1(streq(split[0], "hello"));
18         ok1(streq(split[1], ""));
19         ok1(streq(split[2], "world"));
20         ok1(split[3] == NULL);
21         talloc_free(split);
22
23         split = strsplit(NULL, "hello  world", " ", NULL);
24         ok1(streq(split[0], "hello"));
25         ok1(streq(split[1], ""));
26         ok1(streq(split[2], "world"));
27         ok1(split[3] == NULL);
28         talloc_free(split);
29
30         split = strsplit(NULL, "hello  world", "o ", NULL);
31         ok1(streq(split[0], "hell"));
32         ok1(streq(split[1], ""));
33         ok1(streq(split[2], ""));
34         ok1(streq(split[3], "w"));
35         ok1(streq(split[4], "rld"));
36         ok1(split[5] == NULL);
37
38         ctx = split;
39         split = strsplit(ctx, "hello  world", "o ", NULL);
40         ok1(talloc_parent(split) == ctx);
41         talloc_free(ctx);
42
43         str = strjoin(NULL, substrings, ", ");
44         ok1(streq(str, "far, bar, baz, b, ba, z, ar, "));
45         ctx = str;
46         str = strjoin(ctx, substrings, "");
47         ok1(streq(str, "farbarbazbbazar"));
48         ok1(talloc_parent(str) == ctx);
49         talloc_free(ctx);
50
51         return exit_status();
52 }