Sha256: 2206e41673f390a60297d7073a65db20082d74a8f551e0e23a7762b97ee61dd3

Contents?: true

Size: 878 Bytes

Versions: 1

Compression:

Stored size: 878 Bytes

Contents

require 'spec_helper'
module Sexpr
  describe Grammar, "parse" do

    def grammar
      Sexpr.load(:parser => parser)
    end

    context 'when no parser is set' do
      let(:parser){ nil }

      it 'raises an error' do
        lambda{
          grammar.parse("Hello world")
        }.should raise_error(NoParserError)
      end

    end

    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)]
          end
        }
      }

      it 'delegates the call to the parser' do
        grammar.parse("Hello world").should eq([:parsed, "Hello world"])
      end

      it 'passes options' do
        grammar.parse("world", :root => :hello).should eq([:hello, "world"])
      end

    end # when a parser is set

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sexpr-0.3.0 spec/grammar/test_parse.rb