summaryrefslogtreecommitdiff
path: root/test/rdoc/test_rdoc_top_level.rb
blob: f3ee6a4784fa9783a1f3b3c1c049bc8d847d1e18 (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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
require File.expand_path '../xref_test_case', __FILE__

class TestRDocTopLevel < XrefTestCase

  def setup
    super

    @top_level = @store.add_file 'path/top_level.rb'
    @top_level.parser = RDoc::Parser::Ruby
  end

  def test_initialize
    t = RDoc::TopLevel.new 'path/file.rb'

    assert_equal 'path/file.rb', t.absolute_name
    assert_equal 'path/file.rb', t.relative_name
  end

  def test_initialize_relative
    t = RDoc::TopLevel.new 'path/file.rb', 'file.rb'

    assert_equal 'path/file.rb', t.absolute_name
    assert_equal 'file.rb',      t.relative_name
  end

  def test_add_alias
    a = RDoc::Alias.new nil, 'old', 'new', nil
    @top_level.add_alias a

    object = @store.find_class_named 'Object'
    expected = { '#old' => [a] }
    assert_equal expected, object.unmatched_alias_lists
    assert_includes object.in_files, @top_level
  end

  def test_add_alias_nodoc
    @top_level.document_self = false

    a = RDoc::Alias.new nil, 'old', 'new', nil
    @top_level.add_alias a

    object = @store.find_class_named('Object')
    assert_empty object.unmatched_alias_lists
    assert_includes object.in_files, @top_level
  end

  def test_add_constant
    const = RDoc::Constant.new 'C', nil, nil
    @top_level.add_constant const

    object = @store.find_class_named 'Object'
    assert_equal [const], object.constants
    assert_includes object.in_files, @top_level
  end

  def test_add_constant_nodoc
    @top_level.document_self = false

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

    object = @store.find_class_named 'Object'
    assert_empty object.constants
    assert_includes object.in_files, @top_level
  end

  def test_add_include
    include = RDoc::Include.new 'C', nil
    @top_level.add_include include

    object = @store.find_class_named 'Object'
    assert_equal [include], object.includes
    assert_includes object.in_files, @top_level
  end

  def test_add_include_nodoc
    @top_level.document_self = false

    include = RDoc::Include.new 'C', nil
    @top_level.add_include include

    object = @store.find_class_named('Object')
    assert_empty object.includes
    assert_includes object.in_files, @top_level
  end

  def test_add_method
    method = RDoc::AnyMethod.new nil, 'm'
    @top_level.add_method method

    object = @store.find_class_named 'Object'
    assert_equal [method], object.method_list
    assert_includes object.in_files, @top_level
  end

  def test_add_method_stopdoc
    @top_level.document_self = false

    method = RDoc::AnyMethod.new nil, 'm'
    @top_level.add_method method

    object = @store.find_class_named('Object')
    assert_empty object.method_list
    assert_includes object.in_files, @top_level
  end

  def test_base_name
    assert_equal 'top_level.rb', @top_level.base_name
  end

  def test_display_eh
    refute @top_level.display?

    page = @store.add_file 'README.txt'
    page.parser = RDoc::Parser::Simple

    assert page.display?
  end

  def test_eql_eh
    top_level2 = @store.add_file 'path/top_level.rb'
    other_level = @store.add_file 'path/other_level.rb'

    assert_operator @top_level, :eql?, top_level2

    refute_operator other_level, :eql?, @top_level
  end

  def test_equals2
    top_level2 = @store.add_file 'path/top_level.rb'
    other_level = @store.add_file 'path/other_level.rb'

    assert_equal @top_level, top_level2

    refute_equal other_level, @top_level
  end

  def test_find_class_or_module
    assert_equal @c1,    @xref_data.find_class_or_module('C1')
    assert_equal @c2_c3, @xref_data.find_class_or_module('C2::C3')
    assert_equal @c4,    @xref_data.find_class_or_module('C4')
    assert_equal @m1_m2, @xref_data.find_class_or_module('M1::M2')
  end

  def test_full_name
    assert_equal 'path/top_level.rb', @top_level.full_name
  end

  def test_hash
    tl2 = @store.add_file 'path/top_level.rb'
    tl3 = @store.add_file 'other/top_level.rb'

    assert_equal @top_level.hash, tl2.hash
    refute_equal @top_level.hash, tl3.hash
  end

  def test_http_url
    assert_equal 'prefix/path/top_level_rb.html', @top_level.http_url('prefix')
  end

  def test_last_modified
    assert_equal nil, @top_level.last_modified
    stat = Object.new
    def stat.mtime() 0 end
    @top_level.file_stat = stat
    assert_equal 0, @top_level.last_modified
  end

  def test_marshal_dump
    page = @store.add_file 'README.txt'
    page.parser = RDoc::Parser::Simple
    page.comment = RDoc::Comment.new 'This is a page', page

    loaded = Marshal.load Marshal.dump page

    comment = RDoc::Markup::Document.new(
                RDoc::Markup::Paragraph.new('This is a page'))
    comment.file = loaded

    assert_equal page, loaded

    assert_equal 'README.txt', loaded.absolute_name
    assert_equal 'README.txt', loaded.relative_name

    assert_equal RDoc::Parser::Simple, loaded.parser

    assert_equal comment, loaded.comment
  end

  def test_marshal_load_version_0
    loaded = Marshal.load "\x04\bU:\x13RDoc::TopLevel" +
                          "[\ti\x00I\"\x0FREADME.txt\x06:\x06EF" +
                          "c\x19RDoc::Parser::Simple" +
                          "o:\eRDoc::Markup::Document\a:\v@parts" +
                          "[\x06o:\x1CRDoc::Markup::Paragraph\x06;\b" +
                          "[\x06I\"\x13This is a page\x06;\x06F:\n@file@\a"

    comment = RDoc::Markup::Document.new(
                RDoc::Markup::Paragraph.new('This is a page'))
    comment.file = loaded

    assert_equal 'README.txt', loaded.absolute_name
    assert_equal 'README.txt', loaded.relative_name

    assert_equal RDoc::Parser::Simple, loaded.parser

    assert_equal comment, loaded.comment

    assert loaded.display?
  end

  def test_name
    assert_equal 'top_level.rb', @top_level.name
  end

  def test_page_name
    assert_equal 'top_level', @top_level.page_name

    tl = @store.add_file 'README.ja'

    assert_equal 'README.ja', tl.page_name

    tl = @store.add_file 'Rakefile'

    assert_equal 'Rakefile', tl.page_name
  end

  def test_page_name_trim_extension
    tl = @store.add_file 'README.ja.rdoc'

    assert_equal 'README.ja', tl.page_name

    tl = @store.add_file 'README.ja.md'

    assert_equal 'README.ja', tl.page_name

    tl = @store.add_file 'README.txt'

    assert_equal 'README', tl.page_name
  end

  def test_search_record
    assert_nil @xref_data.search_record
  end

  def test_search_record_page
    page = @store.add_file 'README.txt'
    page.parser = RDoc::Parser::Simple
    page.comment = 'This is a comment.'

    expected = [
      'README',
      '',
      'README',
      '',
      'README_txt.html',
      '',
      "<p>This is a comment.\n",
    ]

    assert_equal expected, page.search_record
  end

  def test_text_eh
    refute @xref_data.text?

    rd = @store.add_file 'rd_format.rd'
    rd.parser = RDoc::Parser::RD

    assert rd.text?

    simple = @store.add_file 'simple.txt'
    simple.parser = RDoc::Parser::Simple

    assert simple.text?
  end

  def test_text_eh_no_parser
    refute @xref_data.text?

    rd = @store.add_file 'rd_format.rd'

    refute rd.text?
  end

end