]> git.ozlabs.org Git - ccan/blobdiff - ccan/tal/str/test/run-string.c
tal/str: use tal/talloc backend #ifdef TAL_USE_TALLOC.
[ccan] / ccan / tal / str / test / run-string.c
index bb614ae2fa070e09af6da909cc61b456ec2693c2..8d596e462e13a006a86ea46cfbf1a47af0a1d952 100644 (file)
@@ -1,12 +1,13 @@
 #include <ccan/tal/str/str.h>
 #include <ccan/tal/str/str.c>
 #include <ccan/tap/tap.h>
+#include "helper.h"
 
 int main(void)
 {
        char *parent, *c;
 
-       plan_tests(27);
+       plan_tests(32);
 
        parent = tal(NULL, char);
        ok1(parent);
@@ -21,7 +22,11 @@ int main(void)
        ok1(tal_parent(c) == parent);
        tal_free(c);
 
+#ifdef TAL_USE_TALLOC
+       c = tal_talloc_typechk_(parent, char *);
+#else
        c = tal_typechk_(parent, char *);
+#endif
        c = tal_dup(parent, char, "hello", 6, 0);
        ok1(strcmp(c, "hello") == 0);
        ok1(strcmp(tal_name(c), "char[]") == 0);
@@ -49,26 +54,35 @@ int main(void)
        c = tal_strcat(parent, take(c), " again");
        ok1(strcmp(c, "hello there again") == 0);
        ok1(tal_parent(c) == parent);
-       ok1(tal_first(parent) == c && !tal_next(parent, c));
+       ok1(single_child(parent, c));
 
        c = tal_strcat(parent, "And ", take(c));
        ok1(strcmp(c, "And hello there again") == 0);
        ok1(tal_parent(c) == parent);
-       ok1(tal_first(parent) == c && !tal_next(parent, c));
+       ok1(single_child(parent, c));
 
        /* NULL pass through works... */
        c = tal_strcat(parent, take(NULL), take(c));
        ok1(!c);
-       ok1(!tal_first(parent));
+       ok1(no_children(parent));
 
        c = tal_strcat(parent, take(tal_strdup(parent, "hi")),
                       take(NULL));
        ok1(!c);
-       ok1(!tal_first(parent));
+       ok1(no_children(parent));
 
        c = tal_strcat(parent, take(NULL), take(NULL));
        ok1(!c);
-       ok1(!tal_first(parent));
+       ok1(no_children(parent));
+
+       /* Appending formatted strings. */
+       c = tal_strdup(parent, "hi");
+       ok1(tal_append_fmt(&c, "%s %s", "there", "world"));
+       ok1(strcmp(c, "hithere world") == 0);
+       ok1(tal_parent(c) == parent);
+
+       ok1(!tal_append_fmt(&c, take(NULL), "there", "world"));
+       ok1(strcmp(c, "hithere world") == 0);
 
        tal_free(parent);