From b7ff429c9f1440bac83eaa26c75945742ea70c0b Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Tue, 16 May 2017 17:01:49 +0200 Subject: [PATCH] curl_json plugin: Expand unit tests. This adds various tests involving arrays. Issue: #2266 --- src/curl_json_test.c | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/src/curl_json_test.c b/src/curl_json_test.c index 255d14b8..1e4d3b3b 100644 --- a/src/curl_json_test.c +++ b/src/curl_json_test.c @@ -89,16 +89,39 @@ DEF_TEST(parse) { char *key_path; derive_t want; } cases[] = { + /* simple map */ {"{\"foo\":42,\"bar\":23}", "foo", 42}, {"{\"foo\":42,\"bar\":23}", "bar", 23}, + /* nested map */ {"{\"a\":{\"b\":{\"c\":123}}", "a/b/c", 123}, {"{\"x\":{\"y\":{\"z\":789}}", "x/*/z", 789}, - // {"[10,11,12,13]", "0", 10}, - // {"{\"a\":[[10,11,12,13,14]]}", "a/0/0", 10}, - // {"{\"a\":[[10,11,12,13,14]]}", "a/0/1", 11}, - // {"{\"a\":[[10,11,12,13,14]]}", "a/0/2", 12}, - // {"{\"a\":[[10,11,12,13,14]]}", "a/0/3", 13}, - // {"{\"a\":[[10,11,12,13,14]]}", "a/0/4", 14}, + /* simple array */ + {"[10,11,12,13]", "0", 10}, + {"[10,11,12,13]", "1", 11}, + {"[10,11,12,13]", "2", 12}, + {"[10,11,12,13]", "3", 13}, + /* array index after non-numeric entry */ + {"[true,11]", "1", 11}, + {"[null,11]", "1", 11}, + {"[\"s\",11]", "1", 11}, + {"[{\"k\":\"v\"},11]", "1", 11}, + {"[[0,1,2],11]", "1", 11}, + /* nested array */ + {"[[0,1,2],[3,4,5],[6,7,8]]", "0/0", 0}, + {"[[0,1,2],[3,4,5],[6,7,8]]", "0/1", 1}, + {"[[0,1,2],[3,4,5],[6,7,8]]", "0/2", 2}, + {"[[0,1,2],[3,4,5],[6,7,8]]", "1/0", 3}, + {"[[0,1,2],[3,4,5],[6,7,8]]", "1/1", 4}, + {"[[0,1,2],[3,4,5],[6,7,8]]", "1/2", 5}, + {"[[0,1,2],[3,4,5],[6,7,8]]", "2/0", 6}, + {"[[0,1,2],[3,4,5],[6,7,8]]", "2/1", 7}, + {"[[0,1,2],[3,4,5],[6,7,8]]", "2/2", 8}, + /* testcase from #2266 */ + {"{\"a\":[[10,11,12,13,14]]}", "a/0/0", 10}, + {"{\"a\":[[10,11,12,13,14]]}", "a/0/1", 11}, + {"{\"a\":[[10,11,12,13,14]]}", "a/0/2", 12}, + {"{\"a\":[[10,11,12,13,14]]}", "a/0/3", 13}, + {"{\"a\":[[10,11,12,13,14]]}", "a/0/4", 14}, }; for (size_t i = 0; i < STATIC_ARRAY_SIZE(cases); i++) { -- 2.11.0