Code

frontend: Updated unit-tests for expression related parsing.
[sysdb.git] / t / frontend / parser_test.c
index 71fc1dbd219b0b382b615897670af5d573d35b9f..4b177328c084483edc1c74d7e167cf89533a8db3 100644 (file)
@@ -42,7 +42,7 @@ START_TEST(test_parse)
                const char *query;
                int len;
                int expected;
-               int expected_cmd;
+               sdb_conn_state_t expected_cmd;
        } golden_data[] = {
                /* empty commands */
                { NULL,                 -1, -1, 0 },
@@ -51,11 +51,14 @@ START_TEST(test_parse)
                { ";;",                 -1,  0, 0 },
 
                /* valid commands */
-               { "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  },
+               { "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   },
+
+               { "LOOKUP hosts WHERE "
+                 "host.name = 'host'", -1,  1, CONNECTION_LOOKUP },
 
                /* comments */
                { "/* some comment */", -1,  0, 0 },
@@ -66,6 +69,10 @@ START_TEST(test_parse)
                { "FETCH host",         -1, -1, 0 },
                { "LIST; INVALID",       8, -1, 0 },
                { "/* some incomplete", -1, -1, 0 },
+
+               { "LOOKUP hosts",       -1, -1, 0 },
+               { "LOOKUP foo WHERE "
+                 "host.name = 'host'", -1, -1, 0 },
        };
 
        size_t i;
@@ -113,17 +120,17 @@ START_TEST(test_parse_matcher)
                int expected;
        } golden_data[] = {
                /* empty expressions */
-               { NULL,                 -1, -1 },
-               { "",                   -1, -1 },
+               { NULL,                             -1, -1 },
+               { "",                               -1, -1 },
 
                /* valid expressions */
-               { "'localhost'",        -1,  0 },
-               { "'localhost' -- foo", -1,  0 },
-               { "'host' <garbage>",    6,  0 },
+               { "host.name = 'localhost'",        -1,  0 },
+               { "host.name = 'localhost' -- foo", -1,  0 },
+               { "host.name = 'host' <garbage>",   18,  0 },
 
                /* syntax errors */
-               { "LIST",               -1, -1 },
-               { "foo &^ bar",         -1, -1 },
+               { "LIST",                           -1, -1 },
+               { "foo &^ bar",                     -1, -1 },
        };
 
        size_t i;