add missing test coverage for escape sequences

Sun, 26 Jan 2025 11:59:16 +0100

author
Mike Becker <universe@uap-core.de>
date
Sun, 26 Jan 2025 11:59:16 +0100
changeset 1154
afd12f31d28a
parent 1153
8e4f46349e23
child 1155
b77d56a27e9c

add missing test coverage for escape sequences

tests/test_json.c file | annotate | diff | comparison | revisions
--- a/tests/test_json.c	Sun Jan 26 11:28:50 2025 +0100
+++ b/tests/test_json.c	Sun Jan 26 11:59:16 2025 +0100
@@ -120,7 +120,8 @@
 CX_TEST(test_json_escaped_strings) {
     cxstring text = cx_str(
             "{\n"
-            "\t\"object\":\"{\\n\\t\\\"object\\\":null\\n}\"}\"\n"
+            "\t\"object\":\"{\\n\\t\\\"object\\\":null\\n}\",\n"
+            "\t\"ctrl-chars\":\"\\\\foo\\r\\nbar\\f*ring\\/ring*\\b\"\n"
             "}"
     );
 
@@ -138,7 +139,13 @@
             cxJsonAsCxString(object),
             CX_STR("{\n\t\"object\":null\n}"))
         );
-        cxJsonValueFree(obj);
+        CxJsonValue *ctrl = cxJsonObjGet(obj, "ctrl-chars");
+        CX_TEST_ASSERT(cxJsonIsString(ctrl));
+        CX_TEST_ASSERT(0 == cx_strcmp(
+            cxJsonAsCxString(ctrl),
+            CX_STR("\\foo\r\nbar\f*ring/ring*\b"))
+        );
+        cxJsonValueFree(ctrl);
     }
     cxJsonDestroy(&json);
 }

mercurial