From 61a58de90c2781562aacc8006616e97a3ff12005 Mon Sep 17 00:00:00 2001 From: Matthew Hall Date: Wed, 8 Mar 2023 20:22:33 +1300 Subject: Implement recover --- spec/parcom_spec.cr | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/parcom_spec.cr b/spec/parcom_spec.cr index c395636..d9af3b9 100644 --- a/spec/parcom_spec.cr +++ b/spec/parcom_spec.cr @@ -336,7 +336,26 @@ describe Phrase do end end -pending Recover do +describe Recover do + p = Recover.new(Token.new('t'), '@') + + describe "#parse" do + it "succeeds and returns the wrapped parser's value if it succeeds" do + tokens = TokenStream.from_string("testing") + result = p.parse(tokens) + + result.tokens.should eq(tokens[1..]) + result.value.should eq('t') + end + + it "succeeds and returns the default value without modifying the input of the wrapped parser fails" do + tokens = TokenStream.from_string("_____") + result = p.parse(tokens) + + result.tokens.should eq(tokens) + result.value.should eq('@') + end + end end pending Optional do -- cgit v1.2.1