+
+ split = strsplit(NULL, "hello world", " ", &n);
+ ok1(n == 3);
+ ok1(streq(split[0], "hello"));
+ ok1(streq(split[1], ""));
+ ok1(streq(split[2], "world"));
+ ok1(split[3] == NULL);
+ talloc_free(split);
+
+ split = strsplit(NULL, "hello world", " ", NULL);
+ ok1(streq(split[0], "hello"));
+ ok1(streq(split[1], ""));
+ ok1(streq(split[2], "world"));
+ ok1(split[3] == NULL);
+ talloc_free(split);
+
+ split = strsplit(NULL, "hello world", "o ", NULL);
+ ok1(streq(split[0], "hell"));
+ ok1(streq(split[1], ""));
+ ok1(streq(split[2], ""));
+ ok1(streq(split[3], "w"));
+ ok1(streq(split[4], "rld"));
+ ok1(split[5] == NULL);
+
+ ctx = split;
+ split = strsplit(ctx, "hello world", "o ", NULL);
+ ok1(talloc_parent(split) == ctx);
+ talloc_free(ctx);
+
+ str = strjoin(NULL, substrings, ", ");
+ ok1(streq(str, "far, bar, baz, b, ba, z, ar, "));
+ ctx = str;
+ str = strjoin(ctx, substrings, "");
+ ok1(streq(str, "farbarbazbbazar"));
+ ok1(talloc_parent(str) == ctx);
+ talloc_free(ctx);
+
+ str = grab_file(NULL, "ccan/string/test/run-grab.c");
+ split = strsplit(NULL, str, "\n", NULL);
+ length = strlen(split[0]);
+ ok1(streq(split[0], "/* This is test for grab_file() function */"));
+ for(i = 1; split[i]; i++)
+ length += strlen(split[i]);
+ ok1(streq(split[i-1], "/* End of grab_file() test */"));
+ if (stat("ccan/string/test/run-grab.c", &st) != 0)
+ err(1, "Could not stat self");
+ ok1(st.st_size == length);
+