1 #include <ccan/strset/strset.h>
2 #include <ccan/strset/strset.c>
3 #include <ccan/tap/tap.h>
6 /* Must be > 100, see below. */
9 static bool in_order(const char *value, unsigned int *count)
17 static bool find_empty(const char *value, char *empty)
20 pass("Found empty entry!");
27 const struct strset *sub;
29 char *str[NUM], *empty;
31 plan_tests(7 + 1 + 10 + 100);
34 for (i = 0; i < NUM; i++) {
36 sprintf(template, "%08u", i);
37 str[i] = strdup(template);
40 for (i = 0; i < NUM; i++)
41 strset_set(&set, str[i]);
44 sub = strset_prefix(&set, "a");
45 ok1(strset_empty(sub));
48 sub = strset_prefix(&set, "0");
49 ok1(sub->u.n == set.u.n);
50 sub = strset_prefix(&set, "");
51 ok1(sub->u.n == set.u.n);
54 sub = strset_prefix(&set, "00000000");
56 strset_iterate(sub, in_order, &i);
60 sub = strset_prefix(&set, "0000000");
62 strset_iterate(sub, in_order, &i);
66 sub = strset_prefix(&set, "000000");
68 strset_iterate(sub, in_order, &i);
71 /* Everything, *plus* empty string. */
73 strset_set(&set, empty);
75 sub = strset_prefix(&set, "");
76 /* Check we get *our* empty string back! */
77 strset_iterate(sub, find_empty, empty);
81 for (i = 0; i < NUM; i++)
85 /* This exits depending on whether all tests passed */