Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed specs for !patt (Unless) and &patt (If).
- Loading branch information
Showing
2 changed files
with
37 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |