add json array compare tests

Sat, 13 Dec 2025 16:30:41 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 13 Dec 2025 16:30:41 +0100
changeset 1589
7ab8b302d187
parent 1588
5c4ee11417c1
child 1590
7fc3bea76481

add json array compare tests

tests/test_json.c file | annotate | diff | comparison | revisions
--- a/tests/test_json.c	Sat Dec 13 16:27:24 2025 +0100
+++ b/tests/test_json.c	Sat Dec 13 16:30:41 2025 +0100
@@ -1416,8 +1416,31 @@
 }
 
 CX_TEST(test_json_compare_arrays) {
+    char *str[4];
+    str[0] = "[]";
+    str[1] = "[ true, false ]";
+    str[2] = "[ 0, 1, \"hello\", true, false, null, {}, {\"a\":\"b\"}]";
+    str[3] = "[ \"test\", [ 1, 2, [ \"sub\", \"sub1\", [{\"end\":null}]]]]";
+    
+    CxJsonValue *a[4];
+    CxJsonValue *b[4];
+    for(int i=0;i<4;i++) {
+        cxJsonFromString(NULL, str[i], &a[i]);
+        cxJsonFromString(NULL, str[i], &b[i]);
+    }
+    
     CX_TEST_DO {
-        
+        for(int i=0;i<4;i++) {
+            for(int j=0;j<4;j++) {
+                int ret = cxJsonCompare(a[i], b[j]);
+                CX_TEST_ASSERT(i == j ? ret == 0 : ret != 0);
+            }
+        }
+    }
+    
+    for(int i=0;i<4;i++) {
+        cxJsonValueFree(a[i]);
+        cxJsonValueFree(b[i]);
     }
 }
 

mercurial