tal: tal_dup()
[ccan] / ccan / tal / test / run-string.c
index 43a99da41db041f2b5675540d80e8651ac735314..0155ecbe9212f3b997c39727c3b530bc822abeb0 100644 (file)
@@ -6,7 +6,7 @@ int main(void)
 {
        char *parent, *c;
 
-       plan_tests(9);
+       plan_tests(13);
 
        parent = tal(NULL, char);
        ok1(parent);
@@ -19,10 +19,19 @@ int main(void)
        ok1(strcmp(c, "hel") == 0);
        ok1(tal_parent(c) == parent);
 
-       c = tal_memdup(parent, "hello", 6);
+       c = tal_typechk_(parent, char *);
+       c = tal_dup(parent, char, "hello", 6, 0);
        ok1(strcmp(c, "hello") == 0);
+       ok1(strcmp(tal_name(c), "char[]") == 0);
        ok1(tal_parent(c) == parent);
 
+       /* Now with an extra byte. */
+       c = tal_dup(parent, char, "hello", 6, 1);
+       ok1(strcmp(c, "hello") == 0);
+       ok1(strcmp(tal_name(c), "char[]") == 0);
+       ok1(tal_parent(c) == parent);
+       strcat(c, "x");
+
        c = tal_asprintf(parent, "hello %s", "there");
        ok1(strcmp(c, "hello there") == 0);
        ok1(tal_parent(c) == parent);