Add test for str8 array

This commit is contained in:
2025-09-28 00:05:17 +01:00
parent b3ebff3635
commit 9f32891bbc
5 changed files with 69 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
// vim:fileencoding=utf-8:foldmethod=marker
#include "test_str8_array.h"
TestFuncResult test_str8_array(void) {
b32 result;
Str8 expected[] = {wapp_str8_lit("Hello"), wapp_str8_lit("Hi"), wapp_str8_lit("Bye")};
Str8Array array = wapp_str8_array(wapp_str8_lit("Hello"), wapp_str8_lit("Hi"), wapp_str8_lit("Bye"));
result = array.count == 3 && array.capacity == 8;
Str8 *item;
u64 count = array.count;
u64 index = 0;
b32 running = true;
while (running) {
item = wapp_str8_array_get(&array, index);
result = result && item && (wapp_str8_equal(item, &expected[index]));
++index;
running = index < count;
}
return wapp_tester_result(result);
}

View File

@@ -0,0 +1,30 @@
// vim:fileencoding=utf-8:foldmethod=marker
#include "test_str8_array.h"
TestFuncResult test_str8_array(void) {
b32 result;
Str8 expected[] = {wapp_str8_lit("Hello"), wapp_str8_lit("Hi"), wapp_str8_lit("Bye")};
Str8 str1 = wapp_str8_lit("Hello");
Str8 str2 = wapp_str8_lit("Hi");
Str8 str3 = wapp_str8_lit("Bye");
Str8Array array = wapp_str8_array(str1, str2, str3);
result = array.count == 3 && array.capacity == 8;
Str8 *item;
u64 count = array.count;
u64 index = 0;
b32 running = true;
while (running) {
item = wapp_str8_array_get(&array, index);
result = result && item && (wapp_str8_equal(item, &expected[index]));
++index;
running = index < count;
}
return wapp_tester_result(result);
}

View File

@@ -0,0 +1,10 @@
// vim:fileencoding=utf-8:foldmethod=marker
#ifndef TEST_STR8_ARRAY_H
#define TEST_STR8_ARRAY_H
#include "wapp.h"
TestFuncResult test_str8_array(void);
#endif // !TEST_STR8_ARRAY_H

View File

@@ -2,6 +2,7 @@
#include "test_str8_list.h" #include "test_str8_list.h"
#include "test_allocator.h" #include "test_allocator.h"
#include "test_arena.h" #include "test_arena.h"
#include "test_str8_array.h"
#include "test_i32_array.h" #include "test_i32_array.h"
#include "test_cpath.h" #include "test_cpath.h"
#include "test_shell_commander.h" #include "test_shell_commander.h"
@@ -19,6 +20,7 @@ int main(void) {
test_arena_realloc_smaller_size, test_arena_realloc_smaller_size,
test_arena_clear, test_arena_clear,
test_arena_destroy, test_arena_destroy,
test_str8_array,
test_i32_array, test_i32_array,
test_i32_array_with_capacity, test_i32_array_with_capacity,
test_i32_array_get, test_i32_array_get,

View File

@@ -2,6 +2,7 @@
#include "test_str8_list.h" #include "test_str8_list.h"
#include "test_allocator.h" #include "test_allocator.h"
#include "test_arena.h" #include "test_arena.h"
#include "test_str8_array.h"
#include "test_i32_array.h" #include "test_i32_array.h"
#include "test_cpath.h" #include "test_cpath.h"
#include "test_shell_commander.h" #include "test_shell_commander.h"
@@ -19,6 +20,7 @@ int main(void) {
test_arena_realloc_smaller_size, test_arena_realloc_smaller_size,
test_arena_clear, test_arena_clear,
test_arena_destroy, test_arena_destroy,
test_str8_array,
test_i32_array, test_i32_array,
test_i32_array_with_capacity, test_i32_array_with_capacity,
test_i32_array_get, test_i32_array_get,