Fix the test cases to use reader::read instead of the Reader#read

This commit is contained in:
Sameer Rahmani 2021-07-19 09:38:07 +01:00
parent cb5ea22081
commit ea0bc28f01
3 changed files with 15 additions and 23 deletions

View File

@ -99,5 +99,12 @@ Read More:
- https://en.wikipedia.org/wiki/Comparison_of_parser_generators
*** Our Parser
- We have a hand written LL(1.5) like parser/lexer since lisp already has a structure.
#+BEGIN_SRC lisp
;; pseudo code
(def some-fn (fn (x y)
(+ x y)))
(defn main ()
(println "Result: " (some-fn 3 8)))
#+END_SRC
- LL(1.5)? s
- O(n)

View File

@ -36,9 +36,7 @@ TEST_CASE("Namespace tests", "[namespace]") {
auto userNs =
makeNamespace(*ctx, "user", llvm::Optional<llvm::StringRef>("/some/file"));
auto r = new reader::Reader("(x 1) (def b a)");
auto maybeAst = r->read();
auto maybeAst = reader::read("(x 1) (def b a)");
if (!maybeAst) {
FAIL();
@ -52,7 +50,6 @@ TEST_CASE("Namespace tests", "[namespace]") {
CHECK(exprs::astToString(&userNs->getTree()) ==
"<List <Symbol x> <Number 1>> <List <Symbol def> <Symbol b> <Symbol "
"a>>");
delete r;
};
} // namespace serene

View File

@ -30,8 +30,7 @@ namespace serene {
namespace reader {
TEST_CASE("Read numbers", "[reader]") {
auto r = new reader::Reader("3");
auto maybeAst = r->read();
auto maybeAst = reader::read("3");
if (!maybeAst) {
FAIL();
@ -41,8 +40,7 @@ TEST_CASE("Read numbers", "[reader]") {
REQUIRE_FALSE(ast.empty());
CHECK(ast.front()->toString() == "<Number 3>");
r->setInput("-34");
maybeAst = r->read();
maybeAst = reader::read("-34");
if (!maybeAst) {
FAIL();
@ -52,8 +50,7 @@ TEST_CASE("Read numbers", "[reader]") {
REQUIRE_FALSE(ast.empty());
CHECK(ast.front()->toString() == "<Number -34>");
r->setInput("-3.5434");
maybeAst = r->read();
maybeAst = reader::read("-3.5434");
if (!maybeAst) {
FAIL();
@ -63,8 +60,7 @@ TEST_CASE("Read numbers", "[reader]") {
REQUIRE_FALSE(ast.empty());
CHECK(ast.front()->toString() == "<Number -3.5434>");
r->setInput("444323 2123 123123");
maybeAst = r->read();
maybeAst = reader::read("444323 2123 123123");
if (!maybeAst) {
FAIL();
@ -75,13 +71,9 @@ TEST_CASE("Read numbers", "[reader]") {
CHECK(ast.front()->toString() == "<Number 444323>");
CHECK(ast[1]->toString() == "<Number 2123>" );
CHECK(ast[2]->toString() == "<Number 123123>");
delete r;
};
TEST_CASE("Read Lists and Symbols", "[reader]") {
auto r = new reader::Reader("(x 1)");
auto maybeAst = r->read();
auto maybeAst = reader::read("(x 1)");
if (!maybeAst) {
FAIL();
@ -91,8 +83,7 @@ TEST_CASE("Read Lists and Symbols", "[reader]") {
REQUIRE_FALSE(ast.empty());
CHECK(ast.front()->toString() == "<List <Symbol x> <Number 1>>");
r->setInput("(x (y (z)))");
maybeAst = r->read();
maybeAst = reader::read("(x (y (z)))");
if (!maybeAst) {
FAIL();
@ -102,8 +93,7 @@ TEST_CASE("Read Lists and Symbols", "[reader]") {
REQUIRE_FALSE(ast.empty());
CHECK(ast.front()->toString() == "<List <Symbol x> <List <Symbol y> <List <Symbol z>>>>");
r->setInput("(x \n y)");
maybeAst = r->read();
maybeAst = reader::read("(x \n y)");
if (!maybeAst) {
FAIL();
@ -112,8 +102,6 @@ TEST_CASE("Read Lists and Symbols", "[reader]") {
ast = std::move(maybeAst.getValue());
REQUIRE_FALSE(ast.empty());
CHECK(ast.front()->toString() == "<List <Symbol x> <Symbol y>>");
delete r;
};
} // namespace reader
} // namespace serene