More tests

This commit is contained in:
ala89 2023-11-15 16:10:36 +01:00
parent a57b759af9
commit 5bed6a303c
5 changed files with 26 additions and 4 deletions

View File

@ -29,4 +29,6 @@ public:
*/
EvalResult eval(Node &ast);
void _debug_flush_memory(void);
#endif

View File

@ -8,6 +8,10 @@ using namespace std;
unordered_map<string, MemoryEntry> memory;
void _debug_flush_memory(void) {
memory.clear();
}
EvalResult eval(Node &ast) {
if (ast.index() == 0) {
InnerNode node = get<InnerNode>(ast);

View File

@ -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;
}

View File

@ -1,10 +1,6 @@
#ifndef DEF_TEST_H
#define DEF_TEST_H
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include "../../src/include/colors.h"
#define _TEST_PRESENTATION(description) { printf("\n" BLUE "#### %s:" BOLD "%s" RESET BLUE " #####" RESET "\n", __FILE__, description); }

View File

@ -9,6 +9,8 @@ int execute(string s) {
Node ast = parse(tokens);
EvalResult res = eval(ast);
_debug_flush_memory();
return get<int>(res);
}
@ -45,5 +47,11 @@ int main() {
true
);
_TEST_ASSERT(
_TEST_IS_EXCEPTION(execute("1 + x;"), RuntimeError),
"Identifieur indéfini",
true
);
return 0;
}