57 lines
1.4 KiB
C++
57 lines
1.4 KiB
C++
#include "include/test.hpp"
|
|
|
|
#include "../src/include/execute.hpp"
|
|
#include "../src/include/utils.hpp"
|
|
|
|
EvalResult execute(string s) {
|
|
Memory memory;
|
|
return execute(split_string(s, '\n'), memory);
|
|
}
|
|
|
|
int main() {
|
|
_TEST_PRESENTATION("Variables");
|
|
|
|
_TEST_ASSERT(
|
|
_TEST_NO_EXCEPTION(get<int>(execute("int __une_variable_farfelue__ = 12;")) == 12),
|
|
"Déclaration avec assignement",
|
|
true
|
|
);
|
|
|
|
_TEST_ASSERT(
|
|
_TEST_NO_EXCEPTION(get<int>(execute("int x = 5; x = x + 3;")) == 8),
|
|
"Déclaration puis assignement",
|
|
true
|
|
);
|
|
|
|
_TEST_ASSERT(
|
|
_TEST_IS_EXCEPTION(execute("1 + x;"), ErrorType::UnknownIdentifier),
|
|
"Identifieur indéfini",
|
|
true
|
|
);
|
|
|
|
_TEST_ASSERT(
|
|
_TEST_IS_EXCEPTION(execute("int x; int x;"), ErrorType::AlreadyDeclaredIdentifier),
|
|
"Identifieur déjà défini",
|
|
true
|
|
);
|
|
|
|
_TEST_ASSERT(
|
|
_TEST_IS_EXCEPTION(execute("void x;"), ErrorType::IncompleteType),
|
|
"Type void",
|
|
true
|
|
);
|
|
|
|
_TEST_ASSERT(
|
|
_TEST_NO_EXCEPTION(holds_alternative<monostate>(execute("int x; { int x; }"))),
|
|
"Identifieur déjà défini dans une autre scope",
|
|
true
|
|
);
|
|
|
|
_TEST_ASSERT(
|
|
_TEST_NO_EXCEPTION(get<int>(execute("int x = 1; int y; { int x = 2; y = x + 2; }; y;")) == 4),
|
|
"Shadowing",
|
|
true
|
|
);
|
|
|
|
return 0;
|
|
} |