From 5bed6a303c2b5d7b3b1000b618c39e1710987556 Mon Sep 17 00:00:00 2001 From: ala89 Date: Wed, 15 Nov 2023 16:10:36 +0100 Subject: [PATCH] More tests --- src/include/interpreter.h | 2 ++ src/interpreter.cpp | 4 ++++ test/expr_arithmetiques.cpp | 12 ++++++++++++ test/include/test.h | 4 ---- test/variables.cpp | 8 ++++++++ 5 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/include/interpreter.h b/src/include/interpreter.h index a95aeee..e3e6795 100644 --- a/src/include/interpreter.h +++ b/src/include/interpreter.h @@ -29,4 +29,6 @@ public: */ EvalResult eval(Node &ast); +void _debug_flush_memory(void); + #endif \ No newline at end of file diff --git a/src/interpreter.cpp b/src/interpreter.cpp index e682955..ebe22b1 100644 --- a/src/interpreter.cpp +++ b/src/interpreter.cpp @@ -8,6 +8,10 @@ using namespace std; unordered_map memory; +void _debug_flush_memory(void) { + memory.clear(); +} + EvalResult eval(Node &ast) { if (ast.index() == 0) { InnerNode node = get(ast); diff --git a/test/expr_arithmetiques.cpp b/test/expr_arithmetiques.cpp index bee7cf7..2f8025f 100644 --- a/test/expr_arithmetiques.cpp +++ b/test/expr_arithmetiques.cpp @@ -33,5 +33,17 @@ int main() { true ); + _TEST_ASSERT( + _TEST_IS_EXCEPTION(execute("1 / (5 - 5);"), RuntimeError), + "Division par 0", + true + ); + + _TEST_ASSERT( + _TEST_IS_EXCEPTION(execute("1 % (5 - 5);"), RuntimeError), + "Modulo par 0", + true + ); + return 0; } \ No newline at end of file diff --git a/test/include/test.h b/test/include/test.h index b313cb2..15d27f9 100644 --- a/test/include/test.h +++ b/test/include/test.h @@ -1,10 +1,6 @@ #ifndef DEF_TEST_H #define DEF_TEST_H -#include -#include -#include - #include "../../src/include/colors.h" #define _TEST_PRESENTATION(description) { printf("\n" BLUE "#### %s:" BOLD "%s" RESET BLUE " #####" RESET "\n", __FILE__, description); } diff --git a/test/variables.cpp b/test/variables.cpp index 0ed5c61..e99946c 100644 --- a/test/variables.cpp +++ b/test/variables.cpp @@ -9,6 +9,8 @@ int execute(string s) { Node ast = parse(tokens); EvalResult res = eval(ast); + _debug_flush_memory(); + return get(res); } @@ -45,5 +47,11 @@ int main() { true ); + _TEST_ASSERT( + _TEST_IS_EXCEPTION(execute("1 + x;"), RuntimeError), + "Identifieur indéfini", + true + ); + return 0; } \ No newline at end of file