Add test for str8 array
This commit is contained in:
25
tests/array/test_str8_array.c
Normal file
25
tests/array/test_str8_array.c
Normal 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);
|
||||||
|
}
|
30
tests/array/test_str8_array.cc
Normal file
30
tests/array/test_str8_array.cc
Normal 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);
|
||||||
|
}
|
10
tests/array/test_str8_array.h
Normal file
10
tests/array/test_str8_array.h
Normal 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
|
@@ -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,
|
||||||
|
@@ -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,
|
||||||
|
Reference in New Issue
Block a user