Skip to content

Commit

Permalink
curl_json plugin: Expand unit tests.
Browse files Browse the repository at this point in the history
This adds various tests involving arrays.

Issue: collectd#2266
  • Loading branch information
octo committed May 16, 2017
1 parent a6f29de commit b7ff429
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions src/curl_json_test.c
Expand Up @@ -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++) {
Expand Down

0 comments on commit b7ff429

Please sign in to comment.