Module: Rattler::Util::ParserSpecHelper

Defined in:
lib/rattler/util/parser_spec_helper.rb

Overview

ParserSpecHelper defines a fluent interface for writing RSpec examples for parsers.

Examples:


require 'my_awesome_language/my_awesome_parser'
require 'rattler/util/parser_spec_helper'

describe MyAwesomeLanguage::MyAwesomeParser do
  include Rattler::Util::ParserSpecHelper

  describe '#match(:var_name)' do
    it 'recognizes variable names' do
      matching(' fooBar ').as(:var_name).should result_in('fooBar').at(7)
    end
    it 'rejects non-variables' do
      matching(' 42 ').as(:var_name).should fail.with_message('variable name expected')
    end
  end
end

Defined Under Namespace

Classes: Matching, Parsing

Instance Method Summary collapse

Instance Method Details

#matching(source) ⇒ Object

Return a match result to be matched using #result_in or #fail

matching(source).as(rule_name)
matching(source).as(rule_name).from(pos)


42
43
44
# File 'lib/rattler/util/parser_spec_helper.rb', line 42

def matching(source)
  Matching.new(parser(source))
end

#parsing(source) ⇒ Object

Return a parse result to be matched using #result_in or #fail

parsing(source)
parsing(source).from(pos)


33
34
35
# File 'lib/rattler/util/parser_spec_helper.rb', line 33

def parsing(source)
  Parsing.new(parser(source))
end