diff options
| author | Matthew Hall <hallmatthew314@gmail.com> | 2023-03-09 15:39:01 +1300 |
|---|---|---|
| committer | Matthew Hall <hallmatthew314@gmail.com> | 2023-03-09 15:39:01 +1300 |
| commit | 15e3a96876ca9e8bd67c7408ebcc123c35a1e447 (patch) | |
| tree | 77e299346e3198eaf4494742d142f8b3e47eb9d7 /spec | |
| parent | f5e87b41ffcb036c705c32b55161ae91a04c72e1 (diff) | |
Implement Many and Some
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/parcom_spec.cr | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/spec/parcom_spec.cr b/spec/parcom_spec.cr index 937c43c..57c5024 100644 --- a/spec/parcom_spec.cr +++ b/spec/parcom_spec.cr @@ -402,10 +402,56 @@ describe Tokens do end end -pending Many do +describe Many do + p = Many.new(Token.new('a')) + + describe "#parse" do + it "returns an empty array if the wrapped parser never succeeds" do + tokens = TokenStream.from_string("bb") + result = p.parse(tokens) + + result.value.empty?.should be_true + result.tokens.should eq(tokens) + end + + it "stops parsing when the wrapped parser fails, returns all successes" do + tokens = TokenStream.from_string("aaabcd") + result = p.parse(tokens) + + result.value.should eq("aaa".chars) + result.tokens.should eq(tokens[3..]) + + tokens = TokenStream.from_string("aaa") + result = p.parse(tokens) + + result.value.should eq("aaa".chars) + result.tokens.should eq(tokens[3..]) + end + end end -pending Some do +describe Some do + p = Some.new(Token.new('a')) + describe "#parse" do + it "fails if the wrapped parser never succeeds" do + tokens = TokenStream.from_string("") + expect_raises(ParserException) { p.parse(tokens) } + end + + it "stops parsing when the wrapped parser fails, returns all successes" do + tokens = TokenStream.from_string("aaabcd") + result = p.parse(tokens) + + result.value.should eq("aaa".chars) + result.tokens.should eq(tokens[3..]) + + tokens = TokenStream.from_string("aaa") + result = p.parse(tokens) + + result.value.should eq("aaa".chars) + result.tokens.should eq(tokens[3..]) + end + end end pending Exactly do |
