]> git.ozlabs.org Git - ccan/blobdiff - ccan/tal/str/test/run-string.c
tal/str: add tal_append_fmt() and tal_append_vfmt() helpers.
[ccan] / ccan / tal / str / test / run-string.c
index bb614ae2fa070e09af6da909cc61b456ec2693c2..7bf31a6cf6bce7057423e9dff1d9c4e7941f4cc3 100644 (file)
@@ -6,7 +6,7 @@ int main(void)
 {
        char *parent, *c;
 
-       plan_tests(27);
+       plan_tests(32);
 
        parent = tal(NULL, char);
        ok1(parent);
@@ -70,6 +70,15 @@ int main(void)
        ok1(!c);
        ok1(!tal_first(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);
 
        return exit_status();