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");
16 c = tal_strdup(parent, take(c));
17 ok1(strcmp(c, "hello") == 0);
18 ok1(tal_parent(c) == parent);
20 c = tal_strndup(parent, take(c), 5);
21 ok1(strcmp(c, "hello") == 0);
22 ok1(tal_parent(c) == parent);
24 c = tal_strndup(parent, take(c), 3);
25 ok1(strcmp(c, "hel") == 0);
26 ok1(tal_parent(c) == parent);
29 c = tal_strdup(parent, "hello %s");
30 c = tal_fmt(parent, take(c), "there");
31 ok1(strcmp(c, "hello there") == 0);
32 ok1(tal_parent(c) == parent);
33 /* No leftover allocations. */
35 ok1(tal_first(parent) == NULL);
40 /* NULL pass-through. */
42 ok1(tal_strdup(NULL, take(c)) == NULL);
43 ok1(tal_strndup(NULL, take(c), 5) == NULL);
44 ok1(tal_fmt(NULL, take(c), 0) == NULL);