1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
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
|