summaryrefslogtreecommitdiff
path: root/jni/ruby/test/rdoc/test_rdoc_code_object.rb
blob: 2fb6ac23a524dbacce191c22c7e960f8cd796123 (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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
# coding: US-ASCII

require File.expand_path '../xref_test_case', __FILE__

class TestRDocCodeObject < XrefTestCase

  def setup
    super

    @co = RDoc::CodeObject.new
  end

  def test_initialize
    assert @co.document_self, 'document_self'
    assert @co.document_children, 'document_children'
    refute @co.force_documentation, 'force_documentation'
    refute @co.done_documenting, 'done_documenting'
    refute @co.received_nodoc, 'received_nodoc'
    assert_equal '', @co.comment, 'comment is empty'
  end

  def test_comment_equals
    @co.comment = ''

    assert_equal '', @co.comment

    @co.comment = 'I am a comment'

    assert_equal 'I am a comment', @co.comment
  end

  def test_comment_equals_comment
    @co.comment = comment ''

    assert_equal '', @co.comment.text

    @co.comment = comment 'I am a comment'

    assert_equal 'I am a comment', @co.comment.text
  end

  def test_comment_equals_document
    doc = RDoc::Markup::Document.new
    @co.comment = doc

    @co.comment = ''

    assert_equal doc, @co.comment
  end

  def test_comment_equals_encoding
    skip "Encoding not implemented" unless Object.const_defined? :Encoding

    refute_equal Encoding::UTF_8, ''.encoding, 'Encoding sanity check'

    input = 'text'
    input.force_encoding Encoding::UTF_8

    @co.comment = input

    assert_equal 'text', @co.comment
    assert_equal Encoding::UTF_8, @co.comment.encoding
  end

  def test_comment_equals_encoding_blank
    skip "Encoding not implemented" unless Object.const_defined? :Encoding

    refute_equal Encoding::UTF_8, ''.encoding, 'Encoding sanity check'

    input = ''
    input.force_encoding Encoding::UTF_8

    @co.comment = input

    assert_equal '', @co.comment
    assert_equal Encoding::UTF_8, @co.comment.encoding
  end

  def test_display_eh_document_self
    assert @co.display?

    @co.document_self = false

    refute @co.display?
  end

  def test_display_eh_ignore
    assert @co.display?

    @co.ignore

    refute @co.display?

    @co.stop_doc

    refute @co.display?

    @co.done_documenting = false

    refute @co.display?
  end

  def test_display_eh_suppress
    assert @co.display?

    @co.suppress

    refute @co.display?

    @co.comment = comment('hi')

    refute @co.display?

    @co.done_documenting = false

    assert @co.display?

    @co.ignore
    @co.done_documenting = false

    refute @co.display?
  end

  def test_document_children_equals
    @co.document_children = false

    refute @co.document_children

    @store.rdoc.options.visibility = :nodoc

    @co.store = @store

    assert @co.document_children

    @co.document_children = false

    assert @co.document_children
  end

  def test_document_self_equals
    @co.document_self = false
    refute @co.document_self

    @store.rdoc.options.visibility = :nodoc

    @co.store = @store

    assert @co.document_self

    @co.document_self = false

    assert @co.document_self
  end

  def test_documented_eh
    refute @co.documented?

    @co.comment = 'hi'

    assert @co.documented?

    @co.comment.replace ''

    refute @co.documented?

    @co.document_self = nil # notify :nodoc:

    assert @co.documented?
  end

  def test_done_documenting
    # once done_documenting is set, other properties refuse to go to "true"
    @co.done_documenting = true

    @co.document_self = true
    refute @co.document_self

    @co.document_children = true
    refute @co.document_children

    @co.force_documentation = true
    refute @co.force_documentation

    @co.start_doc
    refute @co.document_self
    refute @co.document_children

    # turning done_documenting on
    # resets others to true

    @co.done_documenting = false
    assert @co.document_self
    assert @co.document_children

    @co.done_documenting = true

    @store.rdoc.options.visibility = :nodoc

    @co.store = @store

    refute @co.done_documenting

    @co.done_documenting = true

    refute @co.done_documenting
  end

  def test_each_parent
    parents = []

    @parent_m.each_parent do |code_object|
      parents << code_object
    end

    assert_equal [@parent, @xref_data], parents
  end

  def test_file_name
    assert_equal nil, @co.file_name

    @co.record_location @store.add_file 'lib/file.rb'

    assert_equal 'lib/file.rb', @co.file_name
  end

  def test_full_name_equals
    @co.full_name = 'hi'

    assert_equal 'hi', @co.instance_variable_get(:@full_name)

    @co.full_name = nil

    assert_nil @co.instance_variable_get(:@full_name)
  end

  def test_ignore
    @co.ignore

    refute @co.document_self
    refute @co.document_children
    assert @co.ignored?

    @store.rdoc.options.visibility = :nodoc

    @co.store = @store

    assert @co.document_self
    assert @co.document_children
    refute @co.ignored?

    @co.ignore

    refute @co.ignored?
  end

  def test_ignore_eh
    refute @co.ignored?

    @co.ignore

    assert @co.ignored?
  end

  def test_line
    @c1_m.line = 5

    assert_equal 5, @c1_m.line
  end

  def test_metadata
    assert_empty @co.metadata

    @co.metadata['markup'] = 'not_rdoc'

    expected = { 'markup' => 'not_rdoc' }

    assert_equal expected, @co.metadata

    assert_equal 'not_rdoc', @co.metadata['markup']
  end

  def test_offset
    @c1_m.offset = 5

    assert_equal 5, @c1_m.offset
  end

  def test_options
    assert_kind_of RDoc::Options, @co.options

    @co.store = @store

    assert_same @options, @co.options
  end

  def test_parent_file_name
    assert_equal '(unknown)', @co.parent_file_name
    assert_equal 'xref_data.rb', @c1.parent_file_name
  end

  def test_parent_name
    assert_equal '(unknown)', @co.parent_name
    assert_equal 'xref_data.rb', @c1.parent_name
    assert_equal 'C2', @c2_c3.parent_name
  end

  def test_received_ndoc
    @co.document_self = false
    refute @co.received_nodoc

    @co.document_self = nil
    assert @co.received_nodoc

    @co.document_self = true
  end

  def test_record_location
    @co.record_location @xref_data

    assert_equal 'xref_data.rb', @co.file.relative_name
  end

  def test_record_location_ignored
    @co.ignore
    @co.record_location @xref_data

    refute @co.ignored?
  end

  def test_record_location_suppressed
    @co.suppress
    @co.record_location @xref_data

    refute @co.suppressed?
  end

  def test_section
    parent = RDoc::Context.new
    section = parent.sections.first

    @co.parent = parent
    @co.instance_variable_set :@section, section

    assert_equal section, @co.section

    @co.instance_variable_set :@section, nil
    @co.instance_variable_set :@section_title, nil

    assert_equal section, @co.section

    @co.instance_variable_set :@section, nil
    @co.instance_variable_set :@section_title, 'new title'

    assert_equal 'new title', @co.section.title
  end

  def test_start_doc
    @co.document_self = false
    @co.document_children = false

    @co.start_doc

    assert @co.document_self
    assert @co.document_children
  end

  def test_start_doc_ignored
    @co.ignore

    @co.start_doc

    assert @co.document_self
    assert @co.document_children
    refute @co.ignored?
  end

  def test_start_doc_suppressed
    @co.suppress

    @co.start_doc

    assert @co.document_self
    assert @co.document_children
    refute @co.suppressed?
  end

  def test_store_equals
    @co.document_self = false

    @co.store = @store

    refute @co.document_self

    @store.rdoc.options.visibility = :nodoc

    @co.store = @store

    assert @co.document_self
  end

  def test_stop_doc
    @co.document_self = true
    @co.document_children = true

    @co.stop_doc

    refute @co.document_self
    refute @co.document_children

    @store.rdoc.options.visibility = :nodoc

    @co.store = @store

    assert @co.document_self
    assert @co.document_children

    @co.stop_doc

    assert @co.document_self
    assert @co.document_children
  end

  def test_suppress
    @co.suppress

    refute @co.document_self
    refute @co.document_children
    assert @co.suppressed?

    @store.rdoc.options.visibility = :nodoc

    @co.store = @store

    refute @co.suppressed?

    @co.suppress

    refute @co.suppressed?
  end

  def test_suppress_eh
    refute @co.suppressed?

    @co.suppress

    assert @co.suppressed?
  end

end