aboutsummaryrefslogtreecommitdiff
path: root/spec/parcom_spec.cr
diff options
context:
space:
mode:
authorMatthew Hall <hallmatthew314@gmail.com>2023-03-11 00:35:43 +1300
committerMatthew Hall <hallmatthew314@gmail.com>2023-03-11 00:35:43 +1300
commit27fb4fa0babc2c3db41c93865a35430515ff3630 (patch)
treec511d07915703b7e162c944a0affa6d48d905736 /spec/parcom_spec.cr
parent60be5fc8a6be8f60ed37af30ef18f02639259774 (diff)
Implement Left and Right parsers
Diffstat (limited to 'spec/parcom_spec.cr')
-rw-r--r--spec/parcom_spec.cr32
1 files changed, 32 insertions, 0 deletions
diff --git a/spec/parcom_spec.cr b/spec/parcom_spec.cr
index 77a14dd..d67f19a 100644
--- a/spec/parcom_spec.cr
+++ b/spec/parcom_spec.cr
@@ -308,6 +308,38 @@ describe Plus do
end
end
+# most behavior shouldn't need to be tested
+# since it is based on tested bbehavior from
+# Plus and Map
+describe Left do
+ describe "#parse" do
+ it "returns the value of the first parser if both succeed" do
+ tokens = TokenStream.from_string("testing")
+ letter_t = Token.new('t')
+ letter_e = Token.new('e')
+ result = (letter_t << letter_e).parse(tokens)
+
+ result.value.should eq('t')
+ result.tokens.should eq(tokens[2..])
+ end
+ end
+end
+
+# same deal as Left
+describe Right do
+ describe "#parse" do
+ it "returns the value of the second parser if both succeed" do
+ tokens = TokenStream.from_string("testing")
+ letter_t = Token.new('t')
+ letter_e = Token.new('e')
+ result = (letter_t >> letter_e).parse(tokens)
+
+ result.value.should eq('e')
+ result.tokens.should eq(tokens[2..])
+ end
+ end
+end
+
describe Phrase do
p = Phrase.new(Token.new('t'))