summaryrefslogtreecommitdiff
path: root/test/rdoc/test_rdoc_constant.rb
blob: 171963d8e4eb3e1a80cfc329ec8568d306811501 (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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
require File.expand_path '../xref_test_case', __FILE__

class TestRDocConstant < XrefTestCase

  def setup
    super

    @const = @c1.constants.first
  end

  def test_documented_eh
    top_level = @store.add_file 'file.rb'

    const = RDoc::Constant.new 'CONST', nil, nil
    top_level.add_constant const

    refute const.documented?

    const.comment = comment 'comment'

    assert const.documented?
  end

  def test_documented_eh_alias
    top_level = @store.add_file 'file.rb'

    const = RDoc::Constant.new 'CONST', nil, nil
    top_level.add_constant const

    refute const.documented?

    const.is_alias_for = 'C1'

    refute const.documented?

    @c1.add_comment comment('comment'), @top_level

    assert const.documented?
  end

  def test_full_name
    assert_equal 'C1::CONST', @const.full_name
  end

  def test_is_alias_for
    top_level = @store.add_file 'file.rb'

    c = RDoc::Constant.new 'CONST', nil, 'comment'
    top_level.add_constant c

    assert_nil c.is_alias_for

    c.is_alias_for = 'C1'

    assert_equal @c1, c.is_alias_for

    c.is_alias_for = 'unknown'

    assert_equal 'unknown', c.is_alias_for
  end

  def test_marshal_dump
    top_level = @store.add_file 'file.rb'

    c = RDoc::Constant.new 'CONST', nil, 'this is a comment'
    c.record_location top_level

    aliased = top_level.add_class RDoc::NormalClass, 'Aliased'
    c.is_alias_for = aliased

    cm = top_level.add_class RDoc::NormalClass, 'Klass'
    cm.add_constant c

    section = cm.sections.first

    loaded = Marshal.load Marshal.dump c
    loaded.store = @store

    comment = doc(para('this is a comment'))

    assert_equal c, loaded

    assert_equal aliased,        loaded.is_alias_for
    assert_equal comment,        loaded.comment
    assert_equal top_level,      loaded.file
    assert_equal 'Klass::CONST', loaded.full_name
    assert_equal 'CONST',        loaded.name
    assert_nil                   loaded.visibility
    assert_equal cm,             loaded.parent
    assert_equal section,        loaded.section
  end

  def test_marshal_load
    top_level = @store.add_file 'file.rb'

    c = RDoc::Constant.new 'CONST', nil, 'this is a comment'
    c.record_location top_level

    cm = top_level.add_class RDoc::NormalClass, 'Klass'
    cm.add_constant c

    section = cm.sections.first

    loaded = Marshal.load Marshal.dump c
    loaded.store = @store

    comment = doc(para('this is a comment'))

    assert_equal c, loaded

    assert_nil                   loaded.is_alias_for
    assert_equal comment,        loaded.comment
    assert_equal top_level,      loaded.file
    assert_equal 'Klass::CONST', loaded.full_name
    assert_equal 'CONST',        loaded.name
    assert_nil                   loaded.visibility
    assert_equal cm,             loaded.parent
    assert_equal section,        loaded.section

    assert loaded.display?
  end

  def test_marshal_load_version_0
    top_level = @store.add_file 'file.rb'

    aliased = top_level.add_class RDoc::NormalClass, 'Aliased'
    cm      = top_level.add_class RDoc::NormalClass, 'Klass'
    section = cm.sections.first

    loaded = Marshal.load "\x04\bU:\x13RDoc::Constant[\x0Fi\x00I" +
                          "\"\nCONST\x06:\x06ETI\"\x11Klass::CONST\x06" +
                          ";\x06T0I\"\fAliased\x06;\x06To" +
                          ":\eRDoc::Markup::Document\a:\v@parts[\x06o" +
                          ":\x1CRDoc::Markup::Paragraph\x06;\b[\x06I" +
                          "\"\x16this is a comment\x06;\x06T:\n@file0I" +
                          "\"\ffile.rb\x06;\x06TI\"\nKlass\x06" +
                          ";\x06Tc\x16RDoc::NormalClass0"

    loaded.store = @store

    comment = doc(para('this is a comment'))

    assert_equal aliased,        loaded.is_alias_for
    assert_equal comment,        loaded.comment
    assert_equal top_level,      loaded.file
    assert_equal 'Klass::CONST', loaded.full_name
    assert_equal 'CONST',        loaded.name
    assert_nil                   loaded.visibility
    assert_equal cm,             loaded.parent
    assert_equal section,        loaded.section

    assert loaded.display?
  end

  def test_marshal_round_trip
    top_level = @store.add_file 'file.rb'

    c = RDoc::Constant.new 'CONST', nil, 'this is a comment'
    c.record_location top_level
    c.is_alias_for = 'Unknown'

    cm = top_level.add_class RDoc::NormalClass, 'Klass'
    cm.add_constant c

    section = cm.sections.first

    loaded = Marshal.load Marshal.dump c
    loaded.store = @store

    reloaded = Marshal.load Marshal.dump loaded
    reloaded.store = @store

    assert_equal section,   reloaded.section
    assert_equal 'Unknown', reloaded.is_alias_for
  end

  def test_path
    assert_equal 'C1.html#CONST', @const.path
  end

end