diff options
| author | Matthew Hall <hallmatthew314@gmail.com> | 2023-03-19 23:21:36 +1300 |
|---|---|---|
| committer | Matthew Hall <hallmatthew314@gmail.com> | 2023-03-19 23:21:36 +1300 |
| commit | 4732d4312a3df624c4ea3d861279ab186788979f (patch) | |
| tree | 31ce3ccfca9e3a0462fdf6f51cdb0b9db7c1db84 /spec | |
| parent | 9734fa2d530b9496b70a388a117ea57fe5730772 (diff) | |
sep_by, and some small tweaks
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/parcom_spec.cr | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/spec/parcom_spec.cr b/spec/parcom_spec.cr index af95953..ba17584 100644 --- a/spec/parcom_spec.cr +++ b/spec/parcom_spec.cr @@ -651,7 +651,33 @@ describe Parser do end end - # TODO: sep_by + describe "#sep_by" do + a = Parser.token('a') + b = Parser.token('b') + p = a.sep_by(b) + + it "fails if it cannot parse the first element" do + tokens = Tokens.from_string("cba") + expect_raises(ParserFail) { p.parse(tokens) } + end + + it "will parse a single element without separators" do + tokens = Tokens.from_string("aca") + result = p.parse(tokens) + + result.value.should eq(['a']) + result.tokens.should eq(tokens[1..]) + end + + it "will parse one element, and as many others separated by sep" do + tokens = Tokens.from_string("abababaa") + result = p.parse(tokens) + + result.value.should eq(['a', 'a', 'a', 'a']) + result.tokens.should eq(tokens[7..]) + end + end + # TODO: phrase # TODO: peek end |
