diff --git a/dev.org b/dev.org index 8333031..91f6fda 100644 --- a/dev.org +++ b/dev.org @@ -126,7 +126,7 @@ functions and detect hot functions similar to how javascript jits do it and recompile those functions with more optimization passes * TODOs - +** TODO Create =Catch2= generators to be used in tests. Specially for the =reader= tests ** TODO Investigate possible implementanion for Internal Errors - An option is to use llvm registry functionality like the one used in =clang-doc= instead of =errorVariants= var. diff --git a/libserene/include/serene/reader/reader.h b/libserene/include/serene/reader/reader.h index 7e811b0..881d853 100644 --- a/libserene/include/serene/reader/reader.h +++ b/libserene/include/serene/reader/reader.h @@ -44,6 +44,7 @@ #include "serene/reader/location.h" #include "serene/serene.h" +#include #include #include @@ -124,12 +125,13 @@ public: /// Parses the given `input` string and returns a `Result` /// which may contains an AST or an `llvm::Error` -exprs::MaybeAst read(SereneContext &ctx, llvm::StringRef input, - llvm::StringRef ns, - llvm::Optional filename); -exprs::MaybeAst read(SereneContext &ctx, llvm::MemoryBufferRef input, - llvm::StringRef ns, - llvm::Optional filename); +SERENE_EXPORT exprs::MaybeAst read(SereneContext &ctx, llvm::StringRef input, + llvm::StringRef ns, + llvm::Optional filename); +SERENE_EXPORT exprs::MaybeAst read(SereneContext &ctx, + llvm::MemoryBufferRef input, + llvm::StringRef ns, + llvm::Optional filename); } // namespace serene::reader #endif diff --git a/libserene/tests/reader/reader_tests.cpp.inc b/libserene/tests/reader/reader_tests.cpp.inc index 3ce1629..c9290c9 100644 --- a/libserene/tests/reader/reader_tests.cpp.inc +++ b/libserene/tests/reader/reader_tests.cpp.inc @@ -16,88 +16,99 @@ * along with this program. If not, see . */ +#ifndef SERENE_TEST_READER_H +#define SERENE_TEST_READER_H + #include "serene/reader/reader.h" -#include "../test_helpers.cpp.inc" -#include +#include + +// *IMPORTANT NOTE:* The `READ` macro is just a quick way to eliminate +// the overhead of writing the same function signature +// over and over again. Nothing special about it. +#define READ(input) reader::read(*ctx, input, "user", llvm::None) namespace serene { namespace reader { TEST_CASE("Read numbers", "[reader]") { - auto maybeAst = reader::read("3"); + auto ctx = makeSereneContext(); + auto maybeAst = READ("3"); if (!maybeAst) { FAIL(); } - auto ast = std::move(maybeAst).getValue(); + auto ast = *maybeAst; REQUIRE_FALSE(ast.empty()); CHECK(ast.front()->toString() == ""); - maybeAst = reader::read("-34"); + maybeAst = READ("-34"); if (!maybeAst) { FAIL(); } - ast = std::move(maybeAst.getValue()); + ast = *maybeAst; REQUIRE_FALSE(ast.empty()); CHECK(ast.front()->toString() == ""); - maybeAst = reader::read("-3.5434"); + maybeAst = READ("-3.5434"); if (!maybeAst) { FAIL(); } - ast = std::move(maybeAst.getValue()); + ast = *maybeAst; REQUIRE_FALSE(ast.empty()); CHECK(ast.front()->toString() == ""); - maybeAst = reader::read("444323 2123 123123"); + maybeAst = READ("444323 2123 123123"); if (!maybeAst) { FAIL(); } - ast = std::move(maybeAst.getValue()); + ast = *maybeAst; REQUIRE(ast.size() == 3); CHECK(ast.front()->toString() == ""); CHECK(ast[1]->toString() == ""); CHECK(ast[2]->toString() == ""); }; + TEST_CASE("Read Lists and Symbols", "[reader]") { - auto maybeAst = reader::read("(x 1)"); + auto ctx = makeSereneContext(); + auto maybeAst = READ("(x 1)"); if (!maybeAst) { FAIL(); } - auto ast = std::move(maybeAst.getValue()); + auto ast = *maybeAst; REQUIRE_FALSE(ast.empty()); - CHECK(ast.front()->toString() == " >"); + CHECK(ast.front()->toString() == " >"); - maybeAst = reader::read("(x (y (z)))"); + maybeAst = READ("(x (y (z)))"); if (!maybeAst) { FAIL(); } - ast = std::move(maybeAst.getValue()); + ast = *maybeAst; REQUIRE_FALSE(ast.empty()); - CHECK(ast.front()->toString() == - " >>>"); + CHECK(ast.front()->toString() == " >>>"); - maybeAst = reader::read("(x \n y)"); + maybeAst = READ("(x \n y)"); if (!maybeAst) { FAIL(); } - ast = std::move(maybeAst.getValue()); + ast = *maybeAst; REQUIRE_FALSE(ast.empty()); - CHECK(ast.front()->toString() == " >"); + CHECK(ast.front()->toString() == " >"); }; } // namespace reader } // namespace serene +#endif