Add tests for continue and comma

This commit is contained in:
ala89 2023-12-15 14:25:39 +01:00
parent eafb9c1d5d
commit 0cd17b9003
2 changed files with 39 additions and 0 deletions

27
test/operators.cpp Normal file
View File

@ -0,0 +1,27 @@
#include "include/test.h"
#include "../src/include/memory.h"
#include "../src/include/tokenize.h"
#include "../src/include/parser.h"
#include "../src/include/interpreter.h"
int execute(string s) {
Memory memory;;
vector<Token> tokens = tokenize({ s });
Node ast = parse(tokens);
EvalResult res = eval(ast, memory);
return get<int>(res);
}
int main() {
_TEST_PRESENTATION("Opérateurs");
_TEST_ASSERT(
_TEST_NO_EXCEPTION(execute("1,2;") == 2),
"Virgule",
true
);
return 0;
}

View File

@ -59,5 +59,17 @@ int main() {
true
);
_TEST_ASSERT(
_TEST_NO_EXCEPTION(get<int>(execute("int x = 0; for (int i = 0; i < 20; i++) { x++; continue; x++; } x;")) == 20),
"For continue",
true
);
_TEST_ASSERT(
_TEST_NO_EXCEPTION(get<int>(execute("int x = 0; int i = 0; while (i < 20) { i++; if (i % 2 == 0) continue; x++; } x;")) == 10),
"While continue",
true
);
return 0;
}