aboutsummaryrefslogtreecommitdiff
path: root/spec/parcom_spec.cr
diff options
context:
space:
mode:
authorMatthew Hall <hallmatthew314@gmail.com>2023-03-09 21:32:35 +1300
committerMatthew Hall <hallmatthew314@gmail.com>2023-03-09 21:32:35 +1300
commita26ccb40ca98c82f486f1c57334ccc04534a1a23 (patch)
tree4d44196022f2280ecc47e07802c6575c3df1ac1a /spec/parcom_spec.cr
parent9dc06838e3c78e4a77731cab6bc773846eafce99 (diff)
Implement between + improve error handling
Diffstat (limited to 'spec/parcom_spec.cr')
-rw-r--r--spec/parcom_spec.cr20
1 files changed, 19 insertions, 1 deletions
diff --git a/spec/parcom_spec.cr b/spec/parcom_spec.cr
index 6301c2e..fd4b470 100644
--- a/spec/parcom_spec.cr
+++ b/spec/parcom_spec.cr
@@ -539,6 +539,7 @@ describe AtLeast do
it "fails if there are not enough matching tokens to parse" do
p = AtLeast.new(5, letter_a)
expect_raises(ParserException) { p.parse(tokens) }
+ #expect_raises(ParserException) { raise ParserException.new("sdgseg") }
end
it "parses n or more times with the given parser" do
@@ -584,7 +585,24 @@ describe AtMost do
end
end
-pending Between do
+describe Between do
+ letter_a = Token.new('a')
+ tokens = TokenStream.from_string("aaaabcd")
+
+ describe "#parse" do
+ it "parses at least i times, up to a limit of j times" do
+ p0_4 = Between.new(0, 4, letter_a)
+ r0_4 = p0_4.parse(tokens)
+
+ r0_4.value.should eq("aaaa".chars)
+ r0_4.tokens.should eq(tokens[4..])
+ end
+
+ it "fails if there are not enough parser successes" do
+ p = Between.new(5, 6, letter_a)
+ expect_raises(ParserException) { p.parse(tokens) }
+ end
+ end
end
pending StopAt do