Sat, 02 Nov 2024 20:19:58 +0100
adds test case for numbers - currently fails due to issue #482
tests/test_json.c | file | annotate | diff | comparison | revisions |
--- a/tests/test_json.c Sat Nov 02 20:17:38 2024 +0100 +++ b/tests/test_json.c Sat Nov 02 20:19:58 2024 +0100 @@ -250,9 +250,19 @@ CxJson json; cxJsonInit(&json); CX_TEST_DO { + // TODO: find a better way to terminate values that are not arrays/objects CxJsonValue *v; - - cxJsonNext(&json, &v); + int result; + cxJsonFill(&json, "3.1415 "); + result = cxJsonNext(&json, &v); + CX_TEST_ASSERT(result == 1); + CX_TEST_ASSERT(cxJsonIsNumber(v)); + CX_TEST_ASSERT(cxJsonAsDouble(v) == 3.1415); + cxJsonFill(&json, "-47.11e2 "); + result = cxJsonNext(&json, &v); + CX_TEST_ASSERT(result == 1); + CX_TEST_ASSERT(cxJsonIsNumber(v)); + CX_TEST_ASSERT(cxJsonAsDouble(v) == -4711.0); } cxJsonDestroy(&json); } @@ -265,6 +275,7 @@ cx_test_register(suite, test_json_object_incomplete_token); cx_test_register(suite, test_json_object_error); cx_test_register(suite, test_json_large_nesting_depth); + cx_test_register(suite, test_json_number); return suite; }