feat: failed attempt to make emscripten work

This commit is contained in:
Matthieu Bessat 2022-05-21 18:38:26 +02:00
parent bb52b98ae7
commit 110eab7a1a
43 changed files with 700 additions and 148 deletions

View file

@ -1,3 +1,5 @@
#include "../src/config.h"
#include "../src/utils.h"
#include "./test_utils.h"
#include "./test_evaluation.h"
#include "./test_line_processing.h"
@ -7,8 +9,10 @@
int main()
{
printf("== UNIT TESTS == \n");
int var1 = 0x34;
printf_wrap("== UNIT TESTS == \n");
test_utils();
printf_wrap("ça commence à faire chier jpp\n");
test_var_store();
test_stack();
test_evaluation();

View file

@ -9,7 +9,7 @@
void test_evaluation()
{
printf("== test evaluation == \n");
printf_wrap("== test evaluation == \n");
struct StateContainer* state = state_init();
@ -93,7 +93,7 @@ void test_evaluation()
evaluate(state, "random_int(1, 100)", &resVal, &resType);
assert(resType == TYPE_INT);
printf(" - random int: %d \n", resVal);
printf_wrap(" - random int: %d \n", resVal);
evaluate(state, "abs(2)+abs(-2)", &resVal, &resType);
assert(resType == TYPE_INT);
@ -201,7 +201,7 @@ void test_evaluation()
evaluate(state, "abs((var2^2)-((var-41)^2))+2", &resVal, &resType);
assert(resType == TYPE_INT);
printf("actually got: %d \n", resVal);
printf_wrap("actually got: %d \n", resVal);
assert(7 == resVal);
/* TYPE FUNCS */

View file

@ -11,7 +11,7 @@
void test_line_processing()
{
printf("== test line processing == \n");
printf_wrap("== test line processing == \n");
// test string manipulation
assert(!recognize_word("", "hello"));
@ -49,7 +49,7 @@ void test_line_processing()
assert(process_line(state1, "#"));
assert(process_line(state1, "# some random comment"));
assert(process_line(state1, "set VAR_A to 8.5"));
printf("%d \n", var_store_get_int(state1->varStore, "VAR_A"));
printf_wrap("%d \n", var_store_get_int(state1->varStore, "VAR_A"));
assert(float_almost_equal(8.5, var_store_get_float(state1->varStore, "VAR_A")));
assert(process_line(state1, "set VAR_B to 1.5"));
@ -113,7 +113,7 @@ void test_line_processing()
process_script(state2, lines4);
assert(!state2->skipping);
printf("got i: %d \n", var_store_get_int(state2->varStore, "i"));
printf_wrap("got i: %d \n", var_store_get_int(state2->varStore, "i"));
assert(9 == var_store_get_int(state2->varStore, "i"));
// test break keyword
@ -127,7 +127,7 @@ void test_line_processing()
process_script(state2, lines5);
assert(!state2->skipping);
printf("got i: %d \n", var_store_get_int(state2->varStore, "i"));
printf_wrap("got i: %d \n", var_store_get_int(state2->varStore, "i"));
assert(10 == var_store_get_int(state2->varStore, "i"));
// test continue keyword

View file

@ -6,7 +6,7 @@
void test_stack()
{
printf("== test stack == \n");
printf_wrap("== test stack == \n");
int res;
struct IntStack* stack1 = int_stack_init();
@ -28,7 +28,7 @@ void test_stack()
assert(int_stack_push(stack1, 2025));
assert(int_stack_push(stack1, 2026));
assert(16 == stack1->allocated);
printf("%d \n", int_stack_length(stack1));
printf_wrap("%d \n", int_stack_length(stack1));
assert(9 == int_stack_length(stack1));
int_stack_print(stack1);

View file

@ -6,7 +6,7 @@
void test_utils()
{
printf("== test utils == \n");
printf_wrap("== test utils == \n");
// test int parsing
char test1[] = "151087";

View file

@ -5,10 +5,40 @@
void test_var_store()
{
printf("== test var store == \n");
printf_wrap("== test var store == \n");
struct VariableStore* store = var_store_init();
// hash function test
int hash1, hash2, hash3 = 0;
hash1 = var_store_hash_name(store, "a");
hash2 = var_store_hash_name(store, "a");
hash3 = var_store_hash_name(store, "a");
assert(hash1 == hash2);
assert(hash2 == hash3);
assert(hash1 == hash3);
hash1 = var_store_hash_name(store, "i");
hash2 = var_store_hash_name(store, "i");
hash3 = var_store_hash_name(store, "i");
assert(hash1 == hash2);
assert(hash2 == hash3);
assert(hash1 == hash3);
var_store_print(store);
int originalLength = store->length;
int varEx = 42;
int originalHash = var_store_hash_name(store, "i");
var_store_set(store, "i", TYPE_INT, &varEx);
assert(originalHash == var_store_hash_name(store, "i"));
assert(TYPE_INT == var_store_get_type(store, "i"));
assert(originalLength+1 == store->length);
assert(42 == var_store_get_int(store, "i"));
// sequential assignement
int iDest = 0;
for (int i = 0; i < 10; i++) {
var_store_set(store, "i", TYPE_INT, &i);