aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Kagamino Lehoux <martin@lehoux.net>2025-07-21 11:59:06 +0200
committerMartin Kagamino Lehoux <martin@lehoux.net>2025-07-21 11:59:23 +0200
commita378ff1b173f7a67272e574fb1a2c275ecb9661b (patch)
tree9ee34a7491c7c7bd66cf39096bc62185eaa4ed09
parent54db532879ed3f6d76463a3ab3f3895bd41c861c (diff)
test: rewrite tests
-rw-r--r--Makefile2
-rw-r--r--README.md1
-rw-r--r--string.c1
-rw-r--r--test_json.c16
-rw-r--r--testing.h3
5 files changed, 14 insertions, 9 deletions
diff --git a/Makefile b/Makefile
index df455a7..2ded5a1 100644
--- a/Makefile
+++ b/Makefile
@@ -14,5 +14,3 @@ test:
fish generate.fish;
make debug;
./Debug/test;
- make release;
- ./Release/test;
diff --git a/README.md b/README.md
index 6536ed4..2485a84 100644
--- a/README.md
+++ b/README.md
@@ -6,3 +6,4 @@
- JSON objet as kv
- Vec push no need to reallocate vec, only items. Same for Str? Read about stack pointers in C
- Vec_get not safe, I made a type mistake. And should be more efficient for loops
+- Fix tests in release
diff --git a/string.c b/string.c
index b07ba02..cc78719 100644
--- a/string.c
+++ b/string.c
@@ -11,6 +11,7 @@ Str *Str_new(Arena *a, uintptr_t len) {
return s;
}
+// Returns 1 if strings are equal, 0 otherwise
int Str_equals(Str a, Str b) {
return (a.len == b.len) && (!a.len || !memcmp(a.data, b.data, a.len));
}
diff --git a/test_json.c b/test_json.c
index b0f1028..751b5bd 100644
--- a/test_json.c
+++ b/test_json.c
@@ -37,13 +37,15 @@ char test_json_int_array() {
char test_json_nested_array() {
Arena perm = Arena_new(128e3);
- JSON jaa = JSON_parse(&perm, "[[1,\"abc\"]]");
+ JSON doc = JSON_parse(&perm, "[[1,\"abc\"]]");
- JSON sub_array = *Vec_get(jaa.array, JSON, 0);
- JSON *val_1 = Vec_get(sub_array.array, JSON, 0);
- t_assert(*val_1->integer == 1);
- JSON *val_2 = Vec_get(sub_array.array, JSON, 1);
- t_assert(Str_equals(*val_2->string, S("abc")));
+ 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);
+ JSON val_2 = *Vec_get(sub_array.array, JSON, 1);
+ Str str = *val_2.string;
+ Str expected = S("abc");
+ t_assert(Str_equals(str, expected));
t_assert(Arena_get_used(perm) == 203);
return 0;
@@ -54,7 +56,7 @@ char test_json_string() {
JSON js = JSON_parse(&perm, "\"abc\"");
- t_assert(Str_equals(*js.string, S("abc")) == 1);
+ t_assert(Str_equals(*js.string, S("abc")));
t_assert(Arena_get_used(perm) == 27);
return 0;
diff --git a/testing.h b/testing.h
index f27daf2..cb40294 100644
--- a/testing.h
+++ b/testing.h
@@ -1,4 +1,7 @@
+#include <stdio.h>
+
#define t_assert(fact) \
if (!(fact)) { \
+ fprintf(stderr, "Assertion failed: %s at %s:%d in %s()\n", #fact, __FILE__, __LINE__, __func__); \
return 1; \
}