c-repl/test/variables.cpp

29 lines
639 B
C++
Raw Normal View History

2023-11-10 22:24:14 +01:00
#include "include/test.h"
#include "../src/include/tokenize.h"
#include "../src/include/parser.h"
#include "../src/include/interpreter.h"
int execute(string s) {
vector<Token> tokens = tokenize(s);
Node ast = parse(tokens);
EvalResult res = eval(ast);
return get<int>(res);
}
int main() {
_TEST_PRESENTATION("Variables");
2023-11-14 17:03:42 +01:00
_TEST_ASSERT(
_TEST_NO_EXCEPTION(execute("int uneVariableFarfelue__ = 12;") == 12),
"Déclaration avec assignement"
);
2023-11-10 22:24:14 +01:00
2023-11-14 17:03:42 +01:00
_TEST_ASSERT(
_TEST_NO_EXCEPTION(execute("int x = 5; x = x + 3;") == 8),
"Déclaration puis assignement"
);
2023-11-10 22:24:14 +01:00
return 0;
}