"}";
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
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));
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;
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);
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=");