Fix the test cases to use reader::read instead of the Reader#read
This commit is contained in:
parent
cb5ea22081
commit
ea0bc28f01
|
@ -99,5 +99,12 @@ Read More:
|
||||||
- https://en.wikipedia.org/wiki/Comparison_of_parser_generators
|
- https://en.wikipedia.org/wiki/Comparison_of_parser_generators
|
||||||
*** Our Parser
|
*** Our Parser
|
||||||
- We have a hand written LL(1.5) like parser/lexer since lisp already has a structure.
|
- 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
|
- LL(1.5)? s
|
||||||
- O(n)
|
- O(n)
|
||||||
|
|
|
@ -36,9 +36,7 @@ TEST_CASE("Namespace tests", "[namespace]") {
|
||||||
auto userNs =
|
auto userNs =
|
||||||
makeNamespace(*ctx, "user", llvm::Optional<llvm::StringRef>("/some/file"));
|
makeNamespace(*ctx, "user", llvm::Optional<llvm::StringRef>("/some/file"));
|
||||||
|
|
||||||
auto r = new reader::Reader("(x 1) (def b a)");
|
auto maybeAst = reader::read("(x 1) (def b a)");
|
||||||
|
|
||||||
auto maybeAst = r->read();
|
|
||||||
|
|
||||||
if (!maybeAst) {
|
if (!maybeAst) {
|
||||||
FAIL();
|
FAIL();
|
||||||
|
@ -52,7 +50,6 @@ TEST_CASE("Namespace tests", "[namespace]") {
|
||||||
CHECK(exprs::astToString(&userNs->getTree()) ==
|
CHECK(exprs::astToString(&userNs->getTree()) ==
|
||||||
"<List <Symbol x> <Number 1>> <List <Symbol def> <Symbol b> <Symbol "
|
"<List <Symbol x> <Number 1>> <List <Symbol def> <Symbol b> <Symbol "
|
||||||
"a>>");
|
"a>>");
|
||||||
delete r;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace serene
|
} // namespace serene
|
||||||
|
|
|
@ -30,8 +30,7 @@ namespace serene {
|
||||||
namespace reader {
|
namespace reader {
|
||||||
|
|
||||||
TEST_CASE("Read numbers", "[reader]") {
|
TEST_CASE("Read numbers", "[reader]") {
|
||||||
auto r = new reader::Reader("3");
|
auto maybeAst = reader::read("3");
|
||||||
auto maybeAst = r->read();
|
|
||||||
|
|
||||||
if (!maybeAst) {
|
if (!maybeAst) {
|
||||||
FAIL();
|
FAIL();
|
||||||
|
@ -41,8 +40,7 @@ TEST_CASE("Read numbers", "[reader]") {
|
||||||
REQUIRE_FALSE(ast.empty());
|
REQUIRE_FALSE(ast.empty());
|
||||||
CHECK(ast.front()->toString() == "<Number 3>");
|
CHECK(ast.front()->toString() == "<Number 3>");
|
||||||
|
|
||||||
r->setInput("-34");
|
maybeAst = reader::read("-34");
|
||||||
maybeAst = r->read();
|
|
||||||
|
|
||||||
if (!maybeAst) {
|
if (!maybeAst) {
|
||||||
FAIL();
|
FAIL();
|
||||||
|
@ -52,8 +50,7 @@ TEST_CASE("Read numbers", "[reader]") {
|
||||||
REQUIRE_FALSE(ast.empty());
|
REQUIRE_FALSE(ast.empty());
|
||||||
CHECK(ast.front()->toString() == "<Number -34>");
|
CHECK(ast.front()->toString() == "<Number -34>");
|
||||||
|
|
||||||
r->setInput("-3.5434");
|
maybeAst = reader::read("-3.5434");
|
||||||
maybeAst = r->read();
|
|
||||||
|
|
||||||
if (!maybeAst) {
|
if (!maybeAst) {
|
||||||
FAIL();
|
FAIL();
|
||||||
|
@ -63,8 +60,7 @@ TEST_CASE("Read numbers", "[reader]") {
|
||||||
REQUIRE_FALSE(ast.empty());
|
REQUIRE_FALSE(ast.empty());
|
||||||
CHECK(ast.front()->toString() == "<Number -3.5434>");
|
CHECK(ast.front()->toString() == "<Number -3.5434>");
|
||||||
|
|
||||||
r->setInput("444323 2123 123123");
|
maybeAst = reader::read("444323 2123 123123");
|
||||||
maybeAst = r->read();
|
|
||||||
|
|
||||||
if (!maybeAst) {
|
if (!maybeAst) {
|
||||||
FAIL();
|
FAIL();
|
||||||
|
@ -75,13 +71,9 @@ TEST_CASE("Read numbers", "[reader]") {
|
||||||
CHECK(ast.front()->toString() == "<Number 444323>");
|
CHECK(ast.front()->toString() == "<Number 444323>");
|
||||||
CHECK(ast[1]->toString() == "<Number 2123>" );
|
CHECK(ast[1]->toString() == "<Number 2123>" );
|
||||||
CHECK(ast[2]->toString() == "<Number 123123>");
|
CHECK(ast[2]->toString() == "<Number 123123>");
|
||||||
|
|
||||||
delete r;
|
|
||||||
};
|
};
|
||||||
TEST_CASE("Read Lists and Symbols", "[reader]") {
|
TEST_CASE("Read Lists and Symbols", "[reader]") {
|
||||||
auto r = new reader::Reader("(x 1)");
|
auto maybeAst = reader::read("(x 1)");
|
||||||
|
|
||||||
auto maybeAst = r->read();
|
|
||||||
|
|
||||||
if (!maybeAst) {
|
if (!maybeAst) {
|
||||||
FAIL();
|
FAIL();
|
||||||
|
@ -91,8 +83,7 @@ TEST_CASE("Read Lists and Symbols", "[reader]") {
|
||||||
REQUIRE_FALSE(ast.empty());
|
REQUIRE_FALSE(ast.empty());
|
||||||
CHECK(ast.front()->toString() == "<List <Symbol x> <Number 1>>");
|
CHECK(ast.front()->toString() == "<List <Symbol x> <Number 1>>");
|
||||||
|
|
||||||
r->setInput("(x (y (z)))");
|
maybeAst = reader::read("(x (y (z)))");
|
||||||
maybeAst = r->read();
|
|
||||||
|
|
||||||
if (!maybeAst) {
|
if (!maybeAst) {
|
||||||
FAIL();
|
FAIL();
|
||||||
|
@ -102,8 +93,7 @@ TEST_CASE("Read Lists and Symbols", "[reader]") {
|
||||||
REQUIRE_FALSE(ast.empty());
|
REQUIRE_FALSE(ast.empty());
|
||||||
CHECK(ast.front()->toString() == "<List <Symbol x> <List <Symbol y> <List <Symbol z>>>>");
|
CHECK(ast.front()->toString() == "<List <Symbol x> <List <Symbol y> <List <Symbol z>>>>");
|
||||||
|
|
||||||
r->setInput("(x \n y)");
|
maybeAst = reader::read("(x \n y)");
|
||||||
maybeAst = r->read();
|
|
||||||
|
|
||||||
if (!maybeAst) {
|
if (!maybeAst) {
|
||||||
FAIL();
|
FAIL();
|
||||||
|
@ -112,8 +102,6 @@ TEST_CASE("Read Lists and Symbols", "[reader]") {
|
||||||
ast = std::move(maybeAst.getValue());
|
ast = std::move(maybeAst.getValue());
|
||||||
REQUIRE_FALSE(ast.empty());
|
REQUIRE_FALSE(ast.empty());
|
||||||
CHECK(ast.front()->toString() == "<List <Symbol x> <Symbol y>>");
|
CHECK(ast.front()->toString() == "<List <Symbol x> <Symbol y>>");
|
||||||
|
|
||||||
delete r;
|
|
||||||
};
|
};
|
||||||
} // namespace reader
|
} // namespace reader
|
||||||
} // namespace serene
|
} // namespace serene
|
||||||
|
|
Loading…
Reference in New Issue