summaryrefslogtreecommitdiff
path: root/jni/ruby/test/rdoc/test_rdoc_include.rb
blob: 464a6980182741e37e25f174eed553bbb3029386 (plain)
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
require File.expand_path '../xref_test_case', __FILE__

class TestRDocInclude < XrefTestCase

  def setup
    super

    @inc = RDoc::Include.new 'M1', 'comment'
    @inc.parent = @m1
    @inc.record_location @top_level
    @inc.store = @store
  end

  def test_module
    assert_equal @m1, @inc.module
    assert_equal 'Unknown', RDoc::Include.new('Unknown', 'comment').module
  end

  def test_module_extended
    m1 = @xref_data.add_module RDoc::NormalModule, 'Mod1'
    m1_m3 = m1.add_module RDoc::NormalModule, 'Mod3'
    m1_m2 = m1.add_module RDoc::NormalModule, 'Mod2'
    m1_m2_m3 = m1_m2.add_module RDoc::NormalModule, 'Mod3'
    m1_m2_m3_m4 = m1_m2_m3.add_module RDoc::NormalModule, 'Mod4'
    m1_m2_m4 = m1_m2.add_module RDoc::NormalModule, 'Mod4'
    m1_m2_k0 = m1_m2.add_class RDoc::NormalClass, 'Klass0'
    m1_m2_k0_m4 = m1_m2_k0.add_module RDoc::NormalModule, 'Mod4'
    #m1_m2_k0_m4_m5 = m1_m2_k0_m4.add_module RDoc::NormalModule, 'Mod5'
    m1_m2_k0_m4_m6 = m1_m2_k0_m4.add_module RDoc::NormalModule, 'Mod6'
    m1_m2_k0_m5 = m1_m2_k0.add_module RDoc::NormalModule, 'Mod5'

    i0_m4 = RDoc::Include.new 'Mod4', nil
    i0_m5 = RDoc::Include.new 'Mod5', nil
    i0_m6 = RDoc::Include.new 'Mod6', nil
    i0_m1 = RDoc::Include.new 'Mod1', nil
    i0_m2 = RDoc::Include.new 'Mod2', nil
    i0_m3 = RDoc::Include.new 'Mod3', nil

    m1_m2_k0.add_include i0_m4
    m1_m2_k0.add_include i0_m5
    m1_m2_k0.add_include i0_m6
    m1_m2_k0.add_include i0_m1
    m1_m2_k0.add_include i0_m2
    m1_m2_k0.add_include i0_m3

    assert_equal [i0_m4, i0_m5, i0_m6, i0_m1, i0_m2, i0_m3], m1_m2_k0.includes
    assert_equal [m1_m2_m3, m1_m2, m1, m1_m2_k0_m4_m6, m1_m2_k0_m5,
                  m1_m2_k0_m4, 'Object'], m1_m2_k0.ancestors

    m1_k1 = m1.add_class RDoc::NormalClass, 'Klass1'

    i1_m1 = RDoc::Include.new 'Mod1', nil
    i1_m2 = RDoc::Include.new 'Mod2', nil
    i1_m3 = RDoc::Include.new 'Mod3', nil
    i1_m4 = RDoc::Include.new 'Mod4', nil
    i1_k0_m4 = RDoc::Include.new 'Klass0::Mod4', nil

    m1_k1.add_include i1_m1
    m1_k1.add_include i1_m2
    m1_k1.add_include i1_m3
    m1_k1.add_include i1_m4
    m1_k1.add_include i1_k0_m4

    assert_equal [i1_m1, i1_m2, i1_m3, i1_m4, i1_k0_m4], m1_k1.includes
    assert_equal [m1_m2_k0_m4, m1_m2_m3_m4, m1_m2_m3, m1_m2, m1, 'Object'],
                 m1_k1.ancestors

    m1_k2 = m1.add_class RDoc::NormalClass, 'Klass2'

    i2_m1 = RDoc::Include.new 'Mod1', nil
    i2_m2 = RDoc::Include.new 'Mod2', nil
    i2_m3 = RDoc::Include.new 'Mod3', nil
    i2_k0_m4 = RDoc::Include.new 'Klass0::Mod4', nil

    m1_k2.add_include i2_m1
    m1_k2.add_include i2_m3
    m1_k2.add_include i2_m2
    m1_k2.add_include i2_k0_m4

    assert_equal [i2_m1, i2_m3, i2_m2, i2_k0_m4], m1_k2.includes
    assert_equal [m1_m2_k0_m4, m1_m2, m1_m3, m1, 'Object'], m1_k2.ancestors

    m1_k3 = m1.add_class RDoc::NormalClass, 'Klass3'

    i3_m1 = RDoc::Include.new 'Mod1', nil
    i3_m2 = RDoc::Include.new 'Mod2', nil
    i3_m4 = RDoc::Include.new 'Mod4', nil

    m1_k3.add_include i3_m1
    m1_k3.add_include i3_m2
    m1_k3.add_include i3_m4

    assert_equal [i3_m1, i3_m2, i3_m4], m1_k3.includes
    assert_equal [m1_m2_m4, m1_m2, m1, 'Object'], m1_k3.ancestors
  end

  def test_store_equals
    incl = RDoc::Include.new 'M', nil
    incl.record_location RDoc::TopLevel.new @top_level.name

    incl.store = @store

    assert_same @top_level, incl.file
    assert_same @store,     incl.file.store
  end

end