tests/test_json.c

changeset 1547
12da0654e4a9
parent 1543
7b66371d6da3
child 1548
12315ee158ad
--- a/tests/test_json.c	Sat Dec 06 16:22:19 2025 +0100
+++ b/tests/test_json.c	Sat Dec 06 16:30:11 2025 +0100
@@ -1116,9 +1116,9 @@
         cxJsonObjPutInteger(obj, "test2", 0);
 
         // verify the values
-        CxIterator iter = cxJsonObjIter(obj);
+        CxMapIterator iter = cxJsonObjIter(obj);
         bool found[5] = {0};
-        cx_foreach(CxJsonObjValue *, ov, iter) {
+        cx_foreach(CxMapEntry *, ov, iter) {
             CxJsonValue *v = ov->value;
             CX_TEST_ASSERT(cxJsonIsInteger(v));
             int64_t i = cxJsonAsInteger(v);
@@ -1192,19 +1192,19 @@
         cxstring expected = cx_str(
 "{\"bool\":false,"
 "\"int\":47,"
+"\"strings\":[\"hello\",\"world\"],"
 "\"nested\":{"
-"\"floats\":[3.1415,47.11,8.15],"
-"\"ints\":[4,8,15,[16,23],42],"
-"\"literals\":[true,null,false],"
 "\"objects\":[{"
 "\"name1\":1,"
 "\"name2\":3"
 "},{"
-"\"name1\":3,"
-"\"name2\":7"
-"}]"
-"},"
-"\"strings\":[\"hello\",\"world\"]"
+"\"name2\":7,"
+"\"name1\":3"
+"}],"
+"\"floats\":[3.1415,47.11,8.15],"
+"\"literals\":[true,null,false],"
+"\"ints\":[4,8,15,[16,23],42]"
+"}"
 "}"
         );
 
@@ -1226,69 +1226,6 @@
 "{\n"
 "    \"bool\": false,\n"
 "    \"int\": 47,\n"
-"    \"nested\": {\n"
-"        \"floats\": [3.1415, 47.11, 8.15],\n"
-"        \"ints\": [4, 8, 15, [16, 23], 42],\n"
-"        \"literals\": [true, null, false],\n"
-"        \"objects\": [{\n"
-"            \"name1\": 1,\n"
-"            \"name2\": 3\n"
-"        }, {\n"
-"            \"name1\": 3,\n"
-"            \"name2\": 7\n"
-"        }]\n"
-"    },\n"
-"    \"strings\": [\"hello\", \"world\"]\n"
-"}"
-        );
-
-        CxJsonWriter writer = cxJsonWriterPretty(true);
-        CX_TEST_CALL_SUBROUTINE(test_json_write_sub, allocator, expected, &writer);
-        CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
-    }
-    cx_testing_allocator_destroy(&talloc);
-}
-
-CX_TEST(test_json_write_pretty_default_tabs) {
-    CxTestingAllocator talloc;
-    cx_testing_allocator_init(&talloc);
-    CxAllocator *allocator = &talloc.base;
-    CX_TEST_DO {
-        cxstring expected = cx_str(
-"{\n"
-"\t\"bool\": false,\n"
-"\t\"int\": 47,\n"
-"\t\"nested\": {\n"
-"\t\t\"floats\": [3.1415, 47.11, 8.15],\n"
-"\t\t\"ints\": [4, 8, 15, [16, 23], 42],\n"
-"\t\t\"literals\": [true, null, false],\n"
-"\t\t\"objects\": [{\n"
-"\t\t\t\"name1\": 1,\n"
-"\t\t\t\"name2\": 3\n"
-"\t\t}, {\n"
-"\t\t\t\"name1\": 3,\n"
-"\t\t\t\"name2\": 7\n"
-"\t\t}]\n"
-"\t},\n"
-"\t\"strings\": [\"hello\", \"world\"]\n"
-"}"
-        );
-        CxJsonWriter writer = cxJsonWriterPretty(false);
-        CX_TEST_CALL_SUBROUTINE(test_json_write_sub, allocator, expected, &writer);
-        CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
-    }
-    cx_testing_allocator_destroy(&talloc);
-}
-
-CX_TEST(test_json_write_pretty_preserve_order) {
-    CxTestingAllocator talloc;
-    cx_testing_allocator_init(&talloc);
-    CxAllocator *allocator = &talloc.base;
-    CX_TEST_DO {
-        cxstring expected = cx_str(
-"{\n"
-"    \"bool\": false,\n"
-"    \"int\": 47,\n"
 "    \"strings\": [\"hello\", \"world\"],\n"
 "    \"nested\": {\n"
 "        \"objects\": [{\n"
@@ -1306,7 +1243,37 @@
         );
 
         CxJsonWriter writer = cxJsonWriterPretty(true);
-        writer.sort_members = false;
+        CX_TEST_CALL_SUBROUTINE(test_json_write_sub, allocator, expected, &writer);
+        CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
+    }
+    cx_testing_allocator_destroy(&talloc);
+}
+
+CX_TEST(test_json_write_pretty_default_tabs) {
+    CxTestingAllocator talloc;
+    cx_testing_allocator_init(&talloc);
+    CxAllocator *allocator = &talloc.base;
+    CX_TEST_DO {
+        cxstring expected = cx_str(
+"{\n"
+"\t\"bool\": false,\n"
+"\t\"int\": 47,\n"
+"\t\"strings\": [\"hello\", \"world\"],\n"
+"\t\"nested\": {\n"
+"\t\t\"objects\": [{\n"
+"\t\t\t\"name1\": 1,\n"
+"\t\t\t\"name2\": 3\n"
+"\t\t}, {\n"
+"\t\t\t\"name2\": 7,\n"
+"\t\t\t\"name1\": 3\n"
+"\t\t}],\n"
+"\t\t\"floats\": [3.1415, 47.11, 8.15],\n"
+"\t\t\"literals\": [true, null, false],\n"
+"\t\t\"ints\": [4, 8, 15, [16, 23], 42]\n"
+"\t}\n"
+"}"
+        );
+        CxJsonWriter writer = cxJsonWriterPretty(false);
         CX_TEST_CALL_SUBROUTINE(test_json_write_sub, allocator, expected, &writer);
         CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
     }
@@ -1521,7 +1488,6 @@
     cx_test_register(suite, test_json_write_default_format);
     cx_test_register(suite, test_json_write_pretty_default_spaces);
     cx_test_register(suite, test_json_write_pretty_default_tabs);
-    cx_test_register(suite, test_json_write_pretty_preserve_order);
     cx_test_register(suite, test_json_write_pretty_deep_nesting);
     cx_test_register(suite, test_json_write_frac_max_digits);
     cx_test_register(suite, test_json_write_string_escape);

mercurial