Merge branch 'main' of gitlab.aliens-lyon.fr:alucas03/c-repl into main
This commit is contained in:
commit
cd9e0a3941
@ -1,8 +1,9 @@
|
||||
#include "include/test.h"
|
||||
|
||||
#include "../src/include/errors.h"
|
||||
#include "../src/include/memory.h"
|
||||
#include "../src/include/tokenize.h"
|
||||
#include "../src/include/parser.h"
|
||||
#include "../src/include/tokenize.h"
|
||||
#include "../src/include/interpreter.h"
|
||||
|
||||
int execute(string s) {
|
||||
@ -36,13 +37,13 @@ int main() {
|
||||
);
|
||||
|
||||
_TEST_ASSERT(
|
||||
_TEST_IS_EXCEPTION(execute("1 / 0;"), RuntimeError),
|
||||
_TEST_IS_EXCEPTION(execute("1 / 0;"), ErrorType::DivisionByZero),
|
||||
"Division par 0",
|
||||
true
|
||||
);
|
||||
|
||||
_TEST_ASSERT(
|
||||
_TEST_IS_EXCEPTION(execute("1 % 0;"), RuntimeError),
|
||||
_TEST_IS_EXCEPTION(execute("1 % 0;"), ErrorType::ModuloByZero),
|
||||
"Modulo par 0",
|
||||
true
|
||||
);
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define DEF_TEST_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); }
|
||||
|
||||
@ -25,13 +26,13 @@
|
||||
} \
|
||||
}()
|
||||
|
||||
#define _TEST_IS_EXCEPTION(expr, excep) \
|
||||
#define _TEST_IS_EXCEPTION(expr, error) \
|
||||
[&]() -> bool { \
|
||||
try { \
|
||||
(expr); \
|
||||
return false; \
|
||||
} catch (const excep& e) { \
|
||||
return true; \
|
||||
} catch (const UserError& e) { \
|
||||
return e.type == error; \
|
||||
} \
|
||||
catch (...) { \
|
||||
return false; \
|
||||
|
@ -118,7 +118,7 @@ int main() {
|
||||
string input = "int a = 10 @;";
|
||||
|
||||
_TEST_ASSERT(
|
||||
_TEST_IS_EXCEPTION(tokenize({ input }), SyntaxError),
|
||||
_TEST_IS_EXCEPTION(tokenize({ input }), ErrorType::UnknownToken),
|
||||
"Token invalide",
|
||||
true
|
||||
)
|
||||
|
@ -32,13 +32,13 @@ int main() {
|
||||
);
|
||||
|
||||
_TEST_ASSERT(
|
||||
_TEST_IS_EXCEPTION(execute("1 + x;"), RuntimeError),
|
||||
_TEST_IS_EXCEPTION(execute("1 + x;"), ErrorType::UnknownIdentifier),
|
||||
"Identifieur indéfini",
|
||||
true
|
||||
);
|
||||
|
||||
_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",
|
||||
true
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user