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!");
27 typedef STRMAP(char *) map_t;
31 char *str[NUM], *empty;
33 plan_tests(8 + 2 * (1 + 10 + 100) + 1);
36 for (i = 0; i < NUM; i++) {
38 sprintf(template, "%08u", i);
39 str[i] = strdup(template);
42 /* All prefixes of an empty map are empty. */
43 sub = strmap_prefix(&map, "a");
44 ok1(strmap_empty(sub));
45 sub = strmap_prefix(&map, "");
46 ok1(strmap_empty(sub));
48 for (i = 0; i < NUM; i++)
49 strmap_add(&map, str[i], str[i]+1);
52 sub = strmap_prefix(&map, "a");
53 ok1(strmap_empty(sub));
56 sub = strmap_prefix(&map, "0");
57 ok1(tcon_unwrap(sub)->u.n == tcon_unwrap(&map)->u.n);
58 sub = strmap_prefix(&map, "");
59 ok1(tcon_unwrap(sub)->u.n == tcon_unwrap(&map)->u.n);
62 sub = strmap_prefix(&map, "00000000");
64 strmap_iterate(sub, in_order, &i);
68 sub = strmap_prefix(&map, "0000000");
70 strmap_iterate(sub, in_order, &i);
74 sub = strmap_prefix(&map, "000000");
76 strmap_iterate(sub, in_order, &i);
79 /* Everything, *plus* empty string. */
81 strmap_add(&map, empty, empty);
83 sub = strmap_prefix(&map, "");
84 /* Check we get *our* empty string back! */
85 strmap_iterate(sub, find_empty, empty);
89 for (i = 0; i < NUM; i++)
93 /* This exits depending on whether all tests passed */