diff options
Diffstat (limited to 'json-glib/tests/path.c')
| -rw-r--r-- | json-glib/tests/path.c | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/json-glib/tests/path.c b/json-glib/tests/path.c index 712b65d..2b7c1f2 100644 --- a/json-glib/tests/path.c +++ b/json-glib/tests/path.c @@ -36,53 +36,70 @@ static const char *test_json = "}"; static const struct { - const char *exp; + const char *desc; + const char *expr; const char *res; } test_expressions[] = { { + "Title of the first book in the store, using objct notation.", "$.store.book[0].title", "[\"Sayings of the Century\"]" }, { + "Title of the first book in the store, using array notation.", "$['store']['book'][0]['title']", "[\"Sayings of the Century\"]" }, { + "All the authors from the every book.", "$.store.book[*].author", "[\"Nigel Rees\",\"Evelyn Waugh\",\"Herman Melville\",\"J. R. R. Tolkien\"]" }, { + "All the authors.", "$..author", "[\"Nigel Rees\",\"Evelyn Waugh\",\"Herman Melville\",\"J. R. R. Tolkien\"]" }, { + "Everything inside the store.", "$.store.*", NULL }, { + "All the prices in the store.", "$.store..price", "[\"8.95\",\"12.99\",\"8.99\",\"22.99\",\"19.95\"]" }, { + "The third book.", "$..book[2]", "[{\"category\":\"fiction\",\"author\":\"Herman Melville\",\"title\":\"Moby Dick\",\"isbn\":\"0-553-21311-3\",\"price\":\"8.99\"}]" }, { + "The last book.", "$..book[-1:]", "[{\"category\":\"fiction\",\"author\":\"J. R. R. Tolkien\",\"title\":\"The Lord of the Rings\",\"isbn\":\"0-395-19395-8\",\"price\":\"22.99\"}]" }, { + "The first two books.", "$..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\"}]" }, { + "The first two books, using a slice.", "$..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\"}]" }, { + "All the books.", "$['store']['book'][*]", "[{\"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\":\"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\"}]" }, + { + "All the members of the bicycle object.", + "$.store.bicycle.*", + "[\"red\",\"19.95\"]" + }, }; static void @@ -93,7 +110,7 @@ test_expression (void) for (i = 0; i < G_N_ELEMENTS (test_expressions); i++) { - const char *expr = test_expressions[i].exp; + const char *expr = test_expressions[i].expr; GError *error = NULL; g_assert (json_path_compile (path, expr, &error)); @@ -117,7 +134,8 @@ test_match (void) for (i = 0; i < G_N_ELEMENTS (test_expressions); i++) { - const char *expr = test_expressions[i].exp; + const char *desc = test_expressions[i].desc; + const char *expr = test_expressions[i].expr; const char *res = test_expressions[i].res; JsonNode *matches; char *str; @@ -135,10 +153,10 @@ test_match (void) if (g_test_verbose ()) { - g_print ("* expr[%02d]: '%s' =>\n" + g_print ("* expr[%02d]: %s ('%s') =>\n" "- result: %s\n" "- expected: %s\n", - i, expr, str, res); + i, desc, expr, str, res); } g_assert_cmpstr (str, ==, res); |
