Sha256: ccbef75b8b09a08edf3df03d5334418bbb612cad0eef8c23d45dddbee6e43696

Contents?: true

Size: 1.79 KB

Versions: 76

Compression:

Stored size: 1.79 KB

Contents

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

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

  def test_exec
    ghi = Rule.for('ghi')
    grammar1 = Grammar.new {
      rule :a, 'abc'
    }
    grammar2 = Grammar.new {
      include grammar1
      rule :a, any(ghi, sup)
    }
    rule_2a = grammar2.rule(:a)
    rule_2a_als = rule_2a.rules[0]
    rule_2a_sup = rule_2a.rules[1]

    events = rule_2a.exec(Input.new('abc'))
    assert_equal([
      rule_2a,
        rule_2a_sup, CLOSE, 3,
      CLOSE, 3
    ], events)

    events = rule_2a.exec(Input.new('ghi'))
    assert_equal([
      rule_2a,
        rule_2a_als, CLOSE, 3,
      CLOSE, 3
    ], events)
  end

  def test_exec_miss
    grammar1 = Grammar.new {
      rule :a, 'abc'
    }
    grammar2 = Grammar.new {
      include grammar1
      rule :a, any('def', sup)
    }
    rule_2a = grammar2.rule(:a)
    events = rule_2a.exec(Input.new('ghi'))
    assert_equal([], events)
  end

  def test_exec_aliased
    grammar1 = Grammar.new {
      rule :a, 'abc'
      rule :b, 'def'
    }
    grammar2 = Grammar.new {
      include grammar1
      rule :a, any(sup, :b)
      rule :b, sup
    }
    rule_2a = grammar2.rule(:a)
    rule_2a_sup = rule_2a.rules[0]
    rule_2a_als = rule_2a.rules[1]

    events = rule_2a.exec(Input.new('abc'))
    assert_equal([
      rule_2a,
        rule_2a_sup, CLOSE, 3,
      CLOSE, 3
    ], events)

    events = rule_2a.exec(Input.new('def'))
    assert_equal([
      rule_2a,
        rule_2a_als, CLOSE, 3,
      CLOSE, 3
    ], events)
  end

  def test_to_s
    rule = Super.new
    assert_equal('super', rule.to_s)
  end

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

Version data entries

76 entries across 76 versions & 2 rubygems

Version Path
harbr-0.1.49 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/super_test.rb
harbr-0.1.48 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/super_test.rb
harbr-0.1.47 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/super_test.rb
harbr-0.1.46 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/super_test.rb
harbr-0.1.45 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/super_test.rb
harbr-0.1.44 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/super_test.rb
harbr-0.1.43 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/super_test.rb
harbr-0.1.42 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/super_test.rb
harbr-0.1.41 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/super_test.rb
harbr-0.1.39 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/super_test.rb
harbr-0.1.38 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/super_test.rb
harbr-0.1.37 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/super_test.rb
citrus-3.0.2 test/super_test.rb
citrus-3.0.1 test/super_test.rb
citrus-3.0.0 test/super_test.rb
citrus-2.5.0 test/super_test.rb