spec/grammar/test_parse.rb in sexpr-0.3.0 vs spec/grammar/test_parse.rb in sexpr-0.4.0
- old
+ new
@@ -1,11 +1,15 @@
require 'spec_helper'
module Sexpr
describe Grammar, "parse" do
def grammar
- Sexpr.load(:parser => parser)
+ Sexpr.load(:parser => parser).extend Module.new{
+ def default_parse_options
+ {:root => :root_rule, :hello => "world"}
+ end
+ }
end
context 'when no parser is set' do
let(:parser){ nil }
@@ -20,20 +24,20 @@
context 'when a parser is set' do
let(:parser){
Object.new.extend Module.new{
include Parser
def parse(s, options = {})
- [options[:root] || :parsed, input_text(s)]
+ [options[:root], "#{s} #{options[:hello]}"]
end
}
}
- it 'delegates the call to the parser' do
- grammar.parse("Hello world").should eq([:parsed, "Hello world"])
+ it 'uses default options when no options are passed' do
+ grammar.parse("Hello").should eq([:root_rule, "Hello world"])
end
- it 'passes options' do
- grammar.parse("world", :root => :hello).should eq([:hello, "world"])
+ it 'merge passed options with default ones' do
+ grammar.parse("Hello", :root => :another_rule).should eq([:another_rule, "Hello world"])
end
end # when a parser is set
end
\ No newline at end of file