aboutsummaryrefslogtreecommitdiff
path: root/test_json.c
diff options
context:
space:
mode:
authorMartin Kagamino Lehoux <martin@lehoux.net>2025-07-21 21:46:41 +0200
committerMartin Kagamino Lehoux <martin@lehoux.net>2025-07-21 21:46:41 +0200
commit413cb3b0c5c70d60eee212c72afed9b5c659b6d8 (patch)
treea509f8d91cab894cc02929cc1747db78ac8ac841 /test_json.c
parenta6e3e5aaf3af1fa05bc54b793f45d66b3e3f4a05 (diff)
refactor: Vec on arena
Diffstat (limited to 'test_json.c')
-rw-r--r--test_json.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/test_json.c b/test_json.c
index 5807524..b268685 100644
--- a/test_json.c
+++ b/test_json.c
@@ -1,6 +1,5 @@
#include "json.h"
#include "testing.h"
-#include <stdio.h>
int test_json_integer() {
Arena perm = Arena_new(128e3);
@@ -30,7 +29,18 @@ int 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), 344);
+ t_assert_equal(Arena_get_used(perm), 384);
+
+ return 0;
+}
+
+int test_json_empty_array() {
+ Arena perm = Arena_new(128e3);
+
+ JSON json_empty_array = JSON_parse(&perm, "[]");
+
+ t_assert(json_empty_array.array->len == 0);
+ t_assert_equal(Arena_get_used(perm), 136);
return 0;
}
@@ -40,7 +50,7 @@ int test_json_nested_array() {
JSON doc = JSON_parse(&perm, "[[1,\"abc\"]]");
- t_assert_equal(Arena_get_used(perm), 283);
+ t_assert_equal(Arena_get_used(perm), 363);
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);
@@ -48,7 +58,7 @@ int 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), 283);
+ t_assert_equal(Arena_get_used(perm), 363);
return 0;
}
@@ -71,7 +81,7 @@ int test_json_empty_object() {
JSON doc = JSON_parse(&perm, "{}");
t_assert_equal(doc.object->len, 0);
- t_assert_equal(Arena_get_used(perm), 216);
+ t_assert_equal(Arena_get_used(perm), 296);
return 0;
}
@@ -81,11 +91,11 @@ int test_json_object() {
JSON doc = JSON_parse(&perm, "{\"key\": \"value\"}");
- t_assert_equal(Arena_get_used(perm), 293);
+ t_assert_equal(Arena_get_used(perm), 373);
t_assert_equal(doc.object->len, 1);
t_assert(Str_equals(*Vec_get(&doc.object->keys, Str, 0), S("key")));
t_assert(Str_equals(*JSONObject_get(doc.object, S("key"))->string,
- S("value"))) t_assert_equal(Arena_get_used(perm), 293);
+ S("value"))) t_assert_equal(Arena_get_used(perm), 373);
return 0;
}