-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
26 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
require 'spec/matching/machine/setup' | ||
require 'spec/matching/shared/grammar' | ||
|
||
describe "Grammar#match" do | ||
it_should_behave_like :ast_grammar | ||
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
describe :ast_grammar, :shared => true do | ||
before :each do | ||
@grammar = Pegarus.grammar | ||
@grammar.B = Pegarus.pattern("a") + -Pegarus.pattern(1) | ||
@grammar.S = (@grammar.B / Pegarus.pattern("b")) * 1 | ||
@grammar.start = :S | ||
end | ||
|
||
it "returns nil if the grammar does not match" do | ||
@grammar.match("cab").should be_nil | ||
end | ||
|
||
it "returns the index following the last matched character" do | ||
@grammar.match("bab").should == 1 | ||
end | ||
|
||
it "returns the index past the end of the subject when the full subject matches" do | ||
@grammar.match("bbba").should == 4 | ||
end | ||
end |