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;