refactor(hectic C): fix warnings

This commit is contained in:
2025-03-24 14:12:55 +00:00
parent d39ed7f9fe
commit 4280f0df95
5 changed files with 171 additions and 130 deletions

View File

@@ -60,10 +60,10 @@ void test_arena_repstr() {
Arena arena = arena_init(128);
const char *original = "Hello, World!";
// Replace substr_cloneing starting at index 5, length 3 (", W") with " -"
// According to the macro logic, the suffix is taken from original[5+3+1] onward.
// That results in: "Hello" + " -" + "rld!" = "Hello -rld!"
// That results in: "Hello" + " -" + "orld!" = "Hello -orld!"
char *result = arena_repstr(&arena, original, 5, 3, " -");
assert(strcmp(result, "Hello -rld!") == 0);
raise_debug("%s", result);
assert(strcmp(result, "Hello -orld!") == 0);
arena_free(&arena);
}
@@ -81,7 +81,7 @@ void test_arena_overwrite_detection() {
// Force allocation near capacity
void *large = arena_alloc_or_null(&arena, 100);
assert(large != NULL || arena.current == arena.begin + arena.capacity); // If NULL, out of memory
assert(large != NULL || (size_t)arena.current == (size_t)arena.begin + arena.capacity); // If NULL, out of memory
// Check strings again
assert(strcmp(s1, "hello") == 0);

View File

@@ -16,7 +16,7 @@ static void test_parse_json_object(void) {
Json *child = root->child;
assert(child && strcmp(child->key, "key") == 0);
assert(child->type == JSON_STRING);
assert(strcmp(child->string, "value") == 0);
assert(strcmp(child->JsonValue.string, "value") == 0);
arena_free(&arena);
}
@@ -26,7 +26,7 @@ static void test_parse_json_number(void) {
const char *json = "42";
Json *root = json_parse(&arena, &json);
assert(root->type == JSON_NUMBER);
assert(root->number == 42);
assert(root->JsonValue.number == 42);
arena_free(&arena);
}
@@ -36,7 +36,7 @@ static void test_parse_json_string(void) {
const char *json = "\"hello\"";
Json *root = json_parse(&arena, &json);
assert(root->type == JSON_STRING);
assert(strcmp(root->string, "hello") == 0);
assert(strcmp(root->JsonValue.string, "hello") == 0);
arena_free(&arena);
}
@@ -47,10 +47,10 @@ static void test_get_object_items(void) {
Json *root = json_parse(&arena, &json);
Json *item_a = json_get_object_item(root, "a");
assert(item_a && item_a->type == JSON_STRING);
assert(strcmp(item_a->string, "1") == 0);
assert(strcmp(item_a->JsonValue.string, "1") == 0);
Json *item_b = json_get_object_item(root, "b");
assert(item_b && item_b->type == JSON_NUMBER);
assert(item_b->number == 2);
assert(item_b->JsonValue.number == 2);
arena_free(&arena);
}
@@ -103,7 +103,7 @@ static void test_nested_json_object(void) {
Json *inner = json_get_object_item(outer, "inner");
assert(inner != NULL);
assert(inner->type == JSON_NUMBER);
assert(inner->number == 100);
assert(inner->JsonValue.number == 100);
arena_free(&arena);
}
@@ -114,6 +114,7 @@ static void test_arena_reset_reuse(void) {
const char *json1 = "{\"key\":\"value\"}";
Json *root1 = json_parse(&arena, &json1);
char *printed1 = json_to_string(&arena, root1);
assert(strcmp(printed1, "{\"key\":\"value\"}") == 0);
arena_reset(&arena);
const char *json2 = "\"another test\"";
Json *root2 = json_parse(&arena, &json2);