mirror of
https://github.com/open-goal/jak-project
synced 2026-09-08 03:46:51 -04:00
check in existing work
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
add_executable(goalc-test
|
||||
test_main.cpp
|
||||
test_test.cpp
|
||||
test_reader.cpp
|
||||
test_goos.cpp
|
||||
test_listener_deci2.cpp
|
||||
test_kernel.cpp
|
||||
test_CodeTester.cpp
|
||||
all_jak1_symbols.cpp)
|
||||
|
||||
target_link_libraries(goalc-test goos util listener runtime emitter gtest)
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,6 @@
|
||||
#ifndef JAK1_ALL_JAK1_SYMBOLS_H
|
||||
#define JAK1_ALL_JAK1_SYMBOLS_H
|
||||
|
||||
extern const char* all_syms[7941];
|
||||
|
||||
#endif // JAK1_ALL_JAK1_SYMBOLS_H
|
||||
@@ -0,0 +1,167 @@
|
||||
/*!
|
||||
* @file test_CodeTester.cpp
|
||||
* Tests for the CodeTester, a tool for testing the emitter by emitting code and running it
|
||||
* from within the test application.
|
||||
*/
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "goalc/emitter/CodeTester.h"
|
||||
#include "goalc/emitter/IGen.h"
|
||||
|
||||
using namespace goal;
|
||||
|
||||
TEST(CodeTester, prologue) {
|
||||
CodeTester tester;
|
||||
tester.init_code_buffer(256);
|
||||
tester.emit_push_all_gprs();
|
||||
// check we generate the right code for pushing all gpr's
|
||||
EXPECT_EQ(tester.dump_to_hex_string(),
|
||||
"50 51 52 53 54 55 56 57 41 50 41 51 41 52 41 53 41 54 41 55 41 56 41 57");
|
||||
}
|
||||
|
||||
TEST(CodeTester, epilogue) {
|
||||
CodeTester tester;
|
||||
tester.init_code_buffer(256);
|
||||
tester.emit_pop_all_gprs();
|
||||
// check we generate the right code for popping all gpr's
|
||||
EXPECT_EQ(tester.dump_to_hex_string(),
|
||||
"41 5f 41 5e 41 5d 41 5c 41 5b 41 5a 41 59 41 58 5f 5e 5d 5c 5b 5a 59 58");
|
||||
}
|
||||
|
||||
TEST(CodeTester, execute_return) {
|
||||
CodeTester tester;
|
||||
tester.init_code_buffer(256);
|
||||
// test creating a function which simply returns
|
||||
tester.emit_return();
|
||||
// and execute it!
|
||||
tester.execute();
|
||||
}
|
||||
|
||||
TEST(CodeTester, execute_push_pop_gprs) {
|
||||
CodeTester tester;
|
||||
tester.init_code_buffer(256);
|
||||
// test we can push/pop gprs without crashing.
|
||||
tester.emit_push_all_gprs();
|
||||
tester.emit_pop_all_gprs();
|
||||
tester.emit_return();
|
||||
tester.execute();
|
||||
}
|
||||
|
||||
TEST(CodeTester, load_constant_64_and_move_gpr_gpr_64) {
|
||||
std::vector<u64> u64_constants = {0, UINT64_MAX, INT64_MAX, 7, 12};
|
||||
|
||||
// test we can load a 64-bit constant into all gprs, move it to any other gpr, and return it.
|
||||
// rsp is skipping because that's the stack pointer and would prevent us from popping gprs after
|
||||
|
||||
CodeTester tester;
|
||||
tester.init_code_buffer(256);
|
||||
|
||||
for (auto constant : u64_constants) {
|
||||
for (int r1 = 0; r1 < 16; r1++) {
|
||||
if (r1 == RSP) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int r2 = 0; r2 < 16; r2++) {
|
||||
if (r2 == RSP) {
|
||||
continue;
|
||||
}
|
||||
tester.clear();
|
||||
tester.emit_push_all_gprs(true);
|
||||
tester.emit(IGen::mov_gpr64_u64(r1, constant));
|
||||
tester.emit(IGen::mov_gpr64_gpr64(r2, r1));
|
||||
tester.emit(IGen::mov_gpr64_gpr64(RAX, r2));
|
||||
tester.emit_pop_all_gprs(true);
|
||||
tester.emit_return();
|
||||
EXPECT_EQ(tester.execute(), constant);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST(CodeTester, load_constant_32_unsigned) {
|
||||
std::vector<u64> u64_constants = {0, UINT32_MAX, INT32_MAX, 7, 12};
|
||||
|
||||
// test loading 32-bit constants, with all upper 32-bits zero.
|
||||
// this uses a different opcode than 64-bit loads.
|
||||
CodeTester tester;
|
||||
tester.init_code_buffer(256);
|
||||
|
||||
for (auto constant : u64_constants) {
|
||||
for (int r1 = 0; r1 < 16; r1++) {
|
||||
if (r1 == RSP) {
|
||||
continue;
|
||||
}
|
||||
|
||||
tester.clear();
|
||||
tester.emit_push_all_gprs(true);
|
||||
tester.emit(IGen::mov_gpr64_u32(r1, constant));
|
||||
tester.emit(IGen::mov_gpr64_gpr64(RAX, r1));
|
||||
tester.emit_pop_all_gprs(true);
|
||||
tester.emit_return();
|
||||
EXPECT_EQ(tester.execute(), constant);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST(CodeTester, load_constant_32_signed) {
|
||||
std::vector<s32> s32_constants = {0, 1, INT32_MAX, INT32_MIN, 12, -1};
|
||||
|
||||
// test loading signed 32-bit constants. for values < 0 this will sign extend.
|
||||
CodeTester tester;
|
||||
tester.init_code_buffer(256);
|
||||
|
||||
for (auto constant : s32_constants) {
|
||||
for (int r1 = 0; r1 < 16; r1++) {
|
||||
if (r1 == RSP) {
|
||||
continue;
|
||||
}
|
||||
|
||||
tester.clear();
|
||||
tester.emit_push_all_gprs(true);
|
||||
tester.emit(IGen::mov_gpr64_s32(r1, constant));
|
||||
tester.emit(IGen::mov_gpr64_gpr64(RAX, r1));
|
||||
tester.emit_pop_all_gprs(true);
|
||||
tester.emit_return();
|
||||
EXPECT_EQ(tester.execute(), constant);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST(CodeTester, xmm_move) {
|
||||
std::vector<u32> u32_constants = {0, INT32_MAX, UINT32_MAX, 17};
|
||||
|
||||
// test moving between xmms (32-bit) and gprs.
|
||||
CodeTester tester;
|
||||
tester.init_code_buffer(256);
|
||||
|
||||
for(auto constant : u32_constants) {
|
||||
for(int r1 = 0; r1 < 16; r1++) {
|
||||
if(r1 == RSP) {
|
||||
continue;
|
||||
}
|
||||
for(int r2 = 0; r2 < 16; r2++) {
|
||||
if(r2 == RSP) {
|
||||
continue;
|
||||
}
|
||||
for(int r3 = 0; r3 < 16; r3++) {
|
||||
for(int r4 = 0; r4 < 16; r4++) {
|
||||
tester.clear();
|
||||
tester.emit_push_all_gprs(true);
|
||||
// move constant to gpr
|
||||
tester.emit(IGen::mov_gpr64_u32(r1, constant));
|
||||
// move gpr to xmm
|
||||
tester.emit(IGen::movd_xmm32_gpr32(get_nth_xmm(r3), r1));
|
||||
// move xmm to xmm
|
||||
tester.emit(IGen::mov_xmm32_xmm32(get_nth_xmm(r4), get_nth_xmm(r3)));
|
||||
// move xmm to gpr
|
||||
tester.emit(IGen::movd_gpr32_xmm32(r2, get_nth_xmm(r4)));
|
||||
// return!
|
||||
tester.emit(IGen::mov_gpr64_gpr64(RAX, r2));
|
||||
tester.emit_return();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+1289
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1 @@
|
||||
(define x 23)
|
||||
@@ -0,0 +1,389 @@
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include "gtest/gtest.h"
|
||||
#include "common/symbols.h"
|
||||
#include "game/kernel/fileio.h"
|
||||
#include "game/kernel/kboot.h"
|
||||
#include "game/kernel/kprint.h"
|
||||
#include "game/kernel/kdsnetm.h"
|
||||
#include "game/kernel/kscheme.h"
|
||||
#include "all_jak1_symbols.h"
|
||||
|
||||
TEST(Kernel, strend) {
|
||||
char test[] = "test";
|
||||
char* end = strend(test);
|
||||
EXPECT_TRUE(*end == 0);
|
||||
EXPECT_TRUE(end - test == 4);
|
||||
}
|
||||
|
||||
TEST(Kernel, kstrcpy) {
|
||||
char buffer[24];
|
||||
memset(buffer, 1, 24);
|
||||
kstrcpy(buffer, "test");
|
||||
EXPECT_TRUE(buffer[0] == 't');
|
||||
EXPECT_TRUE(buffer[1] == 'e');
|
||||
EXPECT_TRUE(buffer[2] == 's');
|
||||
EXPECT_TRUE(buffer[3] == 't');
|
||||
EXPECT_TRUE(buffer[4] == '\0');
|
||||
EXPECT_TRUE(buffer[5] == 1);
|
||||
}
|
||||
|
||||
TEST(Kernel, kstrcpyup) {
|
||||
char buffer[24];
|
||||
memset(buffer, 1, 24);
|
||||
kstrcpyup(buffer, "tesT");
|
||||
EXPECT_TRUE(buffer[0] == 'T');
|
||||
EXPECT_TRUE(buffer[1] == 'E');
|
||||
EXPECT_TRUE(buffer[2] == 'S');
|
||||
EXPECT_TRUE(buffer[3] == 'T');
|
||||
EXPECT_TRUE(buffer[4] == '\0');
|
||||
EXPECT_TRUE(buffer[5] == 1);
|
||||
}
|
||||
|
||||
TEST(Kernel, kstrcat) {
|
||||
char buffer[24] = "test";
|
||||
kstrcat(buffer, "cat");
|
||||
const char expected[] = "testcat";
|
||||
for (int i = 0; i < 8; i++) {
|
||||
EXPECT_TRUE(expected[i] == buffer[i]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Kernel, kstrncat) {
|
||||
{
|
||||
char buffer[24] = "test";
|
||||
kstrncat(buffer, "cat", 6);
|
||||
const char expected[] = "testca";
|
||||
for (int i = 0; i < 7; i++) {
|
||||
EXPECT_TRUE(expected[i] == buffer[i]);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
char buffer[24] = "test";
|
||||
kstrncat(buffer, "cat", 80);
|
||||
const char expected[] = "testcat";
|
||||
for (int i = 0; i < 8; i++) {
|
||||
EXPECT_TRUE(expected[i] == buffer[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Kernel, kstrinsert) {
|
||||
char buffer[24];
|
||||
memset(buffer, 1, 24);
|
||||
buffer[0] = 't';
|
||||
buffer[1] = 'o';
|
||||
buffer[2] = '\0';
|
||||
|
||||
EXPECT_TRUE(buffer == kstrinsert(buffer, 'a', 2));
|
||||
|
||||
EXPECT_TRUE(buffer[0] == 'a');
|
||||
EXPECT_TRUE(buffer[1] == 'a');
|
||||
EXPECT_TRUE(buffer[2] == 't');
|
||||
EXPECT_TRUE(buffer[3] == 'o');
|
||||
EXPECT_TRUE(buffer[4] == '\0');
|
||||
EXPECT_TRUE(buffer[5] == 1);
|
||||
}
|
||||
|
||||
TEST(Kernel, basename) {
|
||||
std::string x;
|
||||
|
||||
char name0[] = "test1.asdf";
|
||||
x = basename_goal(name0);
|
||||
EXPECT_EQ(x, "test1.asdf");
|
||||
|
||||
char name1[] = "a/b/test1.asdf";
|
||||
x = basename_goal(name1);
|
||||
EXPECT_EQ(x, "test1.asdf");
|
||||
|
||||
char name2[] = "a\\b\\test1.asdf";
|
||||
x = basename_goal(name2);
|
||||
EXPECT_EQ(x, "test1.asdf");
|
||||
}
|
||||
|
||||
TEST(Kernel, DecodeFileName) {
|
||||
std::string x;
|
||||
x = DecodeFileName("$TEXTURE/beans");
|
||||
EXPECT_EQ(x, "host:data/texture-page7/beans.go");
|
||||
|
||||
x = DecodeFileName("$ART_GROUP/stuff");
|
||||
EXPECT_EQ(x, "host:data/art-group6/stuff-ag.go");
|
||||
|
||||
x = DecodeFileName("$LEVEL/my-level");
|
||||
EXPECT_EQ(x, "host:data/level30/my-level-bt.go");
|
||||
|
||||
x = DecodeFileName("$LEVEL/my-level.123");
|
||||
EXPECT_EQ(x, "host:data/level30/my-level.123");
|
||||
|
||||
x = DecodeFileName("$DATA/my-data");
|
||||
EXPECT_EQ(x, "host:data/my-data.go");
|
||||
|
||||
x = DecodeFileName("$CODE/my-code");
|
||||
EXPECT_EQ(x, "host:game/obj/my-code.o");
|
||||
|
||||
x = DecodeFileName("$RES/my-res");
|
||||
EXPECT_EQ(x, "host:data/res1/my-res.go");
|
||||
|
||||
x = DecodeFileName("asdf");
|
||||
EXPECT_EQ(x, "host:game/obj/asdf.o");
|
||||
}
|
||||
|
||||
TEST(Kernel, reverse) {
|
||||
char in1[] = "asdf";
|
||||
reverse(in1);
|
||||
char in2[] = "asdfg";
|
||||
reverse(in2);
|
||||
EXPECT_EQ("fdsa", std::string(in1));
|
||||
EXPECT_EQ("gfdsa", std::string(in2));
|
||||
}
|
||||
|
||||
TEST(Kernel, ftoa) {
|
||||
char buffer[128];
|
||||
ftoa(buffer, 1.23, 1, ' ', 4, 0);
|
||||
EXPECT_EQ("1.2300", std::string(buffer));
|
||||
|
||||
ftoa(buffer, -1.23, 1, ' ', 4, 0);
|
||||
EXPECT_EQ("-1.2300", std::string(buffer));
|
||||
|
||||
ftoa(buffer, 1., 1, ' ', 4, 0);
|
||||
EXPECT_EQ("1.0000", std::string(buffer));
|
||||
|
||||
ftoa(buffer, 1., 1, ' ', 0, 0);
|
||||
EXPECT_EQ("1", std::string(buffer));
|
||||
|
||||
ftoa(buffer, 1., 1, ' ', 1, 0);
|
||||
EXPECT_EQ("1.0", std::string(buffer));
|
||||
|
||||
ftoa(buffer, 0.f / 0.f, 1, ' ', 4, 0);
|
||||
EXPECT_EQ("NaN", std::string(buffer));
|
||||
|
||||
ftoa(buffer, 1., 8, ' ', 1, 0);
|
||||
EXPECT_EQ(" 1.0", std::string(buffer));
|
||||
|
||||
ftoa(buffer, -1., 8, '0', 1, 0);
|
||||
EXPECT_EQ("0000-1.0", std::string(buffer));
|
||||
|
||||
ftoa(buffer, 0.f / 0.f, 8, ' ', 4, 0);
|
||||
EXPECT_EQ(" NaN", std::string(buffer));
|
||||
|
||||
ftoa(buffer, 0.1, 1, ' ', 4, 0);
|
||||
EXPECT_EQ("0.1000", std::string(buffer));
|
||||
}
|
||||
|
||||
TEST(Kernel, itoa_base_10) {
|
||||
char buffer[128];
|
||||
|
||||
kprint_init_globals();
|
||||
|
||||
// simple print 1
|
||||
kitoa(buffer, 1, 10, -1, ' ', 0);
|
||||
EXPECT_EQ("1", std::string(buffer));
|
||||
|
||||
// simple print 0
|
||||
kitoa(buffer, 0, 10, -1, ' ', 0);
|
||||
EXPECT_EQ("0", std::string(buffer));
|
||||
|
||||
// simple print -1
|
||||
kitoa(buffer, -1, 10, -1, ' ', 0);
|
||||
EXPECT_EQ("-1", std::string(buffer));
|
||||
|
||||
// print negative which asks to be truncated, but shouldn't be
|
||||
kitoa(buffer, -123456, 10, 4, ' ', 0);
|
||||
EXPECT_EQ("-123456", std::string(buffer));
|
||||
|
||||
// print an interesting number
|
||||
kitoa(buffer, 123321456789, 10, -1, ' ', 0);
|
||||
EXPECT_EQ("123321456789", std::string(buffer));
|
||||
|
||||
// MAX
|
||||
kitoa(buffer, INT64_MAX, 10, -1, ' ', 0);
|
||||
EXPECT_EQ("9223372036854775807", std::string(buffer));
|
||||
|
||||
// MIN
|
||||
kitoa(buffer, INT64_MIN, 10, -1, ' ', 0);
|
||||
EXPECT_EQ("-9223372036854775808", std::string(buffer));
|
||||
|
||||
// Pad
|
||||
kitoa(buffer, 3, 10, 4, 'j', 0);
|
||||
EXPECT_EQ("jjj3", std::string(buffer));
|
||||
|
||||
kitoa(buffer, 333, 10, 4, 'j', 0);
|
||||
EXPECT_EQ("j333", std::string(buffer));
|
||||
|
||||
kitoa(buffer, 3333, 10, 4, 'j', 0);
|
||||
EXPECT_EQ("3333", std::string(buffer));
|
||||
|
||||
kitoa(buffer, 33333, 10, 4, 'j', 0);
|
||||
EXPECT_EQ("33333", std::string(buffer));
|
||||
}
|
||||
|
||||
TEST(Kernel, itoa_base_2) {
|
||||
char buffer[128];
|
||||
|
||||
kprint_init_globals();
|
||||
kitoa(buffer, 1, 2, -1, ' ', 0);
|
||||
EXPECT_EQ("1", std::string(buffer));
|
||||
|
||||
kitoa(buffer, -1, 2, -1, ' ', 0);
|
||||
EXPECT_EQ("1111111111111111111111111111111111111111111111111111111111111111",
|
||||
std::string(buffer));
|
||||
|
||||
kitoa(buffer, -1, 2, 0, ' ', 0);
|
||||
EXPECT_EQ("1111111111111111111111111111111111111111111111111111111111111111",
|
||||
std::string(buffer));
|
||||
|
||||
kitoa(buffer, -1, 2, 5, ' ', 0);
|
||||
EXPECT_EQ("-11111", std::string(buffer));
|
||||
|
||||
kitoa(buffer, 0, 2, -1, ' ', 0);
|
||||
EXPECT_EQ("0", std::string(buffer));
|
||||
|
||||
kitoa(buffer, INT64_MAX, 2, -1, ' ', 0);
|
||||
EXPECT_EQ("111111111111111111111111111111111111111111111111111111111111111", std::string(buffer));
|
||||
|
||||
kitoa(buffer, 476, 2, -1, ' ', 0);
|
||||
EXPECT_EQ("111011100", std::string(buffer));
|
||||
|
||||
kitoa(buffer, 476, 2, 11, 'j', 0);
|
||||
EXPECT_EQ("jj111011100", std::string(buffer));
|
||||
|
||||
kitoa(buffer, INT64_MIN, 2, 0, ' ', 0);
|
||||
EXPECT_EQ("1000000000000000000000000000000000000000000000000000000000000000",
|
||||
std::string(buffer));
|
||||
}
|
||||
|
||||
TEST(Kernel, itoa_base_16) {
|
||||
char buffer[128];
|
||||
|
||||
kprint_init_globals();
|
||||
kitoa(buffer, 1, 16, -1, ' ', 0);
|
||||
EXPECT_EQ("1", std::string(buffer));
|
||||
|
||||
kitoa(buffer, -1, 16, -1, ' ', 0);
|
||||
EXPECT_EQ("ffffffffffffffff",
|
||||
std::string(buffer));
|
||||
|
||||
kitoa(buffer, -1, 16, 5, ' ', 0);
|
||||
EXPECT_EQ("-fffff", std::string(buffer));
|
||||
|
||||
kitoa(buffer, 0, 16, -1, ' ', 0);
|
||||
EXPECT_EQ("0", std::string(buffer));
|
||||
|
||||
kitoa(buffer, INT64_MAX, 16, -1, ' ', 0);
|
||||
EXPECT_EQ("7fffffffffffffff", std::string(buffer));
|
||||
|
||||
kitoa(buffer, 195935983, 16, -1, ' ', 0);
|
||||
EXPECT_EQ("badbeef", std::string(buffer));
|
||||
|
||||
kitoa(buffer, 195935983, 16, 11, 'j', 0);
|
||||
EXPECT_EQ("jjjjbadbeef", std::string(buffer));
|
||||
|
||||
kitoa(buffer, INT64_MIN, 16, 0, ' ', 0);
|
||||
EXPECT_EQ("8000000000000000",
|
||||
std::string(buffer));
|
||||
}
|
||||
|
||||
namespace {
|
||||
void setup_hack_heaps(void* mem, int size) {
|
||||
g_ee_main_mem = (u8*)mem;
|
||||
int heap_size = (size - HEAP_START) / 2;
|
||||
MasterDebug = 1;
|
||||
EXPECT_TRUE(heap_size > 8 * 1024 * 1024);
|
||||
kmalloc_init_globals();
|
||||
kprint_init_globals();
|
||||
|
||||
kinitheap(kglobalheap, Ptr<u8>(HEAP_START), heap_size);
|
||||
kinitheap(kdebugheap, Ptr<u8>(HEAP_START + heap_size), heap_size);
|
||||
init_output();
|
||||
init_crc();
|
||||
|
||||
// create a fake symbol table
|
||||
auto symbol_table = kmalloc(kglobalheap, 0x20000, KMALLOC_MEMSET, "symbol-table").cast<u32>();
|
||||
s7 = symbol_table + (GOAL_MAX_SYMBOLS / 2) * 8 + BASIC_OFFSET;
|
||||
SymbolTable2 = symbol_table + BASIC_OFFSET;
|
||||
LastSymbol = symbol_table + 0xff00;
|
||||
NumSymbols = 0;
|
||||
|
||||
// set up the empty pair (might not be needed?)
|
||||
*(s7 + FIX_SYM_EMPTY_CAR) = (s7 + FIX_SYM_EMPTY_PAIR).offset;
|
||||
*(s7 + FIX_SYM_EMPTY_CDR) = (s7 + FIX_SYM_EMPTY_PAIR).offset;
|
||||
|
||||
// need to set up 'global fixed symbol so allocating memory works.
|
||||
*(s7 + FIX_SYM_GLOBAL_HEAP) = kglobalheap.offset;
|
||||
|
||||
// allocate fundamental types
|
||||
alloc_and_init_type((s7 + FIX_SYM_TYPE_TYPE).cast<Symbol>(), 9);
|
||||
alloc_and_init_type((s7 + FIX_SYM_SYMBOL_TYPE).cast<Symbol>(), 9);
|
||||
alloc_and_init_type((s7 + FIX_SYM_STRING_TYPE).cast<Symbol>(), 9);
|
||||
alloc_and_init_type((s7 + FIX_SYM_FUNCTION_TYPE).cast<Symbol>(), 9);
|
||||
// booleans
|
||||
set_fixed_symbol(FIX_SYM_FALSE, "#f", s7.offset + FIX_SYM_FALSE);
|
||||
set_fixed_symbol(FIX_SYM_TRUE, "#t", s7.offset + FIX_SYM_TRUE);
|
||||
// heap symbols
|
||||
set_fixed_symbol(FIX_SYM_GLOBAL_HEAP, "global", kglobalheap.offset);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST(Kernel, PrintBuffer) {
|
||||
// hack to setup
|
||||
constexpr int size = 32 * 1024 * 1024;
|
||||
auto mem = new u8[size];
|
||||
setup_hack_heaps(mem, size);
|
||||
clear_print();
|
||||
cprintf("test!\n");
|
||||
|
||||
std::string result = PrintBufArea.cast<char>().c() + sizeof(GoalMessageHeader);
|
||||
EXPECT_EQ(result, "test!\n");
|
||||
|
||||
delete[] mem;
|
||||
|
||||
// more complicated tests for format will be done from within GOAL.
|
||||
}
|
||||
|
||||
|
||||
TEST(Kernel, HashTable) {
|
||||
constexpr int size = 32 * 1024 * 1024;
|
||||
auto mem = new u8[size];
|
||||
setup_hack_heaps(mem, size);
|
||||
|
||||
// check crc32 - the game has a hardcoded hash for _empty_ so we should check
|
||||
// that our implementation matches this hardcoded value.
|
||||
|
||||
const char empty_sym_name[] = "_empty_";
|
||||
const char wrong_sym_name[] = "_Empty_";
|
||||
EXPECT_EQ(EMPTY_HASH, crc32((const u8*)empty_sym_name, strlen(empty_sym_name)));
|
||||
EXPECT_NE(EMPTY_HASH, crc32((const u8*)wrong_sym_name, strlen(wrong_sym_name)));
|
||||
|
||||
std::unordered_map<std::string, u32> symbol_locations;
|
||||
std::unordered_set<u32> unique_locations;
|
||||
|
||||
for(auto name : all_syms) {
|
||||
auto loc = intern_from_c(name).offset;
|
||||
symbol_locations[name] = loc;
|
||||
unique_locations.insert(loc);
|
||||
}
|
||||
|
||||
EXPECT_EQ(7941, symbol_locations.size());
|
||||
EXPECT_EQ(7941, unique_locations.size());
|
||||
|
||||
for(auto name : all_syms) {
|
||||
EXPECT_EQ(symbol_locations.at(name), intern_from_c(name).offset);
|
||||
}
|
||||
|
||||
EXPECT_EQ(intern_from_c("global").offset - s7.offset, FIX_SYM_GLOBAL_HEAP);
|
||||
EXPECT_EQ(intern_from_c("#f").offset - s7.offset, 0);
|
||||
EXPECT_EQ(intern_from_c("#t").offset - s7.offset, 8);
|
||||
EXPECT_EQ(intern_from_c("_empty_").offset - s7.offset, FIX_SYM_EMPTY_PAIR);
|
||||
|
||||
// expect no crc32 hash collisions. This doesn't matter, but it's nice to know.
|
||||
std::unordered_set<u32> crc32s;
|
||||
for(auto name : all_syms) {
|
||||
crc32s.insert(crc32((const u8*)name, strlen(name)));
|
||||
}
|
||||
EXPECT_EQ(7941, crc32s.size());
|
||||
|
||||
delete[] mem;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
#include "gtest/gtest.h"
|
||||
#include "goalc/listener/Listener.h"
|
||||
#include "goalc/listener/Deci2Server.h"
|
||||
|
||||
using namespace listener;
|
||||
|
||||
namespace {
|
||||
bool always_false() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Listener, ListenerCreation) {
|
||||
listener::Listener l;
|
||||
}
|
||||
|
||||
TEST(Listener, DeciCreation) {
|
||||
Deci2Server s(always_false);
|
||||
}
|
||||
|
||||
TEST(Listener, DeciInit) {
|
||||
Deci2Server s(always_false);
|
||||
EXPECT_TRUE(s.init());
|
||||
}
|
||||
|
||||
//TEST(Listener, TwoDeciServers) {
|
||||
// Deci2Server s1, s2;
|
||||
// EXPECT_TRUE(s1.init());
|
||||
// EXPECT_TRUE(s2.init());
|
||||
//}
|
||||
|
||||
/*!
|
||||
* Try to connect when no Deci2Server is running
|
||||
*/
|
||||
TEST(Listener, ListenToNothing) {
|
||||
Listener l;
|
||||
EXPECT_FALSE(l.connect_to_target());
|
||||
l.disconnect();
|
||||
}
|
||||
|
||||
TEST(Listener, DeciCheckNoListener) {
|
||||
Deci2Server s(always_false);
|
||||
EXPECT_TRUE(s.init());
|
||||
EXPECT_FALSE(s.check_for_listener());
|
||||
EXPECT_FALSE(s.check_for_listener());
|
||||
EXPECT_FALSE(s.check_for_listener());
|
||||
}
|
||||
|
||||
TEST(Listener, DeciThenListener) {
|
||||
for(int i = 0; i < 10; i++) {
|
||||
Deci2Server s(always_false);
|
||||
EXPECT_TRUE(s.init());
|
||||
EXPECT_FALSE(s.check_for_listener());
|
||||
EXPECT_FALSE(s.check_for_listener());
|
||||
EXPECT_FALSE(s.check_for_listener());
|
||||
Listener l;
|
||||
EXPECT_FALSE(s.check_for_listener());
|
||||
EXPECT_FALSE(s.check_for_listener());
|
||||
EXPECT_TRUE(l.connect_to_target());
|
||||
// kind of a hack.
|
||||
while(!s.check_for_listener()) {
|
||||
printf("...\n");
|
||||
}
|
||||
|
||||
EXPECT_TRUE(s.check_for_listener());
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Listener, DeciThenListener2) {
|
||||
for(int i = 0; i < 10; i++) {
|
||||
Deci2Server s(always_false);
|
||||
EXPECT_TRUE(s.init());
|
||||
EXPECT_FALSE(s.check_for_listener());
|
||||
EXPECT_FALSE(s.check_for_listener());
|
||||
EXPECT_FALSE(s.check_for_listener());
|
||||
Listener l;
|
||||
EXPECT_FALSE(s.check_for_listener());
|
||||
EXPECT_FALSE(s.check_for_listener());
|
||||
EXPECT_TRUE(l.connect_to_target());
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Listener, ListenerThenDeci) {
|
||||
for(int i = 0; i < 10; i++) {
|
||||
Listener l;
|
||||
EXPECT_FALSE(l.connect_to_target());
|
||||
Deci2Server s(always_false);
|
||||
EXPECT_TRUE(s.init());
|
||||
EXPECT_FALSE(s.check_for_listener());
|
||||
EXPECT_TRUE(l.connect_to_target());
|
||||
while(!s.check_for_listener()) {
|
||||
printf("...\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Listener, ListenerMultipleDecis) {
|
||||
Listener l;
|
||||
EXPECT_FALSE(l.connect_to_target());
|
||||
{
|
||||
Deci2Server s(always_false);
|
||||
EXPECT_TRUE(s.init());
|
||||
EXPECT_FALSE(s.check_for_listener());
|
||||
EXPECT_TRUE(l.connect_to_target());
|
||||
while(!s.check_for_listener()) {
|
||||
printf("...\n");
|
||||
}
|
||||
l.disconnect();
|
||||
}
|
||||
|
||||
{
|
||||
Deci2Server s(always_false);
|
||||
EXPECT_TRUE(s.init());
|
||||
EXPECT_FALSE(s.check_for_listener());
|
||||
EXPECT_TRUE(l.connect_to_target());
|
||||
while(!s.check_for_listener()) {
|
||||
printf("...\n");
|
||||
}
|
||||
l.disconnect();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
@@ -0,0 +1,332 @@
|
||||
/*!
|
||||
* @file test_reader.cpp
|
||||
* Test the reader.
|
||||
* For some reason this runs at ~5 fps in CLion IDE.
|
||||
*/
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "goalc/goos/Reader.h"
|
||||
#include "goalc/util/file_io.h"
|
||||
|
||||
using namespace goos;
|
||||
|
||||
TEST(GoosReader, Construction) {
|
||||
// test that reader is able to find the source directory
|
||||
Reader reader;
|
||||
}
|
||||
|
||||
namespace {
|
||||
bool check_first_integer(Object o, int64_t x) {
|
||||
return o.as_pair()->cdr.as_pair()->car.as_int() == x;
|
||||
}
|
||||
|
||||
bool check_first_float(Object o, double x) {
|
||||
return o.as_pair()->cdr.as_pair()->car.as_float() == x;
|
||||
}
|
||||
|
||||
bool check_first_symbol(Object o, const std::string& sym) {
|
||||
return o.as_pair()->cdr.as_pair()->car.as_symbol()->name == sym;
|
||||
}
|
||||
|
||||
bool check_first_string(Object o, const std::string& str) {
|
||||
return o.as_pair()->cdr.as_pair()->car.as_string()->data == str;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST(GoosReader, Integer) {
|
||||
Reader reader;
|
||||
EXPECT_TRUE(check_first_integer(reader.read_from_string("123"), 123));
|
||||
EXPECT_TRUE(check_first_integer(reader.read_from_string("1"), 1));
|
||||
EXPECT_TRUE(check_first_integer(reader.read_from_string("-1"), -1));
|
||||
EXPECT_TRUE(check_first_integer(reader.read_from_string("0"), 0));
|
||||
EXPECT_TRUE(check_first_integer(reader.read_from_string("9223372036854775807"), INT64_MAX));
|
||||
EXPECT_TRUE(check_first_integer(reader.read_from_string("-9223372036854775808"), INT64_MIN));
|
||||
|
||||
EXPECT_TRUE(check_first_integer(reader.read_from_string("-0"), 0));
|
||||
EXPECT_TRUE(check_first_integer(reader.read_from_string("-000000"), 0));
|
||||
|
||||
EXPECT_TRUE(check_first_integer(
|
||||
reader.read_from_string(
|
||||
"-0000000000000000000000000000000000000000000000000000000000000000000000000000000001"),
|
||||
-1));
|
||||
|
||||
EXPECT_TRUE(reader.read_from_string("--0").as_pair()->cdr.as_pair()->car.is_symbol());
|
||||
// too big or too small.
|
||||
EXPECT_ANY_THROW(reader.read_from_string("9223372036854775808"));
|
||||
EXPECT_ANY_THROW(reader.read_from_string("-9223372036854775809"));
|
||||
}
|
||||
|
||||
TEST(GoosReader, Hex) {
|
||||
Reader reader;
|
||||
EXPECT_TRUE(check_first_integer(reader.read_from_string("#x0"), 0));
|
||||
EXPECT_TRUE(check_first_integer(reader.read_from_string("#x1"), 1));
|
||||
EXPECT_TRUE(check_first_integer(reader.read_from_string("#xf"), 15));
|
||||
EXPECT_TRUE(check_first_integer(reader.read_from_string("#xF"), 15));
|
||||
EXPECT_TRUE(check_first_integer(reader.read_from_string("#x0F"), 15));
|
||||
EXPECT_TRUE(check_first_integer(
|
||||
reader.read_from_string("#x0000000000000000000000000000000000000000000000000000f"), 15));
|
||||
|
||||
EXPECT_TRUE(check_first_integer(reader.read_from_string("#xffffffff"), UINT32_MAX));
|
||||
EXPECT_TRUE(check_first_integer(reader.read_from_string("#x100000000"), (1LL << 32LL)));
|
||||
EXPECT_TRUE(check_first_integer(reader.read_from_string("#x7FFFFFFFFFFFFFFF"), INT64_MAX));
|
||||
EXPECT_TRUE(check_first_integer(reader.read_from_string("#x8000000000000000"), INT64_MIN));
|
||||
EXPECT_TRUE(check_first_integer(reader.read_from_string("#xffffffffffffffff"), -1));
|
||||
|
||||
EXPECT_ANY_THROW(reader.read_from_string("#x10000000000000000"));
|
||||
|
||||
EXPECT_TRUE(check_first_symbol(reader.read_from_string("#x"), "#x"));
|
||||
EXPECT_TRUE(check_first_symbol(reader.read_from_string("#x-1"), "#x-1"));
|
||||
EXPECT_TRUE(check_first_symbol(reader.read_from_string("#x.1"), "#x.1"));
|
||||
}
|
||||
|
||||
TEST(GoosReader, Binary) {
|
||||
Reader reader;
|
||||
|
||||
EXPECT_TRUE(check_first_integer(reader.read_from_string("#b0"), 0));
|
||||
EXPECT_TRUE(check_first_integer(reader.read_from_string("#b0000000000"), 0));
|
||||
EXPECT_TRUE(check_first_integer(
|
||||
reader.read_from_string("#b000000000000000000000000000000000000000000000000000000000000000000"
|
||||
"00000000000000000000000000000000"),
|
||||
0));
|
||||
EXPECT_TRUE(check_first_integer(reader.read_from_string("#b1"), 1));
|
||||
EXPECT_TRUE(check_first_integer(reader.read_from_string("#b10"), 2));
|
||||
EXPECT_TRUE(check_first_integer(reader.read_from_string("#b01011"), 11));
|
||||
EXPECT_TRUE(check_first_integer(
|
||||
reader.read_from_string("#b1111111111111111111111111111111111111111111111111111111111111111"),
|
||||
-1));
|
||||
EXPECT_TRUE(check_first_integer(
|
||||
reader.read_from_string(
|
||||
"#b000001111111111111111111111111111111111111111111111111111111111111111"),
|
||||
-1));
|
||||
|
||||
EXPECT_TRUE(check_first_integer(
|
||||
reader.read_from_string("#b0111111111111111111111111111111111111111111111111111111111111111"),
|
||||
INT64_MAX));
|
||||
EXPECT_TRUE(check_first_integer(
|
||||
reader.read_from_string("#b1000000000000000000000000000000000000000000000000000000000000000"),
|
||||
INT64_MIN));
|
||||
|
||||
EXPECT_ANY_THROW(reader.read_from_string(
|
||||
"#b11111111111111111111111111111111111111111111111111111111111111111"));
|
||||
|
||||
EXPECT_TRUE(check_first_symbol(reader.read_from_string("#b"), "#b"));
|
||||
EXPECT_TRUE(check_first_symbol(reader.read_from_string("#b-1"), "#b-1"));
|
||||
EXPECT_TRUE(check_first_symbol(reader.read_from_string("#b.1"), "#b.1"));
|
||||
}
|
||||
|
||||
TEST(GoosReader, Float) {
|
||||
Reader reader;
|
||||
|
||||
EXPECT_TRUE(check_first_float(reader.read_from_string("1.6"), 1.6));
|
||||
EXPECT_TRUE(check_first_float(reader.read_from_string("0000001.6"), 1.6));
|
||||
EXPECT_TRUE(check_first_float(reader.read_from_string("0.6"), 0.6));
|
||||
EXPECT_TRUE(check_first_float(reader.read_from_string("00000.6"), 0.6));
|
||||
EXPECT_TRUE(check_first_float(reader.read_from_string("-0.6"), -0.6));
|
||||
EXPECT_TRUE(check_first_float(reader.read_from_string("-000000.6"), -0.6));
|
||||
EXPECT_TRUE(check_first_float(reader.read_from_string("-.6"), -.6));
|
||||
|
||||
EXPECT_TRUE(check_first_float(reader.read_from_string("1."), 1));
|
||||
EXPECT_TRUE(check_first_float(reader.read_from_string("1.0"), 1));
|
||||
EXPECT_TRUE(check_first_float(reader.read_from_string("01."), 1));
|
||||
EXPECT_TRUE(check_first_float(reader.read_from_string("01.0"), 1));
|
||||
|
||||
EXPECT_TRUE(check_first_float(reader.read_from_string("0."), 0));
|
||||
EXPECT_TRUE(check_first_float(reader.read_from_string(".0"), 0));
|
||||
EXPECT_TRUE(check_first_float(reader.read_from_string("0.0"), 0));
|
||||
EXPECT_TRUE(check_first_float(reader.read_from_string("000."), 0));
|
||||
EXPECT_TRUE(check_first_float(reader.read_from_string(".000"), 0));
|
||||
EXPECT_TRUE(check_first_float(reader.read_from_string("0.000"), 0));
|
||||
EXPECT_TRUE(check_first_float(reader.read_from_string("000.0"), 0));
|
||||
EXPECT_TRUE(check_first_float(reader.read_from_string("000.0000"), 0));
|
||||
|
||||
EXPECT_TRUE(check_first_float(reader.read_from_string("-0."), 0));
|
||||
EXPECT_TRUE(check_first_float(reader.read_from_string("-.0"), 0));
|
||||
EXPECT_TRUE(check_first_float(reader.read_from_string("-0.0"), 0));
|
||||
EXPECT_TRUE(check_first_float(reader.read_from_string("-000."), 0));
|
||||
EXPECT_TRUE(check_first_float(reader.read_from_string("-.000"), 0));
|
||||
EXPECT_TRUE(check_first_float(reader.read_from_string("-0.000"), 0));
|
||||
EXPECT_TRUE(check_first_float(reader.read_from_string("-000.0"), 0));
|
||||
EXPECT_TRUE(check_first_float(reader.read_from_string("-000.0000"), 0));
|
||||
|
||||
EXPECT_TRUE(check_first_symbol(reader.read_from_string("1e0"), "1e0"));
|
||||
EXPECT_ANY_THROW(reader.read_from_string("."));
|
||||
}
|
||||
|
||||
TEST(GoosReader, Boolean) {
|
||||
Reader reader;
|
||||
EXPECT_TRUE(check_first_symbol(reader.read_from_string("#f"), "#f"));
|
||||
EXPECT_TRUE(check_first_symbol(reader.read_from_string("#t"), "#t"));
|
||||
}
|
||||
|
||||
TEST(GoosReader, String) {
|
||||
Reader reader;
|
||||
EXPECT_TRUE(
|
||||
check_first_string(reader.read_from_string("\"testing string ()\""), "testing string ()"));
|
||||
EXPECT_TRUE(check_first_string(reader.read_from_string("\"\""), ""));
|
||||
EXPECT_TRUE(check_first_string(reader.read_from_string("\" \\t \""), " \t "));
|
||||
EXPECT_TRUE(check_first_string(reader.read_from_string("\" \\n \""), " \n "));
|
||||
EXPECT_TRUE(check_first_string(reader.read_from_string("\"test \\n\""), "test \n"));
|
||||
EXPECT_TRUE(check_first_string(reader.read_from_string("\" \\\\ \""), " \\ "));
|
||||
EXPECT_ANY_THROW(reader.read_from_string("\"\\\"")); // "\" invalid escape
|
||||
EXPECT_ANY_THROW(reader.read_from_string("\"\\w\"")); // "\w" invalid escape
|
||||
}
|
||||
|
||||
TEST(GoosReader, Symbol) {
|
||||
std::vector<std::string> test_symbols = {
|
||||
"test", "test-two", "__werid-sym__", "-a", "-", "/", "*", "+", "a", "#f"};
|
||||
|
||||
Reader reader;
|
||||
|
||||
for (const auto& sym : test_symbols) {
|
||||
EXPECT_TRUE(check_first_symbol(reader.read_from_string(sym), sym));
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
bool first_list_matches(Object o, std::vector<Object> stuff) {
|
||||
auto lst = o.as_pair()->cdr.as_pair()->car;
|
||||
for (const auto& x : stuff) {
|
||||
const auto check = x.as_pair()->cdr.as_pair()->car;
|
||||
if (lst.as_pair()->car != check) {
|
||||
return false;
|
||||
}
|
||||
lst = lst.as_pair()->cdr;
|
||||
}
|
||||
|
||||
return lst.is_empty_list();
|
||||
}
|
||||
|
||||
bool first_array_matches(Object o, std::vector<Object> stuff) {
|
||||
auto array = o.as_pair()->cdr.as_pair()->car.as_array();
|
||||
if (stuff.size() != array->size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < array->size(); i++) {
|
||||
if ((*array)[i] != stuff.at(i)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool first_pair_matches(Object o, Object car, Object cdr) {
|
||||
auto lst = o.as_pair()->cdr.as_pair()->car;
|
||||
return (lst.as_pair()->car == car) && (lst.as_pair()->cdr == cdr);
|
||||
}
|
||||
|
||||
bool print_matches(Object o, std::string expected) {
|
||||
return o.as_pair()->cdr.as_pair()->car.print() == expected;
|
||||
}
|
||||
|
||||
bool first_char_matches(Object o, char c) {
|
||||
return o.as_pair()->cdr.as_pair()->car.as_char() == c;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST(GoosReader, List) {
|
||||
Reader reader;
|
||||
auto r = [&](std::string s) { return reader.read_from_string(s); };
|
||||
EXPECT_TRUE(first_list_matches(r("()"), {}));
|
||||
EXPECT_TRUE(first_list_matches(r("(1)"), {r("1")}));
|
||||
EXPECT_TRUE(first_list_matches(r(" ( 1 ) "), {r("1")}));
|
||||
EXPECT_TRUE(first_list_matches(r("(1 2 3)"), {r("1"), r("2"), r("3")}));
|
||||
EXPECT_TRUE(first_list_matches(r(" ( 1 bbbb 3 ) "), {r("1"), r("bbbb"), r("3")}));
|
||||
|
||||
EXPECT_TRUE(first_pair_matches(r("(1 . 2)"), Object::make_integer(1), Object::make_integer(2)));
|
||||
|
||||
EXPECT_TRUE(print_matches(r(" ( 1 . 2 ) "), "(1 . 2)"));
|
||||
EXPECT_TRUE(print_matches(r(" ( 1 1 . 2 ) "), "(1 1 . 2)"));
|
||||
EXPECT_TRUE(print_matches(r(" ( 1 . ( 1 . 2 ) ) "), "(1 1 . 2)"));
|
||||
EXPECT_TRUE(
|
||||
print_matches(r(" ( 1 ( 1 2 ) ( 1 ( 12 3 ) ) . 3 ) "), "(1 (1 2) (1 (12 3)) . 3)"));
|
||||
EXPECT_TRUE(
|
||||
print_matches(r(" ( 1 ( 1 2 ) ( 1 ( 12 3 ) ) . ( ) ) "), "(1 (1 2) (1 (12 3)))"));
|
||||
|
||||
std::vector<std::string> expected_to_throw = {"(", ")", " (", " )()() ",
|
||||
")(", "(1 2 ))", "(( 1 2)", "(1 . . 2)",
|
||||
"(1 . )", "(1 . 2 3)", "( . 2)"};
|
||||
|
||||
for (const auto& x : expected_to_throw) {
|
||||
EXPECT_ANY_THROW(r(x));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(GoosReader, Comments) {
|
||||
Reader reader;
|
||||
auto r = [&](std::string s) { return reader.read_from_string(s); };
|
||||
EXPECT_TRUE(first_list_matches(r(";;\n(1)\n;;"), {r("1")}));
|
||||
EXPECT_TRUE(first_list_matches(r(";;\n(;1\n1;)\n);;\n;"), {r("1")}));
|
||||
|
||||
r(";");
|
||||
r(" ;");
|
||||
r("\n;");
|
||||
r(";\n");
|
||||
|
||||
EXPECT_TRUE(first_list_matches(
|
||||
r("#|multi line\n com(((((ment |# (1) #| multi line\n comm)))))ent |#"), {r("1")}));
|
||||
EXPECT_TRUE(first_list_matches(
|
||||
r("#| #| multi l#|ine\n com#|ment |# (1) #| multi line\n commen))))))t |#"), {r("1")}));
|
||||
|
||||
std::vector<std::string> expected_to_throw = {"|#", "#| |# |#"};
|
||||
|
||||
for (const auto& x : expected_to_throw) {
|
||||
EXPECT_ANY_THROW(r(x));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(GoosReader, Char) {
|
||||
Reader reader;
|
||||
auto r = [&](std::string s) { return reader.read_from_string(s); };
|
||||
|
||||
EXPECT_TRUE(first_char_matches(r("#\\c"), 'c'));
|
||||
EXPECT_TRUE(first_char_matches(r("#\\n"), 'n'));
|
||||
EXPECT_TRUE(first_char_matches(r("#\\\\n"), '\n'));
|
||||
EXPECT_TRUE(first_char_matches(r("#\\\\t"), '\t'));
|
||||
EXPECT_TRUE(first_char_matches(r("#\\\\s"), ' '));
|
||||
}
|
||||
|
||||
TEST(GoosReader, Array) {
|
||||
Reader reader;
|
||||
auto r = [&](std::string s) { return reader.read_from_string(s); };
|
||||
EXPECT_TRUE(print_matches(r(" #( ) "), "#()"));
|
||||
EXPECT_TRUE(first_array_matches(r("#()"), {}));
|
||||
EXPECT_TRUE(first_array_matches(r("#(1 2)"), {Object::make_integer(1), Object::make_integer(2)}));
|
||||
EXPECT_TRUE(first_array_matches(r("#( 1 #| 2 |# 3 )"),
|
||||
{Object::make_integer(1), Object::make_integer(3)}));
|
||||
EXPECT_TRUE(
|
||||
first_array_matches(r("#( 1 #|2|# 3 )"), {Object::make_integer(1), Object::make_integer(3)}));
|
||||
}
|
||||
|
||||
TEST(GoosReader, Macros) {
|
||||
Reader reader;
|
||||
auto r = [&](std::string s) { return reader.read_from_string(s); };
|
||||
EXPECT_TRUE(print_matches(r("'x"), "(quote x)"));
|
||||
EXPECT_TRUE(print_matches(r("`x"), "(quasiquote x)"));
|
||||
EXPECT_TRUE(print_matches(r(",x"), "(unquote x)"));
|
||||
EXPECT_TRUE(print_matches(r(",@x"), "(unquote-splicing x)"));
|
||||
}
|
||||
|
||||
TEST(GoosReader, TopLevel) {
|
||||
Reader reader;
|
||||
auto r = [&](std::string s) { return reader.read_from_string(s); };
|
||||
EXPECT_EQ(r("x").print(), "(top-level x)");
|
||||
}
|
||||
|
||||
TEST(GoosReader, FromFile) {
|
||||
Reader reader;
|
||||
auto result =
|
||||
reader.read_from_file(util::combine_path({"test", "test_reader_file0.gc"})).print();
|
||||
EXPECT_TRUE(result == "(top-level (1 2 3 4))");
|
||||
}
|
||||
|
||||
TEST(GoosReader, TextDb) {
|
||||
// very specific to this particular test file, but whatever.
|
||||
Reader reader;
|
||||
auto file_path = util::combine_path({"test", "test_reader_file0.gc"});
|
||||
auto result = reader.read_from_file(file_path).as_pair()->cdr.as_pair()->car;
|
||||
std::string expected = "text from " + util::combine_path(reader.get_source_dir(), file_path) +
|
||||
", line: 5\n(1 2 3 4)\n";
|
||||
EXPECT_EQ(expected, reader.db.get_info_for(result));
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
; this is a test file for test_reader.cpp
|
||||
|
||||
#| some comment |#
|
||||
|
||||
(1 2 3 4)
|
||||
;a
|
||||
; aaaa
|
||||
|
||||
#| some comment |#
|
||||
@@ -0,0 +1,6 @@
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
TEST(test, test) {
|
||||
EXPECT_TRUE(true);
|
||||
EXPECT_FALSE(false);
|
||||
}
|
||||
Reference in New Issue
Block a user