From a26ccb40ca98c82f486f1c57334ccc04534a1a23 Mon Sep 17 00:00:00 2001 From: Matthew Hall Date: Thu, 9 Mar 2023 21:32:35 +1300 Subject: Implement between + improve error handling --- spec/parcom_spec.cr | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'spec') 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 -- cgit v1.2.1