Sha256: 963d3e727630c9a0b0aa768a48b30a6cd6ff9931c14cb6b43c24eb86edfd2bdb

Contents?: true

Size: 1.14 KB

Versions: 7

Compression:

Stored size: 1.14 KB

Contents

require File.expand_path('../helper', __FILE__)

class AliasTest < Test::Unit::TestCase
  def test_terminal?
    rule = Alias.new
    assert_equal(false, rule.terminal?)
  end

  def test_exec
    grammar = Grammar.new {
      rule :a, :b
      rule :b, 'abc'
    }
    rule_a = grammar.rule(:a)
    rule_b = grammar.rule(:b)
    events = rule_a.exec(Input.new('abc'))
    assert_equal([rule_a, CLOSE, 3], events)
  end

  def test_exec_miss
    grammar = Grammar.new {
      rule :a, :b
      rule :b, 'abc'
    }
    rule = grammar.rule(:a)
    events = rule.exec(Input.new('def'))
    assert_equal([], events)
  end

  def test_exec_included
    grammar1 = Grammar.new {
      rule :a, 'abc'
    }
    grammar2 = Grammar.new {
      include grammar1
      rule :b, :a
    }
    rule_b2 = grammar2.rule(:b)
    rule_a1 = grammar1.rule(:a)
    events = rule_b2.exec(Input.new('abc'))
    assert_equal([rule_b2, CLOSE, 3], events)
  end

  def test_to_s
    rule = Alias.new(:alpha)
    assert_equal('alpha', rule.to_s)
  end

  def test_to_s_with_label
    rule = Alias.new(:alpha)
    rule.label = 'a_label'
    assert_equal('a_label:alpha', rule.to_s)
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
citrus-2.4.1 test/alias_test.rb
citrus-2.4.0 test/alias_test.rb
citrus-2.3.7 test/alias_test.rb
citrus-2.3.6 test/alias_test.rb
citrus-2.3.5 test/alias_test.rb
citrus-2.3.4 test/alias_test.rb
citrus-2.3.3 test/alias_test.rb