Merge branch 'main' of gitlab.aliens-lyon.fr:alucas03/c-repl into main

This commit is contained in:
ala89 2023-12-15 15:36:14 +01:00
commit cd9e0a3941
4 changed files with 11 additions and 9 deletions

View File

@ -1,8 +1,9 @@
#include "include/test.h" #include "include/test.h"
#include "../src/include/errors.h"
#include "../src/include/memory.h" #include "../src/include/memory.h"
#include "../src/include/tokenize.h"
#include "../src/include/parser.h" #include "../src/include/parser.h"
#include "../src/include/tokenize.h"
#include "../src/include/interpreter.h" #include "../src/include/interpreter.h"
int execute(string s) { int execute(string s) {
@ -36,13 +37,13 @@ int main() {
); );
_TEST_ASSERT( _TEST_ASSERT(
_TEST_IS_EXCEPTION(execute("1 / 0;"), RuntimeError), _TEST_IS_EXCEPTION(execute("1 / 0;"), ErrorType::DivisionByZero),
"Division par 0", "Division par 0",
true true
); );
_TEST_ASSERT( _TEST_ASSERT(
_TEST_IS_EXCEPTION(execute("1 % 0;"), RuntimeError), _TEST_IS_EXCEPTION(execute("1 % 0;"), ErrorType::ModuloByZero),
"Modulo par 0", "Modulo par 0",
true true
); );

View File

@ -2,6 +2,7 @@
#define DEF_TEST_H #define DEF_TEST_H
#include "../../src/include/colors.h" #include "../../src/include/colors.h"
#include "../../src/include/errors.h"
#define _TEST_PRESENTATION(description) { printf("\n" BLUE "#### %s:" BOLD "%s" RESET BLUE " #####" RESET "\n", __FILE__, description); } #define _TEST_PRESENTATION(description) { printf("\n" BLUE "#### %s:" BOLD "%s" RESET BLUE " #####" RESET "\n", __FILE__, description); }
@ -25,13 +26,13 @@
} \ } \
}() }()
#define _TEST_IS_EXCEPTION(expr, excep) \ #define _TEST_IS_EXCEPTION(expr, error) \
[&]() -> bool { \ [&]() -> bool { \
try { \ try { \
(expr); \ (expr); \
return false; \ return false; \
} catch (const excep& e) { \ } catch (const UserError& e) { \
return true; \ return e.type == error; \
} \ } \
catch (...) { \ catch (...) { \
return false; \ return false; \

View File

@ -118,7 +118,7 @@ int main() {
string input = "int a = 10 @;"; string input = "int a = 10 @;";
_TEST_ASSERT( _TEST_ASSERT(
_TEST_IS_EXCEPTION(tokenize({ input }), SyntaxError), _TEST_IS_EXCEPTION(tokenize({ input }), ErrorType::UnknownToken),
"Token invalide", "Token invalide",
true true
) )

View File

@ -32,13 +32,13 @@ int main() {
); );
_TEST_ASSERT( _TEST_ASSERT(
_TEST_IS_EXCEPTION(execute("1 + x;"), RuntimeError), _TEST_IS_EXCEPTION(execute("1 + x;"), ErrorType::UnknownIdentifier),
"Identifieur indéfini", "Identifieur indéfini",
true true
); );
_TEST_ASSERT( _TEST_ASSERT(
_TEST_IS_EXCEPTION(execute("int x; int x;"), RuntimeError), _TEST_IS_EXCEPTION(execute("int x; int x;"), ErrorType::AlreadyDefinedIdentifier),
"Identifieur déjà défini", "Identifieur déjà défini",
true true
); );