Skip to content

Commit

Permalink
chore: Add tests for coroutine
Browse files Browse the repository at this point in the history
  • Loading branch information
GearsDatapacks committed Feb 13, 2023
1 parent 307800a commit a03563a
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions spec/parsby/combinators_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -487,4 +487,22 @@ def self.parenthesis
expect { eof.parse("x") }.to raise_error Parsby::ExpectationFailed
end
end

describe "#coroutine" do
it "parses a group defined by a block" do
test_parser = coroutine do |parse|
a_or_b = parse.call choice(lit("a"),lit("b"))

if a_or_b == "a"
parse.call lit("c")
else
parse.call lit("d")
end
end

expect(test_parser.parse("ac")).to eq "c"
expect(test_parser.parse("bd")).to eq "d"
expect { test_parser.parse("ad") }.to raise_error Parsby::ExpectationFailed
end
end
end

0 comments on commit a03563a

Please sign in to comment.