aboutsummaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorMatthew Hall <hallmatthew314@gmail.com>2023-03-18 22:47:02 +1300
committerMatthew Hall <hallmatthew314@gmail.com>2023-03-18 22:47:02 +1300
commit6406766e5a175c87dfc20c1ff1374c8c8a163517 (patch)
tree4c8e841b0d312ce46245f9748bd4057fb38581b1 /spec
parent467660e024bad8e2e084aa703686d0856a7e88b9 (diff)
Many and Some
Diffstat (limited to 'spec')
-rw-r--r--spec/parcom_spec.cr35
1 files changed, 35 insertions, 0 deletions
diff --git a/spec/parcom_spec.cr b/spec/parcom_spec.cr
index 86ad93a..870b0a2 100644
--- a/spec/parcom_spec.cr
+++ b/spec/parcom_spec.cr
@@ -380,5 +380,40 @@ describe Parser do
result.value.should eq('b')
end
end
+
+ describe "#many" do
+ p = Parser(Char, Char).token('a').many
+
+ it "returns no results if it never succeeds" do
+ ["", "bb"].each do |s|
+ tokens = Tokens.from_string(s)
+ result = p.parse(tokens)
+
+ result.value.empty?.should be_true
+ result.tokens.should eq(tokens)
+ end
+ end
+
+ it "parses as many times as possible" do
+ ["a", "aaa", "aaaaa"].each do |s|
+ tokens = Tokens.from_string(s)
+ result = p.parse(tokens)
+
+ result.value.should eq(s.chars)
+ result.tokens.empty?.should be_true
+ end
+ end
+ end
+
+ describe "#some" do
+ p = Parser(Char, Char).token('a').some
+
+ it "fails if it cannot parse at least once" do
+ ["", "bb"].each do |s|
+ tokens = Tokens.from_string(s)
+ expect_raises(ParserFail) { p.parse(tokens) }
+ end
+ end
+ end
end