Skip to content

Commit

Permalink
Specs for matching a grammar.
Browse files Browse the repository at this point in the history
  • Loading branch information
brixen committed Nov 6, 2010
1 parent f4402bb commit 8c89d3d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions spec/matching/machine/grammar_spec.rb
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
20 changes: 20 additions & 0 deletions spec/matching/shared/grammar.rb
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

0 comments on commit 8c89d3d

Please sign in to comment.