new repo for codebase
This commit is contained in:
181
src/testing/testing_main.c
Normal file
181
src/testing/testing_main.c
Normal file
@@ -0,0 +1,181 @@
|
||||
#include "core/core.h"
|
||||
#include "os/os.h"
|
||||
|
||||
#include "core/core.c"
|
||||
#include "os/os.c"
|
||||
|
||||
fn void os_test(void) {
|
||||
ma_temp_t scratch = ma_begin_scratch();
|
||||
|
||||
os_date_t local_time = os_local_time();
|
||||
os_date_t universal_time = os_universal_time();
|
||||
unused(universal_time); unused(local_time);
|
||||
// debugf("OS local_time = %S | universal_time = %S", os_format_date(&tcx->temp, local_time), os_format_date(&tcx->temp, universal_time));
|
||||
|
||||
s8_t exe_dir = os_exe_dir(&tcx->temp);
|
||||
assert(exe_dir.str[exe_dir.len - 1] != '/');
|
||||
s8_t exe = os_exe(&tcx->temp);
|
||||
s8_t cwd = os_cwd(&tcx->temp);
|
||||
assert(cwd.str[cwd.len - 1] != '/');
|
||||
assert(os_is_dir(exe_dir));
|
||||
assert(os_is_file(exe));
|
||||
assert(os_is_dir(cwd));
|
||||
assert(os_exists(exe_dir));
|
||||
assert(os_exists(exe));
|
||||
assert(os_exists(cwd));
|
||||
assert(os_is_abs(exe_dir));
|
||||
assert(os_is_abs(exe));
|
||||
assert(os_is_abs(cwd));
|
||||
assert(!os_is_abs(s8("../path/")));
|
||||
|
||||
s8_t file = os_read(&tcx->temp, s8("../.gitignore"));
|
||||
assert(file.str != 0);
|
||||
assert(file.len != 0);
|
||||
|
||||
// TEST os_copy
|
||||
{
|
||||
b32 a = os_copy(s8("../.gitignore"), s8(".gitignore_copy_test"), true);
|
||||
assert(a);
|
||||
|
||||
s8_t gitignore_copy = os_read(scratch.arena, s8(".gitignore_copy_test"));
|
||||
s8_t gitignore = os_read(scratch.arena, s8("../.gitignore"));
|
||||
assert(s8_are_equal(gitignore, gitignore_copy));
|
||||
os_delete(s8(".gitignore_copy_test"));
|
||||
}
|
||||
|
||||
// TEST os_iter
|
||||
{
|
||||
b32 found_gitignore = false;
|
||||
b32 found_src = false;
|
||||
for (os_iter_t *iter = os_iter(scratch.arena, s8("../")); iter->is_valid; os_advance(iter)) {
|
||||
assert(os_is_abs(iter->abs));
|
||||
assert(!os_is_abs(iter->rel));
|
||||
if (s8_ends_with(iter->rel, s8(".gitignore"))) {
|
||||
found_gitignore = true;
|
||||
assert(os_is_file(iter->rel));
|
||||
}
|
||||
if (s8_ends_with(iter->rel, s8("src"))) {
|
||||
found_src = true;
|
||||
assert(os_is_dir(iter->rel));
|
||||
}
|
||||
|
||||
if (os_is_dir(iter->abs)) {
|
||||
assert(iter->abs.str[iter->abs.len - 1] != '/');
|
||||
}
|
||||
}
|
||||
assert(found_src);
|
||||
assert(found_gitignore);
|
||||
}
|
||||
|
||||
#if PLATFORM_WINDOWS
|
||||
s8_t path = os_appdata(scratch.arena, s8("testing"));
|
||||
assert(path.str[path.len - 1] != '/');
|
||||
assert(s8_starts_with(path, s8("C:/")));
|
||||
assert(s8_ends_with(path, s8("/testing")));
|
||||
#endif
|
||||
ma_end_scratch(scratch);
|
||||
}
|
||||
|
||||
fn void test_s8(void) {
|
||||
ma_arena_t *arena = ma_create(ma_default_reserve_size);
|
||||
|
||||
{
|
||||
ma_temp_t temp = ma_begin_temp(arena);
|
||||
sb8_t *sb = &(sb8_t){arena};
|
||||
|
||||
s8_t memes = s8("memes");
|
||||
sb8_printf(sb, "%S", memes);
|
||||
assert(sb->first == sb->last);
|
||||
assert(sb->first->len == 5);
|
||||
assert(s8_are_equal(sb->first->string, memes));
|
||||
|
||||
sb8_printf(sb, "%S", s8("things are going fine"));
|
||||
s8_t string = sb8_merge(temp.arena, sb);
|
||||
assert(s8_are_equal(string, s8("memesthings are going fine")));
|
||||
|
||||
ma_end_temp(temp);
|
||||
}
|
||||
|
||||
{
|
||||
s8_t str = s8("thing|another|");
|
||||
sb8_t sb = s8_split(arena, str, s8("|"), s8_split_none);
|
||||
|
||||
assert(s8_are_equal(sb.first->string, s8("thing")));
|
||||
assert(s8_are_equal(sb.first->next->string, s8("another")));
|
||||
assert(sb.first->next->next == NULL);
|
||||
}
|
||||
|
||||
{
|
||||
s8_t str = s8("thing|another|");
|
||||
sb8_t sb = s8_split(arena, str, s8("|"), s8_split_inclusive);
|
||||
|
||||
assert(s8_are_equal(sb.first->string, s8("thing")));
|
||||
assert(s8_are_equal(sb.first->next->string, s8("|")));
|
||||
assert(s8_are_equal(sb.first->next->next->string, s8("another")));
|
||||
assert(s8_are_equal(sb.first->next->next->next->string, s8("|")));
|
||||
assert(sb.first->next->next->next->next == NULL);
|
||||
}
|
||||
|
||||
{
|
||||
s8_t str = s8("aabaaBaa");
|
||||
sb8_t sb = s8_split(arena, str, s8("b"), s8_split_inclusive | s8_split_ignore_case);
|
||||
|
||||
assert(s8_are_equal(sb.first->string, s8("aa")));
|
||||
assert(s8_are_equal(sb.first->next->string, s8("b")));
|
||||
assert(s8_are_equal(sb.first->next->next->string, s8("aa")));
|
||||
assert(s8_are_equal(sb.first->next->next->next->string, s8("B")));
|
||||
assert(s8_are_equal(sb.first->next->next->next->next->string, s8("aa")));
|
||||
assert(sb.first->next->next->next->next->next == NULL);
|
||||
}
|
||||
|
||||
{
|
||||
s8_t str = s8("aabaaBaa");
|
||||
sb8_t sb = s8_split(arena, str, s8("b"), s8_split_inclusive);
|
||||
|
||||
assert(s8_are_equal(sb.first->string, s8("aa")));
|
||||
assert(s8_are_equal(sb.first->next->string, s8("b")));
|
||||
assert(s8_are_equal(sb.first->next->next->string, s8("aaBaa")));
|
||||
}
|
||||
|
||||
{
|
||||
s8_t s = s8("0123456789");
|
||||
assert(s8_are_equal(s8_slice(s, 0, 4), s8("0123")));
|
||||
assert(s8_are_equal(s8_slice(s, -2, -1), s8("89")));
|
||||
assert(s8_are_equal(s8_slice(s, -2, 10), s8("89")));
|
||||
assert(s8_are_equal(s8_slice(s, 8, 10), s8("89")));
|
||||
}
|
||||
|
||||
{
|
||||
s8_t s = s8(" a \n");
|
||||
s = s8_trim(s);
|
||||
assert(s8_are_equal(s, s8("a")));
|
||||
}
|
||||
|
||||
{
|
||||
s8_t s = s8("C:/memes/the_thing.c");
|
||||
s8_t ss = s8_get_name_no_ext(s);
|
||||
assert(s8_are_equal(ss, s8("the_thing")));
|
||||
}
|
||||
|
||||
{
|
||||
s8_t s = s8_printf(arena, "%d%Sv%s", 32, s8("|"), ">");
|
||||
assert(s8_are_equal(s, s8("32|v>")));
|
||||
}
|
||||
|
||||
{
|
||||
s8_t s0 = s8("0123456789");
|
||||
s8_t s1 = s8_cut_start(&s0, 2);
|
||||
assert(s8_are_equal(s0, s8("23456789")));
|
||||
assert(s8_are_equal(s1, s8("01")));
|
||||
}
|
||||
|
||||
ma_destroy(arena);
|
||||
}
|
||||
|
||||
int main() {
|
||||
os_core_init();
|
||||
test_s8();
|
||||
os_test();
|
||||
debugf("Testing OK");
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user