Sha256: a36c3cf6bc5e31dc03bfe6aaaaf828942a3373d30e20c86508df3cd9fada6aad

Contents?: true

Size: 1.81 KB

Versions: 3

Compression:

Stored size: 1.81 KB

Contents

require File.join(File.dirname(__FILE__), '..', 'test_helper')

describe "A choice between terminal symbols", :extend => CompilerTestCase do
  testing_expression '"foo" { def foo_method; end } / "bar" { def bar_method; end } / "baz" { def baz_method; end }'

  it "successfully parses input matching any of the alternatives, returning a node that responds to methods defined in its respective inline module" do
    result = parse('foo')
    result.should be_success
    result.should respond_to(:foo_method)
    
    result = parse('bar')
    result.should be_success
    result.should respond_to(:bar_method)
    
    result = parse('baz')
    result.should be_success
    result.should respond_to(:baz_method)
  end
  
  it "attaches the nested failure of the first terminal to a successful parsing of input matching the second" do
    result = parse('bar')
    result.nested_failures.size.should == 1
    nested_failure = result.nested_failures[0]
    nested_failure.expected_string.should == 'foo'
    nested_failure.index.should == 0
  end
  
  it "attaches the nested failure of the first and second terminal to a successful parsing of input matching the third" do
    result = parse('baz')
    result.nested_failures.size.should == 2

    first_nested_failure = result.nested_failures[0]
    first_nested_failure.expected_string == 'foo'
    first_nested_failure.index.should == 0
    
    first_nested_failure = result.nested_failures[1]
    first_nested_failure.expected_string == 'bar'
    first_nested_failure.index.should == 0
  end
end

describe "A choice between sequences", :extend => CompilerTestCase do
  testing_expression "'foo' 'bar' 'baz'\n/\n'bing' 'bang' 'boom'"

  it "successfully parses input matching any of the alternatives" do
    parse('foobarbaz').should be_success
    parse('bingbangboom').should be_success
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
treetop-1.0.2 test/compiler/choice_test.rb
treetop-1.0.1 test/compiler/choice_test.rb
treetop-1.0.0 test/compiler/choice_test.rb