From 27fb4fa0babc2c3db41c93865a35430515ff3630 Mon Sep 17 00:00:00 2001 From: Matthew Hall Date: Sat, 11 Mar 2023 00:35:43 +1300 Subject: Implement Left and Right parsers --- spec/parcom_spec.cr | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'spec/parcom_spec.cr') diff --git a/spec/parcom_spec.cr b/spec/parcom_spec.cr index 77a14dd..d67f19a 100644 --- a/spec/parcom_spec.cr +++ b/spec/parcom_spec.cr @@ -308,6 +308,38 @@ describe Plus do end end +# most behavior shouldn't need to be tested +# since it is based on tested bbehavior from +# Plus and Map +describe Left do + describe "#parse" do + it "returns the value of the first parser if both succeed" do + tokens = TokenStream.from_string("testing") + letter_t = Token.new('t') + letter_e = Token.new('e') + result = (letter_t << letter_e).parse(tokens) + + result.value.should eq('t') + result.tokens.should eq(tokens[2..]) + end + end +end + +# same deal as Left +describe Right do + describe "#parse" do + it "returns the value of the second parser if both succeed" do + tokens = TokenStream.from_string("testing") + letter_t = Token.new('t') + letter_e = Token.new('e') + result = (letter_t >> letter_e).parse(tokens) + + result.value.should eq('e') + result.tokens.should eq(tokens[2..]) + end + end +end + describe Phrase do p = Phrase.new(Token.new('t')) -- cgit v1.2.1