X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=json-glib%2Ftests%2Fpath.c;h=2b7c1f28a73f853e03dffdd01cb4115d78e99cc4;hb=5d1beb647199b64236133d22004de48ddbcf7ead;hp=67d2a8710a9a59c5c57623ede9b590e369f9b2d5;hpb=2a1fb38cc9eba0d13a77da4b60461e135397ad1c;p=platform%2Fupstream%2Fjson-glib.git diff --git a/json-glib/tests/path.c b/json-glib/tests/path.c index 67d2a87..2b7c1f2 100644 --- a/json-glib/tests/path.c +++ b/json-glib/tests/path.c @@ -36,49 +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 @@ -89,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)); @@ -113,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; @@ -131,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); @@ -152,7 +174,9 @@ int main (int argc, char *argv[]) { +#if !GLIB_CHECK_VERSION (2, 35, 1) g_type_init (); +#endif g_test_init (&argc, &argv, NULL); g_test_bug_base ("http://bugzilla.gnome.org/show_bug.cgi?id=");