Add core.cpp, testing changes

This commit is contained in:
Krzosa Karol
2024-01-14 10:22:39 +01:00
parent c375cdf04f
commit 37eed81ea5
7 changed files with 77 additions and 126 deletions

View File

@@ -1,42 +0,0 @@
#include "../core_library/core.c"
#define CL_Allocator MA_Arena *
#define CL_Allocate(a, s) MA_PushSizeNonZeroed(a, s)
#define CL_ASSERT IO_Assert
#define CL_VSNPRINTF stbsp_vsnprintf
#define CL_SNPRINTF stbsp_snprintf
#include "../standalone_libraries/clexer.c"
int main() {
// Unicode iteration over codepoints
{
S8_String s = "mrówka";
bool found_two_byte = false;
For(s) {
if (it.utf8_codepoint_byte_size == 2) {
found_two_byte = true;
IO_Assert(it.i == 2);
}
}
IO_Assert(found_two_byte);
}
{
MA_Scratch scratch;
S8_String filename = "../standalone_libraries/clexer.c";
S8_String file = OS_ReadFile(scratch, filename);
CL_Lexer lexer = CL_Begin(scratch, file.str, filename.str);
char buff[1024];
for (;;) {
CL_Token token = CL_Next(&lexer);
if (token.kind == CL_EOF) break;
if (token.kind != CL_PREPROC_INCLUDE) continue;
CL_Stringify(buff, sizeof(buff), &token);
IO_Printf("%s\n", buff);
}
}
}

View File

@@ -1,5 +1,3 @@
#include "../core_library/core.c"
void TestBootstrapArenaClear() {
MA_Arena *arena = MA_Bootstrap();
IO_Assert(arena->base_len != 0);
@@ -29,36 +27,6 @@ void TestBootstrapArenaClear() {
((char *)arena->memory.data)[arena->len - 1] = 0;
}
void TestScratch() {
MA_Arena *scratch_arena_test = NULL;
{
MA_Scratch scratch;
IO_Assert(scratch.checkpoint.arena->len == 0);
IO_Assert(scratch.checkpoint.arena->memory.data == NULL);
int *a = MA_PushStruct(scratch, int);
IO_Assert(scratch.checkpoint.arena->memory.data);
IO_Assert(scratch.checkpoint.arena->len == sizeof(int));
IO_Assert(scratch.checkpoint.arena);
scratch_arena_test = scratch.checkpoint.arena;
int b = 10;
IO_Assert(MA_IsPointerInside(scratch, a));
IO_Assert(!MA_IsPointerInside(scratch, &b));
}
{
MA_Scratch scratch;
IO_Assert(scratch_arena_test == scratch.checkpoint.arena);
IO_Assert(scratch.checkpoint.arena->len == 0);
MA_Scratch scratch2(scratch.checkpoint);
IO_Assert(scratch.checkpoint.arena != scratch2.checkpoint.arena);
MA_Scratch scratch3(scratch.checkpoint, scratch2.checkpoint);
IO_Assert(scratch3.checkpoint.arena != scratch2.checkpoint.arena);
}
}
void TestBuffer() {
char buffer[1024];
MA_Arena buffer_arena = MA_MakeFromBuffer(buffer, 1024);
@@ -98,12 +66,3 @@ void TestBootstrapExclusive() {
For(v) IO_Assert(it == i++);
v.dealloc();
}
int main() {
TestScratch();
TestBuffer();
TestCreateAllocate();
TestBootstrap();
TestBootstrapExclusive();
TestBootstrapArenaClear();
}

View File

@@ -1,4 +1,3 @@
#include "../core_library/core.c"
void TestExclusiveArenaBackedArray() {
MA_Scratch scratch;
MA_Arena ex = MA_Create();
@@ -118,12 +117,3 @@ void TestCopy() {
a.dealloc();
}
int main() {
TestExclusiveArenaBackedArray();
TestRemoveForLoop();
TestBasic();
TestReverseLoop();
TestCopy();
return 0;
}

63
tests/test_main.cpp Normal file
View File

@@ -0,0 +1,63 @@
#include "../core_library/core.cpp"
#include "test_table.cpp"
#include "test_array.cpp"
#include "test_arena.cpp"
void TestClexer();
int main() {
TestSimpleInsertAndIntegrity();
TestStrings();
TestExclusiveArenaBackedArray();
TestRemoveForLoop();
TestBasic();
TestReverseLoop();
TestCopy();
TestBuffer();
TestCreateAllocate();
TestBootstrap();
TestBootstrapExclusive();
TestBootstrapArenaClear();
TestClexer();
// Unicode iteration over codepoints
{
S8_String s = "mrówka";
bool found_two_byte = false;
For(s) {
if (it.utf8_codepoint_byte_size == 2) {
found_two_byte = true;
IO_Assert(it.i == 2);
}
}
IO_Assert(found_two_byte);
}
}
#define CL_Allocator MA_Arena *
#define CL_Allocate(a, s) MA_PushSizeNonZeroed(a, s)
#define CL_ASSERT IO_Assert
#define CL_VSNPRINTF stbsp_vsnprintf
#define CL_SNPRINTF stbsp_snprintf
#include "../standalone_libraries/clexer.c"
void TestClexer() {
MA_Scratch scratch;
S8_String filename = "../standalone_libraries/clexer.c";
S8_String file = OS_ReadFile(scratch, filename);
CL_Lexer lexer = CL_Begin(scratch, file.str, filename.str);
char buff[1024];
for (;;) {
CL_Token token = CL_Next(&lexer);
if (token.kind == CL_EOF) break;
if (token.kind != CL_PREPROC_INCLUDE) continue;
CL_Stringify(buff, sizeof(buff), &token);
// IO_Printf("%s\n", buff);
}
}

View File

@@ -1,5 +1,3 @@
#include "../core_library/core.c"
void TestSimpleInsertAndIntegrity() {
MA_Scratch scratch;
Table<uint64_t> table = {scratch};
@@ -36,9 +34,3 @@ void TestStrings() {
IO_Assert(table.gets("3")->i == 3);
table.dealloc();
}
int main() {
TestSimpleInsertAndIntegrity();
TestStrings();
return 0;
}