1 #include <ccan/strmap/strmap.h>
2 #include <ccan/strmap/strmap.c>
3 #include <ccan/tap/tap.h>
6 /* Must be > 100, see below. */
9 static bool in_order(const char *index, char *value, unsigned int *count)
12 ok1(i == atoi(value));
18 static bool find_empty(const char *index, char *value, char *empty)
21 pass("Found empty entry!");
28 STRMAP_MEMBERS(char *);
31 const struct map *sub;
33 char *str[NUM], *empty;
35 plan_tests(8 + 2 * (1 + 10 + 100) + 1);
38 for (i = 0; i < NUM; i++) {
40 sprintf(template, "%08u", i);
41 str[i] = strdup(template);
44 /* All prefixes of an empty map are empty. */
45 sub = strmap_prefix(&map, "a");
46 ok1(strmap_empty(sub));
47 sub = strmap_prefix(&map, "");
48 ok1(strmap_empty(sub));
50 for (i = 0; i < NUM; i++)
51 strmap_add(&map, str[i], str[i]+1);
54 sub = strmap_prefix(&map, "a");
55 ok1(strmap_empty(sub));
58 sub = strmap_prefix(&map, "0");
59 ok1(sub->raw.u.n == map.raw.u.n);
60 sub = strmap_prefix(&map, "");
61 ok1(sub->raw.u.n == map.raw.u.n);
64 sub = strmap_prefix(&map, "00000000");
66 strmap_iterate(sub, in_order, &i);
70 sub = strmap_prefix(&map, "0000000");
72 strmap_iterate(sub, in_order, &i);
76 sub = strmap_prefix(&map, "000000");
78 strmap_iterate(sub, in_order, &i);
81 /* Everything, *plus* empty string. */
83 strmap_add(&map, empty, empty);
85 sub = strmap_prefix(&map, "");
86 /* Check we get *our* empty string back! */
87 strmap_iterate(sub, find_empty, empty);
91 for (i = 0; i < NUM; i++)
95 /* This exits depending on whether all tests passed */