57 lines
1.3 KiB
C++
57 lines
1.3 KiB
C++
#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 = Memory();
|
|
vector<Token> tokens = tokenize({ s });
|
|
Node ast = parse(tokens);
|
|
EvalResult res = eval(ast, memory);
|
|
|
|
return get<int>(res);
|
|
}
|
|
|
|
int main() {
|
|
_TEST_PRESENTATION("Variables");
|
|
|
|
_TEST_ASSERT(
|
|
_TEST_NO_EXCEPTION(execute("int uneVariableFarfelue__ = 12;") == 12),
|
|
"Déclaration avec assignement",
|
|
true
|
|
);
|
|
|
|
_TEST_ASSERT(
|
|
_TEST_NO_EXCEPTION(execute("int x = 5; x = x + 3;") == 8),
|
|
"Déclaration puis assignement",
|
|
true
|
|
);
|
|
|
|
_TEST_ASSERT(
|
|
_TEST_NO_EXCEPTION(execute("int a = 27; ++a;") == 28),
|
|
"Incrémentation par la gauche",
|
|
true
|
|
);
|
|
|
|
_TEST_ASSERT(
|
|
_TEST_NO_EXCEPTION(execute("int a = 27; a--;") == 27),
|
|
"Décrémentation par la droite",
|
|
true
|
|
);
|
|
|
|
_TEST_ASSERT(
|
|
_TEST_NO_EXCEPTION(execute("int a = 27; -(+-++a);") == 28),
|
|
"Incrémentation et opérations unaires",
|
|
true
|
|
);
|
|
|
|
_TEST_ASSERT(
|
|
_TEST_IS_EXCEPTION(execute("1 + x;"), RuntimeError),
|
|
"Identifieur indéfini",
|
|
true
|
|
);
|
|
|
|
return 0;
|
|
} |