--- a/tests/test_json.c Wed Jan 22 21:02:46 2025 +0100 +++ b/tests/test_json.c Sat Jan 25 16:13:28 2025 +0100 @@ -143,6 +143,58 @@ cxJsonDestroy(&json); } +CX_TEST(test_json_escaped_unicode_strings) { + cxstring text = cx_str( + "{\n" + "\"ascii\":\"\\u0041\\u0053\\u0043\\u0049\\u0049\",\n" + "\"unicode\":\"\\u00df\\u00DF\",\n" + "\"mixed\":\"mixed ä ö \\u00e4 \\u00f6\",\n" + "\"wide\":\"\\u03a3\\u29b0\"" + "}" + ); + + CxJson json; + cxJsonInit(&json, NULL); + CX_TEST_DO { + cxJsonFill(&json, text); + CxJsonValue *obj; + CxJsonStatus result = cxJsonNext(&json, &obj); + CX_TEST_ASSERT(result == CX_JSON_NO_ERROR); + CX_TEST_ASSERT(cxJsonIsObject(obj)); + + CxJsonValue *ascii = cxJsonObjGet(obj, "ascii"); + CX_TEST_ASSERT(cxJsonIsString(ascii)); + CX_TEST_ASSERT(0 == cx_strcmp( + cxJsonAsCxString(ascii), + CX_STR("ASCII")) + ); + + CxJsonValue *unicode = cxJsonObjGet(obj, "unicode"); + CX_TEST_ASSERT(cxJsonIsString(unicode)); + CX_TEST_ASSERT(0 == cx_strcmp( + cxJsonAsCxString(unicode), + CX_STR("ßß")) + ); + + CxJsonValue *mixed = cxJsonObjGet(obj, "mixed"); + CX_TEST_ASSERT(cxJsonIsString(mixed)); + CX_TEST_ASSERT(0 == cx_strcmp( + cxJsonAsCxString(mixed), + CX_STR("mixed ä ö ä ö")) + ); + + CxJsonValue *wide = cxJsonObjGet(obj, "wide"); + CX_TEST_ASSERT(cxJsonIsString(wide)); + CX_TEST_ASSERT(0 == cx_strcmp( + cxJsonAsCxString(wide), + CX_STR("\u03a3\u29b0")) + ); + + cxJsonValueFree(obj); + } + cxJsonDestroy(&json); +} + CX_TEST(test_json_escaped_end_of_string) { CxJson json; cxJsonInit(&json, NULL); @@ -1042,6 +1094,7 @@ cx_test_register(suite, test_json_init_default); cx_test_register(suite, test_json_simple_object); cx_test_register(suite, test_json_escaped_strings); + cx_test_register(suite, test_json_escaped_unicode_strings); cx_test_register(suite, test_json_escaped_end_of_string); cx_test_register(suite, test_json_object_incomplete_token); cx_test_register(suite, test_json_token_wrongly_completed);