From 0b3f780ec783c445f7e3d321fe8a0db9fa6bce35 Mon Sep 17 00:00:00 2001 From: Ilusha <63184036+IlyaShurupov@users.noreply.github.com> Date: Wed, 13 Mar 2024 14:20:50 +0300 Subject: [PATCH] tmp --- Objects/tests/TestCompiler.cpp | 54 ++++++++++++++++++++++++++++++++ Objects/tests/TestPrimitives.cpp | 8 +++-- 2 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 Objects/tests/TestCompiler.cpp diff --git a/Objects/tests/TestCompiler.cpp b/Objects/tests/TestCompiler.cpp new file mode 100644 index 0000000..c390cbb --- /dev/null +++ b/Objects/tests/TestCompiler.cpp @@ -0,0 +1,54 @@ + +#include "Testing.hpp" + +#include "compiler/function.h" +#include "core/object.h" +#include "interpreter/interpreter.h" +#include "primitives/interpreterobject.h" +#include "primitives/linkobject.h" +#include "primitives/methodobject.h" + +using namespace tp; +using namespace obj; + +TEST_DEF_STATIC(Basic) { + { + // no errors + auto method = NDO_CAST(MethodObject, NDO->create("method")); + + method->mScript->mReadable->val = "print 1 * 20 + 10;"; + method->compile(); + + NDO->destroy(method); + + assertNoLeaks(); + } + + { + // with errors + auto method = NDO_CAST(MethodObject, NDO->create("method")); + + method->mScript->mReadable->val = "print undefinedVariable;"; + method->compile(); + + NDO->destroy(method); + + assertNoLeaks(); + } +} + +TEST_DEF_STATIC(ErrorHandling) { + Parser parser; + + String stream = "var i = true; print (i + 1) * 10; invalidCharacter "; + auto res = parser.parse(stream); + + TEST(res.isError); + + delete res.scope; +} + +TEST_DEF(Compiler) { + testBasic(); + testErrorHandling(); +} diff --git a/Objects/tests/TestPrimitives.cpp b/Objects/tests/TestPrimitives.cpp index 1cc9c65..6c2927e 100644 --- a/Objects/tests/TestPrimitives.cpp +++ b/Objects/tests/TestPrimitives.cpp @@ -1,10 +1,12 @@ #include "Testing.hpp" +#include "compiler/function.h" #include "core/object.h" - -#include "primitives/dictobject.h" -#include "primitives/intobject.h" +#include "interpreter/interpreter.h" +#include "primitives/interpreterobject.h" +#include "primitives/linkobject.h" +#include "primitives/methodobject.h" using namespace tp; using namespace obj;