Add tests for continue and comma
This commit is contained in:
parent
eafb9c1d5d
commit
0cd17b9003
27
test/operators.cpp
Normal file
27
test/operators.cpp
Normal 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;
|
||||
}
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user