Code

curl_json plugin: Expand unit tests.
authorFlorian Forster <octo@collectd.org>
Tue, 16 May 2017 15:01:49 +0000 (17:01 +0200)
committerFlorian Forster <octo@collectd.org>
Tue, 16 May 2017 17:40:26 +0000 (19:40 +0200)
This adds various tests involving arrays.

Issue: #2266

src/curl_json_test.c

index 255d14b8cbecee3ad1bef1ef4d20af55904e49d3..1e4d3b3bb0db7a96d151238a79e1c271591f36f9 100644 (file)
@@ -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++) {