diff options
| author | Emmanuele Bassi <ebassi@linux.intel.com> | 2011-07-05 15:07:20 +0100 |
|---|---|---|
| committer | Emmanuele Bassi <ebassi@linux.intel.com> | 2011-07-05 15:07:20 +0100 |
| commit | dd3c30c5821f9f6bac4cc9016c49c7e6250377eb (patch) | |
| tree | 410d298f0947dc0d4580c1b058248e9740f93aff | |
| parent | acb33a7e6bd3d05d36e7278fafdcb4c35ec88388 (diff) | |
| download | json-glib-dd3c30c5821f9f6bac4cc9016c49c7e6250377eb.tar.gz | |
tests/path: Link expressions and results
Use a structure to keep the testable expressions and their results
together.
| -rw-r--r-- | json-glib/tests/path.c | 74 |
1 files changed, 47 insertions, 27 deletions
diff --git a/json-glib/tests/path.c b/json-glib/tests/path.c index 3a5e41c..67d2a87 100644 --- a/json-glib/tests/path.c +++ b/json-glib/tests/path.c @@ -35,30 +35,50 @@ static const char *test_json = " }" "}"; -static const char *test_expressions[] = { - "$.store.book[0].title", - "$['store']['book'][0]['title']", - "$.store.book[*].author", - "$..author", - "$.store.*", - "$.store..price", - "$..book[2]", - "$..book[-1:]", - "$..book[0,1]", - "$..book[:2]", -}; - -static const char *test_results[] = { - "[\"Sayings of the Century\"]", - "[\"Sayings of the Century\"]", - "[\"Nigel Rees\",\"Evelyn Waugh\",\"Herman Melville\",\"J. R. R. Tolkien\"]", - "[\"Nigel Rees\",\"Evelyn Waugh\",\"Herman Melville\",\"J. R. R. Tolkien\"]", - NULL, - "[\"8.95\",\"12.99\",\"8.99\",\"22.99\",\"19.95\"]", - "[{\"category\":\"fiction\",\"author\":\"Herman Melville\",\"title\":\"Moby Dick\",\"isbn\":\"0-553-21311-3\",\"price\":\"8.99\"}]", - "[{\"category\":\"fiction\",\"author\":\"J. R. R. Tolkien\",\"title\":\"The Lord of the Rings\",\"isbn\":\"0-395-19395-8\",\"price\":\"22.99\"}]", - "[{\"category\":\"reference\",\"author\":\"Nigel Rees\",\"title\":\"Sayings of the Century\",\"price\":\"8.95\"},{\"category\":\"fiction\",\"author\":\"Evelyn Waugh\",\"title\":\"Sword of Honour\",\"price\":\"12.99\"}]", - "[{\"category\":\"reference\",\"author\":\"Nigel Rees\",\"title\":\"Sayings of the Century\",\"price\":\"8.95\"},{\"category\":\"fiction\",\"author\":\"Evelyn Waugh\",\"title\":\"Sword of Honour\",\"price\":\"12.99\"}]", +static const struct { + const char *exp; + const char *res; +} test_expressions[] = { + { + "$.store.book[0].title", + "[\"Sayings of the Century\"]" + }, + { + "$['store']['book'][0]['title']", + "[\"Sayings of the Century\"]" + }, + { + "$.store.book[*].author", + "[\"Nigel Rees\",\"Evelyn Waugh\",\"Herman Melville\",\"J. R. R. Tolkien\"]" + }, + { + "$..author", + "[\"Nigel Rees\",\"Evelyn Waugh\",\"Herman Melville\",\"J. R. R. Tolkien\"]" + }, + { + "$.store.*", + NULL + }, + { + "$.store..price", + "[\"8.95\",\"12.99\",\"8.99\",\"22.99\",\"19.95\"]" + }, + { + "$..book[2]", + "[{\"category\":\"fiction\",\"author\":\"Herman Melville\",\"title\":\"Moby Dick\",\"isbn\":\"0-553-21311-3\",\"price\":\"8.99\"}]" + }, + { + "$..book[-1:]", + "[{\"category\":\"fiction\",\"author\":\"J. R. R. Tolkien\",\"title\":\"The Lord of the Rings\",\"isbn\":\"0-395-19395-8\",\"price\":\"22.99\"}]" + }, + { + "$..book[0,1]", + "[{\"category\":\"reference\",\"author\":\"Nigel Rees\",\"title\":\"Sayings of the Century\",\"price\":\"8.95\"},{\"category\":\"fiction\",\"author\":\"Evelyn Waugh\",\"title\":\"Sword of Honour\",\"price\":\"12.99\"}]" + }, + { + "$..book[:2]", + "[{\"category\":\"reference\",\"author\":\"Nigel Rees\",\"title\":\"Sayings of the Century\",\"price\":\"8.95\"},{\"category\":\"fiction\",\"author\":\"Evelyn Waugh\",\"title\":\"Sword of Honour\",\"price\":\"12.99\"}]" + }, }; static void @@ -69,7 +89,7 @@ test_expression (void) for (i = 0; i < G_N_ELEMENTS (test_expressions); i++) { - const char *expr = test_expressions[i]; + const char *expr = test_expressions[i].exp; GError *error = NULL; g_assert (json_path_compile (path, expr, &error)); @@ -93,8 +113,8 @@ test_match (void) for (i = 0; i < G_N_ELEMENTS (test_expressions); i++) { - const char *expr = test_expressions[i]; - const char *res = test_results[i]; + const char *expr = test_expressions[i].exp; + const char *res = test_expressions[i].res; JsonNode *matches; char *str; |
