Added test cases and documentation for json_array_foreach()
This commit is contained in:
@@ -400,6 +400,31 @@ static void test_circular()
|
||||
json_decref(array1);
|
||||
}
|
||||
|
||||
static void test_array_foreach()
|
||||
{
|
||||
int index;
|
||||
json_t *array1, *array2, *value;
|
||||
|
||||
array1 = json_pack("[sisisi]", "foo", 1, "bar", 2, "baz", 3);
|
||||
array2 = json_array();
|
||||
|
||||
printf("before array1: %s\n", json_dumps(array1, 0));
|
||||
printf("before array2: %s\n", json_dumps(array2, 0));
|
||||
|
||||
json_array_foreach(array1, index, value) {
|
||||
json_array_append(array2, value);
|
||||
}
|
||||
|
||||
printf("after array1: %s\n", json_dumps(array1, 0));
|
||||
printf("after array2: %s\n", json_dumps(array2, 0));
|
||||
|
||||
if(!json_equal(array1, array2))
|
||||
fail("json_array_foreach failed to iterate all elements");
|
||||
|
||||
json_decref(array1);
|
||||
json_decref(array2);
|
||||
}
|
||||
|
||||
|
||||
static void run_tests()
|
||||
{
|
||||
@@ -409,4 +434,5 @@ static void run_tests()
|
||||
test_clear();
|
||||
test_extend();
|
||||
test_circular();
|
||||
test_array_foreach();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user