diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2025-07-22 09:34:52 +0200 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2025-07-22 09:34:52 +0200 |
| commit | 95018d0e410c22fc56a6518d967be25428e3a6ed (patch) | |
| tree | 9bb0157a888f1c7ed1904a636d3a733d942dcccd /test_json.c | |
| parent | 13fdee74dc28f0b068503843c6e14071a7c339f2 (diff) | |
feat(json): Float parsing
Diffstat (limited to 'test_json.c')
| -rw-r--r-- | test_json.c | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/test_json.c b/test_json.c index 240a61e..91bae28 100644 --- a/test_json.c +++ b/test_json.c @@ -7,7 +7,7 @@ i32 test_json_integer() { JSON json_int = JSON_parse(&perm, "123"); t_assert(*json_int.integer == 123); - t_assert_equal(Arena_get_used(perm), 44); + t_assert_equal(Arena_get_used(perm), 52); return 0; } @@ -29,7 +29,7 @@ i32 test_json_int_array() { t_assert(ints[1] == 2); t_assert(ints[2] == 3); t_assert(sum == 6); - t_assert_equal(Arena_get_used(perm), 464); + t_assert_equal(Arena_get_used(perm), 544); return 0; } @@ -40,7 +40,7 @@ i32 test_json_empty_array() { JSON json_empty_array = JSON_parse(&perm, "[]"); t_assert(json_empty_array.array->len == 0); - t_assert_equal(Arena_get_used(perm), 160); + t_assert_equal(Arena_get_used(perm), 184); return 0; } @@ -50,7 +50,6 @@ i32 test_json_nested_array() { JSON doc = JSON_parse(&perm, "[[1,\"abc\"]]"); - t_assert_equal(Arena_get_used(perm), 427); JSON sub_array = *Vec_get(doc.array, JSON, 0); JSON val_1 = *Vec_get(sub_array.array, JSON, 0); t_assert(*val_1.integer == 1); @@ -58,7 +57,7 @@ i32 test_json_nested_array() { Str str = *val_2.string; Str expected = S("abc"); t_assert(Str_equals(str, expected)); - t_assert_equal(Arena_get_used(perm), 427); + t_assert_equal(Arena_get_used(perm), 491); return 0; } @@ -68,9 +67,8 @@ i32 test_json_string() { JSON js = JSON_parse(&perm, "\"abc\""); - t_assert_equal(Arena_get_used(perm), 59); t_assert(Str_equals(*js.string, S("abc"))); - t_assert_equal(Arena_get_used(perm), 59); + t_assert_equal(Arena_get_used(perm), 67); return 0; } @@ -81,7 +79,7 @@ i32 test_json_empty_object() { JSON doc = JSON_parse(&perm, "{}"); t_assert_equal(doc.object->len, 0); - t_assert_equal(Arena_get_used(perm), 320); + t_assert_equal(Arena_get_used(perm), 344); return 0; } @@ -91,12 +89,11 @@ i32 test_json_object() { JSON doc = JSON_parse(&perm, "{\"key\": \"value\"}"); - t_assert_equal(Arena_get_used(perm), 405); t_assert_equal(doc.object->len, 1); t_assert(Str_equals(*Vec_get(&doc.object->keys, Str, 0), S("key"))); JSON value = *JSONObject_get(doc.object, S("key")); t_assert(Str_equals(*value.string, S("value"))); - t_assert_equal(Arena_get_used(perm), 405); + t_assert_equal(Arena_get_used(perm), 437); return 0; } @@ -106,12 +103,25 @@ i32 test_json_boolean() { JSON doc = JSON_parse(&perm, "{\"a\": true, \"b\": false}"); - t_assert_equal(Arena_get_used(perm), 460); JSON a = *JSONObject_get(doc.object, S("a")); t_assert(*a.boolean == 1); JSON b = *JSONObject_get(doc.object, S("b")); t_assert(*b.boolean == 0); - t_assert_equal(Arena_get_used(perm), 460); + t_assert_equal(Arena_get_used(perm), 500); + + return 0; +} + +i32 test_json_float() { + Arena perm = Arena_new(128e3); + + JSON doc = JSON_parse(&perm, "[1.2, 2.3]"); + t_assert_equal(doc.array->len, 2); + JSON first = *Vec_get(doc.array, JSON, 0); + t_assert_fequal(*first.floating, 1.2); + JSON second = *Vec_get(doc.array, JSON, 1); + t_assert_fequal(*second.floating, 2.3); + t_assert_equal(Arena_get_used(perm), 292); return 0; } |
