From 0cd17b9003af28772161db7bb7368586165b2103 Mon Sep 17 00:00:00 2001 From: ala89 Date: Fri, 15 Dec 2023 14:25:39 +0100 Subject: [PATCH] Add tests for continue and comma --- test/operators.cpp | 27 +++++++++++++++++++++++++++ test/statements.cpp | 12 ++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 test/operators.cpp diff --git a/test/operators.cpp b/test/operators.cpp new file mode 100644 index 0000000..3f5c74d --- /dev/null +++ b/test/operators.cpp @@ -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 tokens = tokenize({ s }); + Node ast = parse(tokens); + EvalResult res = eval(ast, memory); + + return get(res); +} + +int main() { + _TEST_PRESENTATION("Opérateurs"); + + _TEST_ASSERT( + _TEST_NO_EXCEPTION(execute("1,2;") == 2), + "Virgule", + true + ); + + return 0; +} \ No newline at end of file diff --git a/test/statements.cpp b/test/statements.cpp index 2b1d650..c972214 100644 --- a/test/statements.cpp +++ b/test/statements.cpp @@ -59,5 +59,17 @@ int main() { true ); + _TEST_ASSERT( + _TEST_NO_EXCEPTION(get(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(execute("int x = 0; int i = 0; while (i < 20) { i++; if (i % 2 == 0) continue; x++; } x;")) == 10), + "While continue", + true + ); + return 0; } \ No newline at end of file