From 33e84cba11e0644b39a3dbea7c4195dd82290858 Mon Sep 17 00:00:00 2001 From: Matthew Hall Date: Wed, 22 Mar 2023 21:32:23 +1300 Subject: Some more tests for and_then --- spec/parcom_spec.cr | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'spec') diff --git a/spec/parcom_spec.cr b/spec/parcom_spec.cr index c586a7c..efb3964 100644 --- a/spec/parcom_spec.cr +++ b/spec/parcom_spec.cr @@ -418,10 +418,23 @@ describe Parser do # Parses two of the same word, with whitespace between: two_words = (p_any_word << space).and_then(p_string) - tokens = Tokens.from_string("foo foo") - result = two_words.parse(tokens) + it "succeeds if the original parser and generated parser succeed" do + tokens = Tokens.from_string("foo foo") + result = two_words.parse(tokens) - result.value.should eq("foo") + result.value.should eq("foo") + result.tokens.empty?.should be_true + end + + it "fails if the original parser fails" do + tokens = Tokens.from_string("__ foo") + expect_raises(ParserFail) { two_words.parse(tokens) } + end + + it "fails if the generated parser fails" do + tokens = Tokens.from_string("bar foo") + expect_raises(ParserFail) { two_words.parse(tokens) } + end end describe "#many" do -- cgit v1.2.1