1 #include <ccan/tal/str/str.h>
2 #include <ccan/tal/str/str.c>
3 #include <ccan/tap/tap.h>
12 parent = tal(NULL, char);
15 c = tal_strdup(parent, "hello");
16 ok1(strcmp(c, "hello") == 0);
17 ok1(tal_parent(c) == parent);
20 c = tal_strndup(parent, "hello", 3);
21 ok1(strcmp(c, "hel") == 0);
22 ok1(tal_parent(c) == parent);
26 c = tal_talloc_typechk_(parent, char *);
28 c = tal_typechk_(parent, char *);
30 c = tal_dup_arr(parent, char, "hello", 6, 0);
31 ok1(strcmp(c, "hello") == 0);
32 ok1(strcmp(tal_name(c), "char[]") == 0);
33 ok1(tal_parent(c) == parent);
36 /* Now with an extra byte. */
37 c = tal_dup_arr(parent, char, "hello", 6, 1);
38 ok1(strcmp(c, "hello") == 0);
39 ok1(strcmp(tal_name(c), "char[]") == 0);
40 ok1(tal_parent(c) == parent);
44 c = tal_fmt(parent, "hello %s", "there");
45 ok1(strcmp(c, "hello there") == 0);
46 ok1(tal_parent(c) == parent);
49 c = tal_strcat(parent, "hello ", "there");
50 ok1(strcmp(c, "hello there") == 0);
51 ok1(tal_parent(c) == parent);
53 /* Make sure take works correctly. */
54 c = tal_strcat(parent, take(c), " again");
55 ok1(strcmp(c, "hello there again") == 0);
56 ok1(tal_parent(c) == parent);
57 ok1(single_child(parent, c));
59 c = tal_strcat(parent, "And ", take(c));
60 ok1(strcmp(c, "And hello there again") == 0);
61 ok1(tal_parent(c) == parent);
62 ok1(single_child(parent, c));
64 /* NULL pass through works... */
65 c = tal_strcat(parent, take(NULL), take(c));
67 ok1(no_children(parent));
69 c = tal_strcat(parent, take(tal_strdup(parent, "hi")),
72 ok1(no_children(parent));
74 c = tal_strcat(parent, take(NULL), take(NULL));
76 ok1(no_children(parent));
78 /* Appending formatted strings. */
79 c = tal_strdup(parent, "hi");
80 ok1(tal_append_fmt(&c, "%s %s", "there", "world"));
81 ok1(strcmp(c, "hithere world") == 0);
82 ok1(tal_parent(c) == parent);
84 ok1(!tal_append_fmt(&c, take(NULL), "there", "world"));
85 ok1(strcmp(c, "hithere world") == 0);