51 lines
1.2 KiB
C++
51 lines
1.2 KiB
C++
#include "include/test.h"
|
|
|
|
#include "../src/include/memory.h"
|
|
#include "../src/include/tokenize.h"
|
|
#include "../src/include/parser.h"
|
|
#include "../src/include/interpreter.h"
|
|
|
|
EvalResult execute(string s) {
|
|
Memory memory = Memory();
|
|
vector<Token> tokens = tokenize({ s });
|
|
Node ast = parse(tokens);
|
|
EvalResult res = eval(ast, memory);
|
|
|
|
return res;
|
|
}
|
|
|
|
int main() {
|
|
_TEST_PRESENTATION("Statements");
|
|
|
|
_TEST_ASSERT(
|
|
_TEST_NO_EXCEPTION(get<int>(execute("int x = 0; if (1) x++; x;")) == 1),
|
|
"If vérifié",
|
|
true
|
|
);
|
|
|
|
_TEST_ASSERT(
|
|
_TEST_NO_EXCEPTION(get<int>(execute("int x = 0; if (0) x++; x;")) == 0),
|
|
"If pas vérifié",
|
|
true
|
|
);
|
|
|
|
_TEST_ASSERT(
|
|
_TEST_NO_EXCEPTION(get<int>(execute("int x = 1; if (0) x++; else x--; x;")) == 0),
|
|
"If else pas vérifié",
|
|
true
|
|
);
|
|
|
|
_TEST_ASSERT(
|
|
_TEST_NO_EXCEPTION(get<int>(execute("int i = 0; while (i < 100) i++; i;")) == 100),
|
|
"While",
|
|
true
|
|
);
|
|
|
|
_TEST_ASSERT(
|
|
_TEST_NO_EXCEPTION(get<int>(execute("int i = 0; for (int j = 0; j < 100; j++) { i++; } i;")) == 100),
|
|
"For",
|
|
true
|
|
);
|
|
|
|
return 0;
|
|
} |