c-repl/test/variables.cpp

29 lines
639 B
C++

#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");
_TEST_ASSERT(
_TEST_NO_EXCEPTION(execute("int uneVariableFarfelue__ = 12;") == 12),
"Déclaration avec assignement"
);
_TEST_ASSERT(
_TEST_NO_EXCEPTION(execute("int x = 5; x = x + 3;") == 8),
"Déclaration puis assignement"
);
return 0;
}