1# coding: US-ASCII
2
3require File.expand_path '../xref_test_case', __FILE__
4
5class TestRDocCodeObject < XrefTestCase
6
7  def setup
8    super
9
10    @co = RDoc::CodeObject.new
11  end
12
13  def test_initialize
14    assert @co.document_self, 'document_self'
15    assert @co.document_children, 'document_children'
16    refute @co.force_documentation, 'force_documentation'
17    refute @co.done_documenting, 'done_documenting'
18    refute @co.received_nodoc, 'received_nodoc'
19    assert_equal '', @co.comment, 'comment is empty'
20  end
21
22  def test_comment_equals
23    @co.comment = ''
24
25    assert_equal '', @co.comment
26
27    @co.comment = 'I am a comment'
28
29    assert_equal 'I am a comment', @co.comment
30  end
31
32  def test_comment_equals_comment
33    @co.comment = comment ''
34
35    assert_equal '', @co.comment.text
36
37    @co.comment = comment 'I am a comment'
38
39    assert_equal 'I am a comment', @co.comment.text
40  end
41
42  def test_comment_equals_document
43    doc = RDoc::Markup::Document.new
44    @co.comment = doc
45
46    @co.comment = ''
47
48    assert_equal doc, @co.comment
49  end
50
51  def test_comment_equals_encoding
52    skip "Encoding not implemented" unless Object.const_defined? :Encoding
53
54    refute_equal Encoding::UTF_8, ''.encoding, 'Encoding sanity check'
55
56    input = 'text'
57    input.force_encoding Encoding::UTF_8
58
59    @co.comment = input
60
61    assert_equal 'text', @co.comment
62    assert_equal Encoding::UTF_8, @co.comment.encoding
63  end
64
65  def test_comment_equals_encoding_blank
66    skip "Encoding not implemented" unless Object.const_defined? :Encoding
67
68    refute_equal Encoding::UTF_8, ''.encoding, 'Encoding sanity check'
69
70    input = ''
71    input.force_encoding Encoding::UTF_8
72
73    @co.comment = input
74
75    assert_equal '', @co.comment
76    assert_equal Encoding::UTF_8, @co.comment.encoding
77  end
78
79  def test_display_eh_document_self
80    assert @co.display?
81
82    @co.document_self = false
83
84    refute @co.display?
85  end
86
87  def test_display_eh_ignore
88    assert @co.display?
89
90    @co.ignore
91
92    refute @co.display?
93
94    @co.stop_doc
95
96    refute @co.display?
97
98    @co.done_documenting = false
99
100    refute @co.display?
101  end
102
103  def test_document_children_equals
104    @co.document_children = false
105    refute @co.document_children
106
107    # TODO this is not true anymore:
108    # test all the nodoc stuff etc...
109    #@c2.document_children = false
110    #assert_empty @c2.classes
111  end
112
113  def test_document_self_equals
114    @co.document_self = false
115    refute @co.document_self
116
117    # TODO this is not true anymore:
118    # test all the nodoc stuff etc...
119    #@c1.document_self = false
120    #assert_empty @c1.method_list
121  end
122
123  def test_documented_eh
124    refute @co.documented?
125
126    @co.comment = 'hi'
127
128    assert @co.documented?
129
130    @co.comment.replace ''
131
132    refute @co.documented?
133
134    @co.document_self = nil # notify :nodoc:
135
136    assert @co.documented?
137  end
138
139  def test_done_documenting
140    # once done_documenting is set, other properties refuse to go to "true"
141    @co.done_documenting = true
142
143    @co.document_self = true
144    refute @co.document_self
145
146    @co.document_children = true
147    refute @co.document_children
148
149    @co.force_documentation = true
150    refute @co.force_documentation
151
152    @co.start_doc
153    refute @co.document_self
154    refute @co.document_children
155
156    # turning done_documenting on
157    # resets others to true
158
159    @co.done_documenting = false
160    assert @co.document_self
161    assert @co.document_children
162  end
163
164  def test_each_parent
165    parents = []
166
167    @parent_m.each_parent do |code_object|
168      parents << code_object
169    end
170
171    assert_equal [@parent, @xref_data], parents
172  end
173
174  def test_file_name
175    assert_equal nil, @co.file_name
176
177    @co.record_location @store.add_file 'lib/file.rb'
178
179    assert_equal 'lib/file.rb', @co.file_name
180  end
181
182  def test_full_name_equals
183    @co.full_name = 'hi'
184
185    assert_equal 'hi', @co.instance_variable_get(:@full_name)
186
187    @co.full_name = nil
188
189    assert_nil @co.instance_variable_get(:@full_name)
190  end
191
192  def test_ignore
193    @co.ignore
194
195    refute @co.document_self
196    refute @co.document_children
197    assert @co.ignored?
198  end
199
200  def test_ignore_eh
201    refute @co.ignored?
202
203    @co.ignore
204
205    assert @co.ignored?
206  end
207
208  def test_line
209    @c1_m.line = 5
210
211    assert_equal 5, @c1_m.line
212  end
213
214  def test_metadata
215    assert_empty @co.metadata
216
217    @co.metadata['markup'] = 'not_rdoc'
218
219    expected = { 'markup' => 'not_rdoc' }
220
221    assert_equal expected, @co.metadata
222
223    assert_equal 'not_rdoc', @co.metadata['markup']
224  end
225
226  def test_offset
227    @c1_m.offset = 5
228
229    assert_equal 5, @c1_m.offset
230  end
231
232  def test_parent_file_name
233    assert_equal '(unknown)', @co.parent_file_name
234    assert_equal 'xref_data.rb', @c1.parent_file_name
235  end
236
237  def test_parent_name
238    assert_equal '(unknown)', @co.parent_name
239    assert_equal 'xref_data.rb', @c1.parent_name
240    assert_equal 'C2', @c2_c3.parent_name
241  end
242
243  def test_received_ndoc
244    @co.document_self = false
245    refute @co.received_nodoc
246
247    @co.document_self = nil
248    assert @co.received_nodoc
249
250    @co.document_self = true
251  end
252
253  def test_record_location
254    @co.record_location @xref_data
255
256    assert_equal 'xref_data.rb', @co.file.relative_name
257  end
258
259  def test_record_location_ignored
260    @co.ignore
261    @co.record_location @xref_data
262
263    refute @co.ignored?
264  end
265
266  def test_section
267    parent = RDoc::Context.new
268    section = parent.sections.first
269
270    @co.parent = parent
271    @co.instance_variable_set :@section, section
272
273    assert_equal section, @co.section
274
275    @co.instance_variable_set :@section, nil
276    @co.instance_variable_set :@section_title, nil
277
278    assert_equal section, @co.section
279
280    @co.instance_variable_set :@section, nil
281    @co.instance_variable_set :@section_title, 'new title'
282
283    assert_equal 'new title', @co.section.title
284  end
285
286  def test_start_doc
287    @co.document_self = false
288    @co.document_children = false
289
290    @co.start_doc
291
292    assert @co.document_self
293    assert @co.document_children
294  end
295
296  def test_start_doc_ignored
297    @co.ignore
298
299    @co.start_doc
300
301    assert @co.document_self
302    assert @co.document_children
303    refute @co.ignored?
304  end
305
306  def test_stop_doc
307    @co.document_self = true
308    @co.document_children = true
309
310    @co.stop_doc
311
312    refute @co.document_self
313    refute @co.document_children
314  end
315
316end
317
318