1 #include <ccan/tal/str/str.h>
2 #include <ccan/tal/str/str.c>
3 #include <ccan/tap/tap.h>
11 parent = tal(NULL, char);
14 c = tal_strdup(parent, "hello");
15 ok1(strcmp(c, "hello") == 0);
16 ok1(tal_parent(c) == parent);
19 c = tal_strndup(parent, "hello", 3);
20 ok1(strcmp(c, "hel") == 0);
21 ok1(tal_parent(c) == parent);
24 c = tal_typechk_(parent, char *);
25 c = tal_dup(parent, char, "hello", 6, 0);
26 ok1(strcmp(c, "hello") == 0);
27 ok1(strcmp(tal_name(c), "char[]") == 0);
28 ok1(tal_parent(c) == parent);
31 /* Now with an extra byte. */
32 c = tal_dup(parent, char, "hello", 6, 1);
33 ok1(strcmp(c, "hello") == 0);
34 ok1(strcmp(tal_name(c), "char[]") == 0);
35 ok1(tal_parent(c) == parent);
39 c = tal_asprintf(parent, "hello %s", "there");
40 ok1(strcmp(c, "hello there") == 0);
41 ok1(tal_parent(c) == parent);
44 c = tal_strcat(parent, "hello ", "there");
45 ok1(strcmp(c, "hello there") == 0);
46 ok1(tal_parent(c) == parent);
48 /* Make sure take works correctly. */
49 c = tal_strcat(parent, take(c), " again");
50 ok1(strcmp(c, "hello there again") == 0);
51 ok1(tal_parent(c) == parent);
52 ok1(tal_first(parent) == c && !tal_next(parent, c));
54 c = tal_strcat(parent, "And ", take(c));
55 ok1(strcmp(c, "And hello there again") == 0);
56 ok1(tal_parent(c) == parent);
57 ok1(tal_first(parent) == c && !tal_next(parent, c));
59 /* NULL pass through works... */
60 c = tal_strcat(parent, take(NULL), take(c));
62 ok1(!tal_first(parent));
64 c = tal_strcat(parent, take(tal_strdup(parent, "hi")),
67 ok1(!tal_first(parent));
69 c = tal_strcat(parent, take(NULL), take(NULL));
71 ok1(!tal_first(parent));