Sha256: afb2ae91f1cf13e4e761cc59fb75f7e5cd5bc589e7d658b23be6970de47516ed

Contents?: true

Size: 1.33 KB

Versions: 6

Compression:

Stored size: 1.33 KB

Contents

require 'spec_helper'

module TerminalSymbolSpec
  class Foo < Treetop::Runtime::SyntaxNode
  end

  describe "a terminal symbol followed by a node class declaration and a block" do
    testing_expression "'foo' <TerminalSymbolSpec::Foo> { def a_method; end }"

    it "correctly parses matching input prefixes at various indices, returning an instance of the declared class that can respond to methods defined in the inline module" do
      parse "foo", :index => 0 do |result|
        result.should be_an_instance_of(Foo)
        result.should respond_to(:a_method)
        result.interval.should == (0...3)
        result.text_value.should == 'foo'
      end

      parse "xfoo", :index => 1 do |result|
        result.should be_an_instance_of(Foo)
        result.should respond_to(:a_method)
        result.interval.should == (1...4)
        result.text_value.should == 'foo'
      end
    
      parse "---foo", :index => 3 do |result|
        result.should be_an_instance_of(Foo)
        result.should respond_to(:a_method)
        result.interval.should == (3...6)
        result.text_value.should == 'foo'
      end
    end

    it "fails to parse nonmatching input at the index even if a match occurs later" do
      parse(" foo", :index =>  0) do |result|
	result.should be_nil
	parser.terminal_failures.size.should == 1
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
treetop-1.6.5 spec/compiler/terminal_symbol_spec.rb
treetop-1.6.4 spec/compiler/terminal_symbol_spec.rb
swift-pyrite-0.1.1 vendor/bundle/ruby/2.0.0/gems/treetop-1.6.3/spec/compiler/terminal_symbol_spec.rb
swift-pyrite-0.1.0 vendor/bundle/ruby/2.0.0/gems/treetop-1.6.3/spec/compiler/terminal_symbol_spec.rb
treetop-1.6.3 spec/compiler/terminal_symbol_spec.rb
treetop-1.6.2 spec/compiler/terminal_symbol_spec.rb