c-repl/test/expr_arithmetiques.cpp

25 lines
597 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("Expressions Arithmétiques");
_TEST_ASSERT(execute("10 + 3 * (7 - 2);") == 25, "Priorités");
_TEST_ASSERT(execute("12 - 4 - 20;") == -12, "Ordre de soustraction");
_TEST_ASSERT(execute("-7 + 13 + -6;") == 0, "Opérateurs unaires");
return 0;
}