/* -*- C++ -*- * Serene Programming Language * * Copyright (c) 2019-2022 Sameer Rahmani * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 2. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "serene/reader/reader.h" #include "../test_helpers.cpp.inc" #include namespace serene { namespace reader { TEST_CASE("Read numbers", "[reader]") { auto maybeAst = reader::read("3"); if (!maybeAst) { FAIL(); } auto ast = std::move(maybeAst).getValue(); REQUIRE_FALSE(ast.empty()); CHECK(ast.front()->toString() == ""); maybeAst = reader::read("-34"); if (!maybeAst) { FAIL(); } ast = std::move(maybeAst.getValue()); REQUIRE_FALSE(ast.empty()); CHECK(ast.front()->toString() == ""); maybeAst = reader::read("-3.5434"); if (!maybeAst) { FAIL(); } ast = std::move(maybeAst.getValue()); REQUIRE_FALSE(ast.empty()); CHECK(ast.front()->toString() == ""); maybeAst = reader::read("444323 2123 123123"); if (!maybeAst) { FAIL(); } ast = std::move(maybeAst.getValue()); 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)"); if (!maybeAst) { FAIL(); } auto ast = std::move(maybeAst.getValue()); REQUIRE_FALSE(ast.empty()); CHECK(ast.front()->toString() == " >"); maybeAst = reader::read("(x (y (z)))"); if (!maybeAst) { FAIL(); } ast = std::move(maybeAst.getValue()); REQUIRE_FALSE(ast.empty()); CHECK(ast.front()->toString() == " >>>"); maybeAst = reader::read("(x \n y)"); if (!maybeAst) { FAIL(); } ast = std::move(maybeAst.getValue()); REQUIRE_FALSE(ast.empty()); CHECK(ast.front()->toString() == " >"); }; } // namespace reader } // namespace serene