aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Kagamino Lehoux <martin@lehoux.net>2025-07-23 14:46:07 +0200
committerMartin Kagamino Lehoux <martin@lehoux.net>2025-07-23 14:46:07 +0200
commit2d3b907128e00b1384484c0bd96591db3f4c3c90 (patch)
tree8fc346a0259e7f44e144c8dc7f7e2b59c36dd889
parent034d197e7eb3749f9f5b347595abdcfe2d086965 (diff)
test(json): Much more complex json
-rw-r--r--memory.c1
-rw-r--r--test_json.c38
2 files changed, 38 insertions, 1 deletions
diff --git a/memory.c b/memory.c
index 83757b6..73d6345 100644
--- a/memory.c
+++ b/memory.c
@@ -1,6 +1,5 @@
#include <assert.h>
#include <stdint.h>
-#include <stdio.h>
#include <stdlib.h>
#include <string.h>
diff --git a/test_json.c b/test_json.c
index 7243a34..a37996c 100644
--- a/test_json.c
+++ b/test_json.c
@@ -167,3 +167,41 @@ i32 test_json_nested_object() {
t_assert(lvl_2.type == JSON_OBJECT);
return 0;
}
+
+i32 test_json_complex_multiline() {
+ Arena perm = Arena_new(128e3);
+ JSON doc =
+ JSON_parse(&perm, "{\n"
+ " \"id\": 819228,\n"
+ " \"username\": \"rCrRv4PRnUNuAy\",\n"
+ " \"email\": \"xzbwrzj@zwod.com\",\n"
+ " \"first_name\": \"4WH7g7PsOEm5\",\n"
+ " \"last_name\": \"6ulndxUgjbIayl\",\n"
+ " \"age\": 30,\n"
+ " \"phone\": \"+1-529-712-3931\",\n"
+ " \"is_active\": false,\n"
+ " \"balance\": 9347.49,\n"
+ " \"tags\": [\n"
+ " \"TWvZi0\",\n"
+ " \"pM0TPv9X\"\n"
+ " ],\n"
+ " \"metadata\": {\n"
+ " \"last_login\": \"2024-06-13T21:22:32Z\",\n"
+ " \"login_count\": 245,\n"
+ " \"preferences\": {\n"
+ " \"theme\": \"auto\",\n"
+ " \"notifications\": true,\n"
+ " \"language\": \"en\"\n"
+ " }\n"
+ " }\n"
+ " }");
+
+ JSON id = *JSONObject_get(doc.as.object, S("id"));
+ t_assert(id.as.integer == 819228);
+ JSON metadata = *JSONObject_get(doc.as.object, S("metadata"));
+ JSON preferences = *JSONObject_get(metadata.as.object, S("preferences"));
+ JSON theme = *JSONObject_get(preferences.as.object, S("theme"));
+ t_assert(Str_equals(theme.as.string, S("auto")));
+
+ return 0;
+}