aboutsummaryrefslogtreecommitdiff
path: root/spec/parcom_spec.cr
diff options
context:
space:
mode:
authorMatthew Hall <hallmatthew314@gmail.com>2023-03-17 22:50:14 +1300
committerMatthew Hall <hallmatthew314@gmail.com>2023-03-17 22:50:14 +1300
commit982d239252b54297ff3558894038871f8d3a4175 (patch)
tree41ab6073fd601caf2da0bf87c4cd8226b87b7126 /spec/parcom_spec.cr
parentf023ca56dbf9372464afe0060270fcef85271db0 (diff)
Please work this time
Diffstat (limited to 'spec/parcom_spec.cr')
-rw-r--r--spec/parcom_spec.cr65
1 files changed, 32 insertions, 33 deletions
diff --git a/spec/parcom_spec.cr b/spec/parcom_spec.cr
index ceb7de8..05fd12d 100644
--- a/spec/parcom_spec.cr
+++ b/spec/parcom_spec.cr
@@ -79,29 +79,10 @@ describe Result do
end
end
-pending Parser do
- describe "#assert" do
- p = Basic(Char, Char).any_token.assert { |c| c == 'a' }
-
- it "succeeds if the parser succeeds and if the predicate passes" do
- tokens = Tokens.from_string("abcd")
- result = p.parse(tokens)
-
- result.value.should eq(tokens[0])
- result.tokens.should eq(tokens[1..])
- end
-
- it "fails if the predicate fails" do
- tokens = Tokens.from_string("bbcd")
- expect_raises(ParserFail) { p.parse(tokens) }
- end
- end
-end
-
-describe Basic do
- describe "Basic.pure" do
+describe Parser do
+ describe "Parser.pure" do
v = 'a'
- p = Basic(Char, Char).pure(v)
+ p = Parser(Char, Char).pure(v)
tokens = Tokens.from_string("____")
result = p.parse(tokens)
@@ -114,15 +95,15 @@ describe Basic do
end
end
- describe "Basic.flunk" do
- p = Basic(Char, Char).flunk
+ describe "Parser.flunk" do
+ p = Parser(Char, Char).flunk
it "always fails" do
expect_raises(ParserFail) { p.parse(Tokens.from_string("arbitrary")) }
end
end
- describe "Basic.any_token" do
- p = Basic(Char, Nil).any_token
+ describe "Parser.any_token" do
+ p = Parser(Char, Nil).any_token
it "parses the first token in the input stream" do
tokens = Tokens.from_string("abcd")
@@ -138,8 +119,8 @@ describe Basic do
end
end
- describe "Basic.eof" do
- p = Basic(Char, Nil).eof
+ describe "Parser.eof" do
+ p = Parser(Char, Nil).eof
it "succeeds with nil if the input stream is empty" do
tokens = Tokens.from_string("")
@@ -155,14 +136,12 @@ describe Basic do
end
end
- # TODO: the type checker hates me
- describe "Basic.satisfy" do
- #p = Basic.satisfy(Char) { |c| c == 'a' }
- p = Basic(Char, Char).satisfy(->(c : Char) { c == 'a' })
+ describe "Parser.satisfy" do
+ p = Parser(Char, Char).satisfy { |c| c == 'a' }
it "succeeds if the token passes the predicate" do
tokens = Tokens.from_string("abcd")
- result = p.parse(tokens).as_a(Result(Char, Char))
+ result = p.parse(tokens)
result.value.should eq(tokens[0])
result.tokens.should eq(tokens[1..])
@@ -173,5 +152,25 @@ describe Basic do
expect_raises(ParserFail) { p.parse(tokens) }
end
end
+
+ describe "#assert" do
+ p = Parser(Char, Char).any_token.assert { |c| c == 'a' }
+
+ it "succeeds if the parser succeeds and if the predicate passes" do
+ tokens = Tokens.from_string("abcd")
+ result = p.parse(tokens)
+
+ result.value.should eq(tokens[0])
+ result.tokens.should eq(tokens[1..])
+ end
+
+ it "fails if the predicate fails" do
+ tokens = Tokens.from_string("bbcd")
+ expect_raises(ParserFail) { p.parse(tokens) }
+ end
+ end
end
+#pending Basic do
+##end
+