Compare commits
2 Commits
7746fdda6f
...
8a9655cdd5
Author | SHA1 | Date | |
---|---|---|---|
8a9655cdd5 | |||
b6c095caf1 |
@@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <concepts>
|
#include <concepts>
|
||||||
#include <vector>
|
#include <deque>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
@@ -17,7 +17,7 @@ struct Nil {};
|
|||||||
|
|
||||||
|
|
||||||
using LispValue = std::variant<Integer, Double, String, Symbol, List>;
|
using LispValue = std::variant<Integer, Double, String, Symbol, List>;
|
||||||
struct List {std::vector<LispValue> list;};
|
struct List {std::deque<LispValue> list;};
|
||||||
// during compilation, we don't really care for cyclical lists etc.
|
// during compilation, we don't really care for cyclical lists etc.
|
||||||
// during compilation we'll mostly be dealing with regular, flat lists
|
// during compilation we'll mostly be dealing with regular, flat lists
|
||||||
// that form function calls.
|
// that form function calls.
|
||||||
|
@@ -1,7 +1,16 @@
|
|||||||
|
#include "value.hpp"
|
||||||
#include <catch2/catch_test_macros.hpp>
|
#include <catch2/catch_test_macros.hpp>
|
||||||
#include <lex.hpp>
|
#include <lex.hpp>
|
||||||
|
#include <parse.hpp>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
T pop_and_front(deque<T> &dq) {
|
||||||
|
T t = dq.front();
|
||||||
|
dq.pop_front();
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
TEST_CASE("Lexer lexes doubles correctly", "[Lexer]") {
|
TEST_CASE("Lexer lexes doubles correctly", "[Lexer]") {
|
||||||
|
|
||||||
SECTION("double and negative syntax") {
|
SECTION("double and negative syntax") {
|
||||||
@@ -19,3 +28,25 @@ TEST_CASE("Lexer lexes doubles correctly", "[Lexer]") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Parser parses correctly", "[Parser]") {
|
||||||
|
SECTION("hello world") {
|
||||||
|
Parser p (Lexer("(print \"hello world\")"));
|
||||||
|
auto dq = get<List>(*p.next()).list;
|
||||||
|
REQUIRE(get<Symbol>(pop_and_front(dq)).value == "print");
|
||||||
|
REQUIRE(get<String>(pop_and_front(dq)).value == "hello world");
|
||||||
|
}
|
||||||
|
SECTION("doubles") {
|
||||||
|
Parser p (Lexer("(1.0 0.1 -.1 -1. . - -. .-)"));
|
||||||
|
auto dq = get<List>(*p.next()).list;
|
||||||
|
REQUIRE(get<Double>(pop_and_front(dq)).value == 1.0);
|
||||||
|
REQUIRE(get<Double>(pop_and_front(dq)).value == 0.1);
|
||||||
|
REQUIRE(get<Double>(pop_and_front(dq)).value == -0.1);
|
||||||
|
REQUIRE(get<Double>(pop_and_front(dq)).value == -1.0);
|
||||||
|
REQUIRE(get<Symbol>(pop_and_front(dq)).value == ".");
|
||||||
|
REQUIRE(get<Symbol>(pop_and_front(dq)).value == "-");
|
||||||
|
REQUIRE(get<Symbol>(pop_and_front(dq)).value == "-.");
|
||||||
|
REQUIRE(get<Symbol>(pop_and_front(dq)).value == ".-");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user