rdoc 3.8 → 3.9

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rdoc might be problematic. Click here for more details.

@@ -38,6 +38,7 @@ class TestRDocGeneratorDarkfish < MiniTest::Unit::TestCase
38
38
 
39
39
  @top_level = RDoc::TopLevel.new 'file.rb'
40
40
  @klass = @top_level.add_class RDoc::NormalClass, 'Object'
41
+
41
42
  @meth = RDoc::AnyMethod.new nil, 'method'
42
43
  @meth_bang = RDoc::AnyMethod.new nil, 'method!'
43
44
  @attr = RDoc::Attr.new nil, 'attr', 'RW', ''
@@ -45,6 +46,9 @@ class TestRDocGeneratorDarkfish < MiniTest::Unit::TestCase
45
46
  @klass.add_method @meth
46
47
  @klass.add_method @meth_bang
47
48
  @klass.add_attribute @attr
49
+
50
+ @ignored = @top_level.add_class RDoc::NormalClass, 'Ignored'
51
+ @ignored.ignore
48
52
  end
49
53
 
50
54
  def teardown
@@ -83,6 +87,8 @@ class TestRDocGeneratorDarkfish < MiniTest::Unit::TestCase
83
87
  File.read('Object.html'))
84
88
  assert_match(/<meta content="text\/html; charset=#{encoding}"/,
85
89
  File.read('file_rb.html'))
90
+
91
+ refute_match(/Ignored/, File.read('index.html'))
86
92
  end
87
93
 
88
94
  def test_generate_dry_run
@@ -124,6 +124,24 @@ class TestRDocMarkupDocument < MiniTest::Unit::TestCase
124
124
  assert_equal expected, result
125
125
  end
126
126
 
127
+ def test_merge_empty
128
+ original = @RM::Document.new
129
+ root = @RM::Document.new original
130
+
131
+ replace = @RM::Document.new @RM::Paragraph.new 'replace'
132
+ replace.file = 'file.rb'
133
+
134
+ other = @RM::Document.new replace
135
+
136
+ result = root.merge other
137
+
138
+ inner = @RM::Document.new @RM::Paragraph.new 'replace'
139
+ inner.file = 'file.rb'
140
+ expected = @RM::Document.new inner
141
+
142
+ assert_equal expected, result
143
+ end
144
+
127
145
  def test_push
128
146
  @d.push @RM::BlankLine.new, @RM::BlankLine.new
129
147
 
@@ -1366,6 +1366,44 @@ Example heading:
1366
1366
  assert_equal expected, @RMP.tokenize(str)
1367
1367
  end
1368
1368
 
1369
+ def test_tokenize_verbatim_rule
1370
+ str = <<-STR
1371
+ Verbatim section here that is double-underlined
1372
+ ===============================================
1373
+ STR
1374
+
1375
+ expected = [
1376
+ [:TEXT, 'Verbatim section here that is double-underlined', 2, 0],
1377
+ [:NEWLINE, "\n", 49, 0],
1378
+ [:HEADER, 47, 2, 1],
1379
+ [:NEWLINE, "\n", 49, 1],
1380
+ ]
1381
+
1382
+ assert_equal expected, @RMP.tokenize(str)
1383
+ end
1384
+
1385
+ def test_tokenize_verbatim_rule_fancy
1386
+ str = <<-STR
1387
+ A
1388
+ b
1389
+ ===============================================
1390
+ c
1391
+ STR
1392
+
1393
+ expected = [
1394
+ [:TEXT, 'A', 2, 0],
1395
+ [:NEWLINE, "\n", 3, 0],
1396
+ [:TEXT, 'b', 4, 1],
1397
+ [:NEWLINE, "\n", 5, 1],
1398
+ [:HEADER, 47, 2, 2],
1399
+ [:NEWLINE, "\n", 49, 2],
1400
+ [:TEXT, 'c', 4, 3],
1401
+ [:NEWLINE, "\n", 5, 3],
1402
+ ]
1403
+
1404
+ assert_equal expected, @RMP.tokenize(str)
1405
+ end
1406
+
1369
1407
  # HACK move to Verbatim test case
1370
1408
  def test_verbatim_normalize
1371
1409
  v = @RM::Verbatim.new "foo\n", "\n", "\n", "bar\n"
@@ -5,6 +5,7 @@ require 'rubygems'
5
5
  require 'minitest/autorun'
6
6
  require 'rdoc/markup/pre_process'
7
7
  require 'rdoc/code_objects'
8
+ require 'rdoc/options'
8
9
 
9
10
  class TestRDocMarkupPreProcess < MiniTest::Unit::TestCase
10
11
 
@@ -19,6 +20,8 @@ class TestRDocMarkupPreProcess < MiniTest::Unit::TestCase
19
20
  end
20
21
 
21
22
  def teardown
23
+ RDoc::Markup::PreProcess.registered.clear
24
+
22
25
  @tempfile.close
23
26
  end
24
27
 
@@ -73,6 +76,14 @@ contents of a string.
73
76
  end
74
77
 
75
78
  def test_handle
79
+ text = "# :main: M\n"
80
+ out = @pp.handle text
81
+
82
+ assert_same out, text
83
+ assert_equal "#\n", text
84
+ end
85
+
86
+ def test_handle_unregistered
76
87
  text = "# :x: y\n"
77
88
  out = @pp.handle text
78
89
 
@@ -80,142 +91,329 @@ contents of a string.
80
91
  assert_equal "# :x: y\n", text
81
92
  end
82
93
 
83
- def test_handle_block
84
- text = "# :x: y\n"
94
+ def test_handle_directive_blankline
95
+ result = @pp.handle_directive '#', 'arg', 'a, b'
96
+
97
+ assert_equal "#\n", result
98
+ end
99
+
100
+ def test_handle_directive_downcase
101
+ method = RDoc::AnyMethod.new nil, 'm'
102
+
103
+ @pp.handle_directive '', 'ARG', 'a, b', method
104
+
105
+ assert_equal 'a, b', method.params
106
+ end
107
+
108
+ def test_handle_directive_arg
109
+ method = RDoc::AnyMethod.new nil, 'm'
110
+
111
+ @pp.handle_directive '', 'arg', 'a, b', method
112
+
113
+ assert_equal 'a, b', method.params
114
+ end
115
+
116
+ def test_handle_directive_arg_no_context
117
+ result = @pp.handle_directive '', 'arg', 'a, b', nil
118
+
119
+ assert_equal "\n", result
120
+ end
121
+
122
+ def test_handle_directive_args
123
+ method = RDoc::AnyMethod.new nil, 'm'
85
124
 
86
- @pp.handle text do |directive, param|
125
+ @pp.handle_directive '', 'args', 'a, b', method
126
+
127
+ assert_equal 'a, b', method.params
128
+ end
129
+
130
+ def test_handle_directive_block
131
+ result = @pp.handle_directive '', 'x', 'y' do |directive, param|
132
+ ''
133
+ end
134
+
135
+ assert_empty result
136
+ end
137
+
138
+ def test_handle_directive_block_false
139
+ result = @pp.handle_directive '', 'x', 'y' do |directive, param|
87
140
  false
88
141
  end
89
142
 
90
- assert_equal "# :x: y\n", text
143
+ assert_equal ":x: y\n", result
144
+ end
91
145
 
92
- @pp.handle text do |directive, param|
93
- ''
146
+ def test_handle_directive_block_nil
147
+ result = @pp.handle_directive '', 'x', 'y' do |directive, param|
148
+ nil
94
149
  end
95
150
 
96
- assert_equal "", text
151
+ assert_equal ":x: y\n", result
97
152
  end
98
153
 
99
- def test_handle_category
154
+ def test_handle_directive_category
100
155
  context = RDoc::Context.new
101
156
  original_section = context.current_section
102
157
 
103
- text = "# :category: other\n"
104
-
105
- @pp.handle text, context
158
+ @pp.handle_directive '', 'category', 'other', context
106
159
 
107
160
  refute_equal original_section, context.current_section
108
161
  end
109
162
 
110
- def test_handle_code_object
111
- cd = RDoc::CodeObject.new
112
- text = "# :x: y\n"
113
- @pp.handle text, cd
163
+ def test_handle_directive_doc
164
+ code_object = RDoc::CodeObject.new
165
+ code_object.document_self = false
166
+ code_object.force_documentation = false
114
167
 
115
- assert_equal "# :x: y\n", text
116
- assert_equal 'y', cd.metadata['x']
168
+ @pp.handle_directive '', 'doc', nil, code_object
169
+
170
+ assert code_object.document_self
171
+ assert code_object.force_documentation
172
+ end
117
173
 
118
- cd.metadata.clear
119
- text = "# :x:\n"
120
- @pp.handle text, cd
174
+ def test_handle_directive_doc_no_context
175
+ result = @pp.handle_directive '', 'doc', nil
121
176
 
122
- assert_equal "# :x: \n", text
123
- assert_includes cd.metadata, 'x'
177
+ assert_equal "\n", result
124
178
  end
125
179
 
126
- def test_handle_code_object_block
127
- cd = RDoc::CodeObject.new
128
- text = "# :x: y\n"
129
- @pp.handle text, cd do
130
- false
131
- end
180
+ def test_handle_directive_enddoc
181
+ code_object = RDoc::CodeObject.new
132
182
 
133
- assert_equal "# :x: y\n", text
134
- assert_empty cd.metadata
183
+ @pp.handle_directive '', 'enddoc', nil, code_object
135
184
 
136
- @pp.handle text, cd do
137
- nil
138
- end
185
+ assert code_object.done_documenting
186
+ end
139
187
 
140
- assert_equal "# :x: y\n", text
141
- assert_equal 'y', cd.metadata['x']
188
+ def test_handle_directive_include
189
+ @tempfile.write 'included'
190
+ @tempfile.flush
142
191
 
143
- cd.metadata.clear
192
+ result = @pp.handle_directive '', 'include', @file_name
144
193
 
145
- @pp.handle text, cd do
146
- ''
147
- end
194
+ assert_equal 'included', result
195
+ end
196
+
197
+ def test_handle_directive_main
198
+ @pp.options = RDoc::Options.new
199
+
200
+ @pp.handle_directive '', 'main', 'M'
201
+
202
+ assert_equal 'M', @pp.options.main_page
203
+ end
204
+
205
+ def test_handle_directive_notnew
206
+ m = RDoc::AnyMethod.new nil, 'm'
207
+
208
+ @pp.handle_directive '', 'notnew', nil, m
209
+
210
+ assert m.dont_rename_initialize
211
+ end
212
+
213
+ def test_handle_directive_not_new
214
+ m = RDoc::AnyMethod.new nil, 'm'
215
+
216
+ @pp.handle_directive '', 'not_new', nil, m
217
+
218
+ assert m.dont_rename_initialize
219
+ end
220
+
221
+ def test_handle_directive_not_dash_new
222
+ m = RDoc::AnyMethod.new nil, 'm'
223
+
224
+ @pp.handle_directive '', 'not-new', nil, m
225
+
226
+ assert m.dont_rename_initialize
227
+ end
228
+
229
+ def test_handle_directive_nodoc
230
+ code_object = RDoc::CodeObject.new
231
+ code_object.document_self = true
232
+ code_object.document_children = true
148
233
 
149
- assert_equal '', text
150
- assert_empty cd.metadata
234
+ @pp.handle_directive '', 'nodoc', nil, code_object
235
+
236
+ refute code_object.document_self
237
+ assert code_object.document_children
238
+ end
239
+
240
+ def test_handle_directive_nodoc_all
241
+ code_object = RDoc::CodeObject.new
242
+ code_object.document_self = true
243
+ code_object.document_children = true
244
+
245
+ @pp.handle_directive '', 'nodoc', 'all', code_object
246
+
247
+ refute code_object.document_self
248
+ refute code_object.document_children
151
249
  end
152
250
 
153
- def test_handle_registered
251
+ def test_handle_directive_nodoc_no_context
252
+ result = @pp.handle_directive '', 'nodoc', nil
253
+
254
+ assert_equal "\n", result
255
+ end
256
+
257
+ def test_handle_directive_registered
154
258
  RDoc::Markup::PreProcess.register 'x'
155
- text = "# :x: y\n"
156
- @pp.handle text
157
259
 
158
- assert_equal '', text
260
+ result = @pp.handle_directive '', 'x', 'y'
159
261
 
160
- text = "# :x: y\n"
262
+ assert_nil result
161
263
 
162
- @pp.handle text do |directive, param|
264
+ result = @pp.handle_directive '', 'x', 'y' do |directive, param|
163
265
  false
164
266
  end
165
267
 
166
- assert_equal "# :x: y\n", text
167
-
168
- text = "# :x: y\n"
268
+ assert_equal ":x: y\n", result
169
269
 
170
- @pp.handle text do |directive, param|
270
+ result = @pp.handle_directive '', 'x', 'y' do |directive, param|
171
271
  ''
172
272
  end
173
273
 
174
- assert_equal "", text
274
+ assert_equal '', result
175
275
  end
176
276
 
177
- def test_handle_registered_block
277
+ def test_handle_directive_registered_block
178
278
  called = nil
279
+
179
280
  RDoc::Markup::PreProcess.register 'x' do |directive, param|
180
281
  called = [directive, param]
181
282
  'blah'
182
283
  end
183
284
 
184
- text = "# :x: y\n"
185
- @pp.handle text
285
+ result = @pp.handle_directive '', 'x', 'y'
186
286
 
187
- assert_equal 'blah', text
287
+ assert_equal 'blah', result
188
288
  assert_equal %w[x y], called
189
289
  end
190
290
 
191
- def test_handle_registered_code_object
291
+ def test_handle_directive_registered_code_object
192
292
  RDoc::Markup::PreProcess.register 'x'
193
- cd = RDoc::CodeObject.new
293
+ code_object = RDoc::CodeObject.new
194
294
 
195
- text = "# :x: y\n"
196
- @pp.handle text, cd
295
+ @pp.handle_directive '', 'x', 'y', code_object
197
296
 
198
- assert_equal '', text
199
- assert_equal 'y', cd.metadata['x']
297
+ assert_equal 'y', code_object.metadata['x']
200
298
 
201
- cd.metadata.clear
202
- text = "# :x: y\n"
299
+ code_object.metadata.clear
203
300
 
204
- @pp.handle text do |directive, param|
301
+ result = @pp.handle_directive '', 'x', 'y' do |directive, param|
205
302
  false
206
303
  end
207
304
 
208
- assert_equal "# :x: y\n", text
209
- assert_empty cd.metadata
305
+ assert_equal ":x: y\n", result
306
+ assert_empty code_object.metadata
210
307
 
211
- text = "# :x: y\n"
308
+ result = @pp.handle_directive '', 'x', 'y' do |directive, param|
309
+ ''
310
+ end
311
+
312
+ assert_equal '', result
313
+ assert_empty code_object.metadata
314
+ end
315
+
316
+ def test_handle_directive_startdoc
317
+ code_object = RDoc::CodeObject.new
318
+ code_object.stop_doc
319
+ code_object.force_documentation = false
320
+
321
+ @pp.handle_directive '', 'startdoc', nil, code_object
322
+
323
+ assert code_object.document_self
324
+ assert code_object.document_children
325
+ assert code_object.force_documentation
326
+ end
327
+
328
+ def test_handle_directive_stopdoc
329
+ code_object = RDoc::CodeObject.new
330
+
331
+ @pp.handle_directive '', 'stopdoc', nil, code_object
332
+
333
+ refute code_object.document_self
334
+ refute code_object.document_children
335
+ end
336
+
337
+ def test_handle_directive_title
338
+ @pp.options = RDoc::Options.new
339
+
340
+ @pp.handle_directive '', 'title', 'T'
341
+
342
+ assert_equal 'T', @pp.options.title
343
+ end
344
+
345
+ def test_handle_directive_unhandled
346
+ code_object = RDoc::CodeObject.new
347
+
348
+ @pp.handle_directive '', 'x', 'y', code_object
349
+
350
+ assert_equal 'y', code_object.metadata['x']
351
+
352
+ code_object.metadata.clear
353
+
354
+ @pp.handle_directive '', 'x', '', code_object
355
+
356
+ assert_includes code_object.metadata, 'x'
357
+ end
358
+
359
+ def test_handle_directive_unhandled_block
360
+ code_object = RDoc::CodeObject.new
361
+
362
+ @pp.handle_directive '', 'x', 'y', code_object do
363
+ false
364
+ end
365
+
366
+ assert_empty code_object.metadata
367
+
368
+ @pp.handle_directive '', 'x', 'y', code_object do
369
+ nil
370
+ end
371
+
372
+ assert_equal 'y', code_object.metadata['x']
212
373
 
213
- @pp.handle text do |directive, param|
374
+ code_object.metadata.clear
375
+
376
+ @pp.handle_directive '', 'x', 'y', code_object do
214
377
  ''
215
378
  end
216
379
 
217
- assert_equal "", text
218
- assert_empty cd.metadata
380
+ assert_empty code_object.metadata
381
+ end
382
+
383
+ def test_handle_directive_yield
384
+ method = RDoc::AnyMethod.new nil, 'm'
385
+ method.params = 'index, &block'
386
+
387
+ @pp.handle_directive '', 'yield', 'item', method
388
+
389
+ assert_equal 'item', method.block_params
390
+ assert_equal 'index', method.params
391
+ end
392
+
393
+ def test_handle_directive_yield_block_param
394
+ method = RDoc::AnyMethod.new nil, 'm'
395
+ method.params = '&block'
396
+
397
+ @pp.handle_directive '', 'yield', 'item', method
398
+
399
+ assert_equal 'item', method.block_params
400
+ assert_empty method.params
401
+ end
402
+
403
+ def test_handle_directive_yield_no_context
404
+ method = RDoc::AnyMethod.new nil, 'm'
405
+
406
+ @pp.handle_directive '', 'yield', 'item', method
407
+
408
+ assert_equal 'item', method.block_params
409
+ end
410
+
411
+ def test_handle_directive_yields
412
+ method = RDoc::AnyMethod.new nil, 'm'
413
+
414
+ @pp.handle_directive '', 'yields', 'item', method
415
+
416
+ assert_equal 'item', method.block_params
219
417
  end
220
418
 
221
419
  end