tests/test_json.c

changeset 1033
e3009345984b
parent 1032
aaad28e23dac
--- a/tests/test_json.c	Fri Dec 20 15:15:18 2024 +0100
+++ b/tests/test_json.c	Fri Dec 20 16:51:01 2024 +0100
@@ -535,6 +535,27 @@
     cxJsonDestroy(&json);
 }
 
+CX_TEST(test_json_array_iterator) {
+    CxJson json;
+    cxJsonInit(&json, NULL);
+    CX_TEST_DO {
+        CxJsonValue *v;
+        CxJsonStatus result;
+        cxJsonFill(&json, "[ 0, 3, 6, 9, 12, 15 ]\n");
+        result = cxJsonNext(&json, &v);
+        CX_TEST_ASSERT(result == CX_JSON_NO_ERROR);
+        CX_TEST_ASSERT(cxJsonIsArray(v));
+        CxIterator iter = cxJsonArrIter(v);
+        unsigned i = 0;
+        cx_foreach(CxJsonValue*, elem, iter) {
+            CX_TEST_ASSERT(cxJsonIsNumber(elem));
+            CX_TEST_ASSERT(i == cxJsonAsInteger(elem));
+            i += 3;
+        }
+    }
+    cxJsonDestroy(&json);
+}
+
 CX_TEST(test_json_allocator) {
     CxTestingAllocator talloc;
     cx_testing_allocator_init(&talloc);
@@ -610,6 +631,7 @@
     cx_test_register(suite, test_json_number);
     cx_test_register(suite, test_json_number_format_errors);
     cx_test_register(suite, test_json_multiple_values);
+    cx_test_register(suite, test_json_array_iterator);
     cx_test_register(suite, test_json_allocator);
     cx_test_register(suite, test_json_allocator_parse_error);
     

mercurial