Skip to content

Commit c07c527

Browse files
committed
tests: internal: slist: add tests for the new split_tokens api
Signed-off-by: Eduardo Silva <[email protected]>
1 parent 98d8060 commit c07c527

File tree

1 file changed

+58
-3
lines changed

1 file changed

+58
-3
lines changed

tests/internal/slist.c

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,60 @@ void test_slist_split_string()
101101

102102
}
103103

104+
void token_check(struct mk_list *list, int id, char *str)
105+
{
106+
int i = 0;
107+
int len;
108+
int ret;
109+
struct mk_list *head;
110+
struct flb_slist_entry *e = NULL;
111+
112+
mk_list_foreach(head, list) {
113+
if (i == id) {
114+
e = mk_list_entry(head, struct flb_slist_entry, _head);
115+
break;
116+
}
117+
e = NULL;
118+
i++;
119+
}
120+
TEST_CHECK(e != NULL);
121+
122+
len = strlen(str);
123+
ret = flb_sds_cmp(e->str, str, len);
124+
TEST_CHECK(ret == 0);
125+
if (ret != 0) {
126+
fprintf(stderr, "[token %i] expected '%s', got '%s'\n\n",
127+
i, str, e->str);
128+
exit(EXIT_FAILURE);
129+
}
130+
}
131+
132+
void test_slist_split_tokens()
133+
{
134+
struct mk_list list;
135+
char *txt = \
136+
" this \"is a tokens parser\" \" apples \", "
137+
"no\"quoted \"this is \\\"quoted\\\"\" "
138+
"don't escape insi\\\"de q\\\"uoted strings\\\"";
139+
140+
mk_list_init(&list);
141+
flb_slist_split_tokens(&list, txt);
142+
143+
token_check(&list, 0, "this");
144+
token_check(&list, 1, "is a tokens parser");
145+
token_check(&list, 2, " apples ");
146+
token_check(&list, 3, ",");
147+
token_check(&list, 4, "no\"quoted");
148+
token_check(&list, 5, "this is \"quoted\"");
149+
token_check(&list, 6, "don't");
150+
token_check(&list, 7, "escape");
151+
token_check(&list, 8, "insi\\\"de");
152+
token_check(&list, 9, "q\\\"uoted");
153+
token_check(&list, 10, "strings\\\"");
154+
155+
flb_slist_destroy(&list);
156+
}
157+
104158
void test_bugs()
105159
{
106160
int ret;
@@ -119,8 +173,9 @@ void test_bugs()
119173
}
120174

121175
TEST_LIST = {
122-
{ "add" , test_slist_add},
123-
{ "split", test_slist_split_string},
124-
{ "bugs" , test_bugs},
176+
{ "add" , test_slist_add},
177+
{ "split_string", test_slist_split_string},
178+
{ "split_tokens", test_slist_split_tokens},
179+
{ "bugs" , test_bugs},
125180
{ 0 }
126181
};

0 commit comments

Comments
 (0)