]> git.ozlabs.org Git - ccan/blob - ccan/tal/str/test/run-string.c
tal/str: move tal string functions here from tal.
[ccan] / ccan / tal / str / test / run-string.c
1 #include <ccan/tal/str/str.h>
2 #include <ccan/tal/str/str.c>
3 #include <ccan/tap/tap.h>
4
5 int main(void)
6 {
7         char *parent, *c;
8
9         plan_tests(13);
10
11         parent = tal(NULL, char);
12         ok1(parent);
13
14         c = tal_strdup(parent, "hello");
15         ok1(strcmp(c, "hello") == 0);
16         ok1(tal_parent(c) == parent);
17
18         c = tal_strndup(parent, "hello", 3);
19         ok1(strcmp(c, "hel") == 0);
20         ok1(tal_parent(c) == parent);
21
22         c = tal_typechk_(parent, char *);
23         c = tal_dup(parent, char, "hello", 6, 0);
24         ok1(strcmp(c, "hello") == 0);
25         ok1(strcmp(tal_name(c), "char[]") == 0);
26         ok1(tal_parent(c) == parent);
27
28         /* Now with an extra byte. */
29         c = tal_dup(parent, char, "hello", 6, 1);
30         ok1(strcmp(c, "hello") == 0);
31         ok1(strcmp(tal_name(c), "char[]") == 0);
32         ok1(tal_parent(c) == parent);
33         strcat(c, "x");
34
35         c = tal_asprintf(parent, "hello %s", "there");
36         ok1(strcmp(c, "hello there") == 0);
37         ok1(tal_parent(c) == parent);
38         tal_free(parent);
39
40         return exit_status();
41 }