aboutsummaryrefslogtreecommitdiff
path: root/spec/parcom_spec.cr
diff options
context:
space:
mode:
authorMatthew Hall <hallmatthew314@gmail.com>2023-03-22 21:32:23 +1300
committerMatthew Hall <hallmatthew314@gmail.com>2023-03-22 21:32:23 +1300
commit33e84cba11e0644b39a3dbea7c4195dd82290858 (patch)
tree0418300e3901e6ae0a497270a55ee3fa4e60e6cb /spec/parcom_spec.cr
parenta30e194bce569b168dfc237f01add1cd028e8c23 (diff)
Some more tests for and_thenand_then
Diffstat (limited to 'spec/parcom_spec.cr')
-rw-r--r--spec/parcom_spec.cr19
1 files changed, 16 insertions, 3 deletions
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