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");
17 c = tal_strdup(parent, take(c));
18 ok1(strcmp(c, "hello") == 0);
19 ok1(tal_parent(c) == parent);
21 c = tal_strndup(parent, take(c), 5);
22 ok1(strcmp(c, "hello") == 0);
23 ok1(tal_parent(c) == parent);
25 c = tal_strndup(parent, take(c), 3);
26 ok1(strcmp(c, "hel") == 0);
27 ok1(tal_parent(c) == parent);
30 c = tal_strdup(parent, "hello %s");
31 c = tal_fmt(parent, take(c), "there");
32 ok1(strcmp(c, "hello there") == 0);
33 ok1(tal_parent(c) == parent);
34 /* No leftover allocations. */
36 ok1(no_children(parent));
41 /* NULL pass-through. */
43 ok1(tal_strdup(NULL, take(c)) == NULL);
44 ok1(tal_strndup(NULL, take(c), 5) == NULL);
45 ok1(tal_fmt(NULL, take(c), 0) == NULL);