Skip to content

Commit

Permalink
Fixed specs for !patt (Unless) and &patt (If).
Browse files Browse the repository at this point in the history
  • Loading branch information
brixen committed Oct 27, 2010
1 parent 8ae96fa commit 92b55a4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 17 deletions.
26 changes: 18 additions & 8 deletions spec/matching/shared/if.rb
@@ -1,16 +1,26 @@
describe :ast_if, :shared => true do
it "returns nil if the first pattern does not match" do
pat = Pegarus.pattern(1) + +Pegarus.pattern("a")
it "returns nil if the subject is empty" do
pat = +Pegarus.pattern("abc")
pat.match("").should be_nil
end

it "returns nil if the second pattern does not match" do
pat = Pegarus.pattern(1) + +Pegarus.pattern("c")
pat.match("ab").should be_nil
it "returns nil if the pattern does not match" do
pat = +Pegarus.pattern("abc")
pat.match("abdc").should be_nil
end

it "returns the index of the character following the matched substring" do
pat = Pegarus.pattern(1) + +Pegarus.pattern("ac")
pat.match("aacbde").should == 1
it "returns the index at the beginning of the pattern if the pattern matches" do
pat = +Pegarus.pattern("abc")
pat.match("abcd").should == 0
end

it "returns nil if the compound pattern does not match" do
pat = +(Pegarus.pattern("a") + Pegarus.pattern("c"))
pat.match("abc").should be_nil
end

it "returns the index at the beginning of the pattern if the compound pattern matches" do
pat = Pegarus.pattern(1) + +(Pegarus.pattern("b") + Pegarus.pattern("c"))
pat.match("abcd").should == 1
end
end
28 changes: 19 additions & 9 deletions spec/matching/shared/unless.rb
@@ -1,16 +1,26 @@
describe :ast_unless, :shared => true do
it "returns nil if the first pattern does not match" do
pat = Pegarus.pattern(1) + -Pegarus.pattern("a")
pat.match("").should be_nil
it "returns 0 if the subject is empty" do
pat = -Pegarus.pattern("abc")
pat.match("").should == 0
end

it "returns nil if the second pattern match" do
pat = Pegarus.pattern(1) + -Pegarus.pattern("b")
pat.match("ab").should be_nil
it "returns nil of the pattern matches" do
pat = -Pegarus.pattern("abc")
pat.match("abcd").should be_nil
end

it "returns the index of the character following the matched substring" do
pat = Pegarus.pattern(1) + -Pegarus.pattern("xx")
pat.match("aacbde").should == 1
it "returns the index at the beginning of the pattern if the pattern does not match" do
pat = -Pegarus.pattern("abc")
pat.match("bcd").should == 0
end

it "returns nil if the compound pattern matches" do
pat = -(Pegarus.pattern("a") + Pegarus.pattern("bc"))
pat.match("abc").should be_nil
end

it "returns the index at the beginning of the pattern if the compound pattern does not match" do
pat = Pegarus.pattern(1) + -(Pegarus.pattern("b") + Pegarus.pattern("d"))
pat.match("abcd").should == 1
end
end

0 comments on commit 92b55a4

Please sign in to comment.