aboutsummaryrefslogtreecommitdiff
path: root/spec/parcom_spec.cr
diff options
context:
space:
mode:
authorMatthew Hall <hallmatthew314@gmail.com>2023-03-08 20:11:24 +1300
committerMatthew Hall <hallmatthew314@gmail.com>2023-03-08 20:11:24 +1300
commitf7b089d954cb028ee3c46ad45f0f81ae2e5386cf (patch)
tree3b079b43f1820676528baa1b7f74d7594477a4a4 /spec/parcom_spec.cr
parent8835f1de0dbc6a059a42fad78d4acbb0984b94e2 (diff)
Implement Phrase
Diffstat (limited to 'spec/parcom_spec.cr')
-rw-r--r--spec/parcom_spec.cr25
1 files changed, 24 insertions, 1 deletions
diff --git a/spec/parcom_spec.cr b/spec/parcom_spec.cr
index f35465c..c395636 100644
--- a/spec/parcom_spec.cr
+++ b/spec/parcom_spec.cr
@@ -310,7 +310,30 @@ describe Plus do
end
end
-pending Phrase do
+describe Phrase do
+ p = Phrase.new(Token.new('t'))
+
+ describe "#parse" do
+ it "fails if the wrapped parser fails" do
+ tokens = TokenStream.from_string("_")
+
+ expect_raises(ParserException) { p.parse(tokens) }
+ end
+
+ it "fails if not all of the input tokens are parsed" do
+ tokens = TokenStream.from_string("tt")
+
+ expect_raises(ParserException) { p.parse(tokens) }
+ end
+
+ it "succeeds if the wrapped parser successfully parses all of the input" do
+ tokens = TokenStream.from_string("t")
+ result = p.parse(tokens)
+
+ result.tokens.empty?.should be_true
+ result.value.should eq('t')
+ end
+ end
end
pending Recover do