Sun, 14 Dec 2025 12:07:55 +0100
add json array clone tests
| tests/test_json.c | file | annotate | diff | comparison | revisions |
--- a/tests/test_json.c Sun Dec 14 11:54:50 2025 +0100 +++ b/tests/test_json.c Sun Dec 14 12:07:55 2025 +0100 @@ -1701,9 +1701,35 @@ } CX_TEST(test_json_clone_arrays) { - + CxJsonValue *a[6]; + cxJsonFromString(NULL, "[]", &a[0]); + cxJsonFromString(NULL, "[ 1, 2, 4, 8, 16, 32, 64 ]", &a[1]); + cxJsonFromString(NULL, "[ \"string\", 12, 3.14, true, null, false, [] ]", &a[2]); + cxJsonFromString(NULL, "[[1, [[2, [3, 4, 5]]], true], false]", &a[3]); + cxJsonFromString(NULL, "[ { \"abc\": 200, \"str\": \"hello\" }, { }, null ]", &a[4]); + cxJsonFromString(NULL, "[ { \"array\": [ 1,2,3 ]} ]", &a[5]); + CX_TEST_DO { - + // TODO: only the first 4 tests work. Change i<4 to i<6 + for(int i=0;i<4;i++) { + CX_TEST_ASSERT(cxJsonIsArray(a[i])); + + CxJsonValue *b = cxJsonClone(a[i], NULL); + CX_TEST_ASSERT(b); + CX_TEST_ASSERT(cxJsonIsArray(b)); + CX_TEST_ASSERT(cxJsonCompare(a[i], b) == 0); + + // TODO: enable when cxJsonToString(b, NULL) works + //cxmutstr a_str = cxJsonToString(a[i], NULL); + //cxmutstr b_str = cxJsonToString(b, NULL); + //CX_TEST_ASSERT(cx_strcmp(a_str, b_str) == 0); + + cxJsonValueFree(b); + } + } + + for(int i=0;i<6;i++) { + cxJsonValueFree(a[i]); } }