summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 9ae8350)
raw | patch | inline | side by side (parent: 9ae8350)
author | Sebastian Harl <sh@tokkee.org> | |
Mon, 31 Mar 2014 21:18:37 +0000 (23:18 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Mon, 31 Mar 2014 21:18:37 +0000 (23:18 +0200) |
t/frontend/parser_test.c | patch | blob | history |
index acd8ee69f079c5571be0b4786ef8ec9c647436fe..85265147b1bebdb86ad842ba0a180ef6560faa01 100644 (file)
--- a/t/frontend/parser_test.c
+++ b/t/frontend/parser_test.c
const char *query;
int len;
int expected;
+ int expected_cmd;
} golden_data[] = {
/* empty commands */
- { NULL, -1, -1 },
- { "", -1, 0 },
- { ";", -1, 0 },
- { ";;", -1, 0 },
+ { NULL, -1, -1, 0 },
+ { "", -1, 0, 0 },
+ { ";", -1, 0, 0 },
+ { ";;", -1, 0, 0 },
/* valid commands */
- { "LIST", -1, 1 },
- { "LIST -- comment", -1, 1 },
- { "LIST;", -1, 1 },
- { "LIST; INVALID", 5, 1 },
+ { "FETCH host", -1, 1, CONNECTION_FETCH },
+ { "LIST", -1, 1, CONNECTION_LIST },
+ { "LIST -- comment", -1, 1, CONNECTION_LIST },
+ { "LIST;", -1, 1, CONNECTION_LIST },
+ { "LIST; INVALID", 5, 1, CONNECTION_LIST },
/* comments */
- { "/* some comment */", -1, 0 },
- { "-- another comment", -1, 0 },
+ { "/* some comment */", -1, 0, 0 },
+ { "-- another comment", -1, 0, 0 },
/* syntax errors */
- { "INVALID", -1, -1 },
- { "LIST; INVALID", 8, -1 },
- { "/* some incomplete", -1, -1 },
+ { "INVALID", -1, -1, 0 },
+ { "FETCH $%&#", -1, -1, 0 },
+ { "LIST; INVALID", 8, -1, 0 },
+ { "/* some incomplete", -1, -1, 0 },
};
size_t i;
sdb_llist_t *check;
for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
+ sdb_object_t *obj;
_Bool ok;
check = sdb_fe_parse(golden_data[i].query, golden_data[i].len);
if (! check)
continue;
- if ((! strcmp(golden_data[i].query, "LIST"))
- || (! strcmp(golden_data[i].query, "LIST;"))) {
- sdb_object_t *obj = sdb_llist_get(check, 0);
- fail_unless(SDB_CONN_NODE(obj)->cmd == CONNECTION_LIST,
- "sdb_fe_parse(LIST)->cmd = %i; expected: %d "
- "(CONNECTION_LIST)", SDB_CONN_NODE(obj)->cmd,
- CONNECTION_LIST);
- sdb_object_deref(obj);
+ if ((! golden_data[i].expected_cmd)
+ || (golden_data[i].expected <= 0)) {
+ sdb_llist_destroy(check);
+ continue;
}
+ obj = sdb_llist_get(check, 0);
+ fail_unless(SDB_CONN_NODE(obj)->cmd == golden_data[i].expected_cmd,
+ "sdb_fe_parse(%s)->cmd = %i; expected: %d",
+ golden_data[i].query, SDB_CONN_NODE(obj)->cmd,
+ golden_data[i].expected_cmd);
+ sdb_object_deref(obj);
sdb_llist_destroy(check);
}
}