c-repl/test/repl.cpp
2024-01-03 16:20:42 +01:00

42 lines
955 B
C++

#include "include/test.h"
#include "../src/include/execute.h"
#include "../src/include/utils.h"
EvalResult execute(string s, Memory& memory) {
return execute(split_string(s, '\n'), memory);
}
int main() {
_TEST_PRESENTATION("Repl");
Memory mem1;
_TEST_ASSERT(
_TEST_NO_EXCEPTION(get<int>(execute("int x = 1;", mem1)) == 1),
"Déclaration d'une variable globale",
false
);
_TEST_ASSERT(
_TEST_NO_EXCEPTION(get<int>(execute("x;", mem1)) == 1),
"Persistance de variable",
true
);
Memory mem2;
_TEST_ASSERT(
_TEST_IS_EXCEPTION(execute("{ int x = 1; 1 / 0; }", mem2), ErrorType::DivisionByZero),
"Déclaration d'une scope avec erreur au runtime",
false
);
_TEST_ASSERT(
_TEST_IS_EXCEPTION(execute("x;", mem2), ErrorType::UnknownIdentifier),
"Destruction des scopes en cas d'erreur",
true
);
return 0;
}