aboutsummaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-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'))