rdoc 4.0.0 → 4.0.1

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.

@@ -229,6 +229,14 @@ class TestRDocCodeObject < XrefTestCase
229
229
  assert_equal 5, @c1_m.offset
230
230
  end
231
231
 
232
+ def test_options
233
+ assert_kind_of RDoc::Options, @co.options
234
+
235
+ @co.store = @store
236
+
237
+ assert_same @options, @co.options
238
+ end
239
+
232
240
  def test_parent_file_name
233
241
  assert_equal '(unknown)', @co.parent_file_name
234
242
  assert_equal 'xref_data.rb', @c1.parent_file_name
@@ -256,7 +256,7 @@ class TestRDocMarkupToHtml < RDoc::Markup::FormatterTestCase
256
256
  end
257
257
 
258
258
  def accept_paragraph_break
259
- assert_equal "\n<p>hello<br>\nworld</p>\n", @to.res.join
259
+ assert_equal "\n<p>hello<br> world</p>\n", @to.res.join
260
260
  end
261
261
 
262
262
  def accept_paragraph_i
@@ -389,6 +389,14 @@ class TestRDocMarkupToHtml < RDoc::Markup::FormatterTestCase
389
389
  assert_equal "\n<h1 id=\"label-Hello\">Hello</h1>\n", @to.res.join
390
390
  end
391
391
 
392
+ def test_accept_paragraph_newline
393
+ @to.start_accepting
394
+
395
+ @to.accept_paragraph para("hello\n", "world\n")
396
+
397
+ assert_equal "\n<p>hello world</p>\n", @to.res.join
398
+ end
399
+
392
400
  def test_accept_verbatim_parseable
393
401
  verb = @RM::Verbatim.new("class C\n", "end\n")
394
402
 
@@ -422,6 +430,24 @@ class TestRDocMarkupToHtml < RDoc::Markup::FormatterTestCase
422
430
  assert_equal expected, @to.res.join
423
431
  end
424
432
 
433
+ def test_accept_verbatim_pipe
434
+ @options.pipe = true
435
+
436
+ verb = @RM::Verbatim.new("1 + 1\n")
437
+ verb.format = :ruby
438
+
439
+ @to.start_accepting
440
+ @to.accept_verbatim verb
441
+
442
+ expected = <<-EXPECTED
443
+
444
+ <pre><code>1 + 1
445
+ </code></pre>
446
+ EXPECTED
447
+
448
+ assert_equal expected, @to.res.join
449
+ end
450
+
425
451
  def test_accept_verbatim_ruby
426
452
  verb = @RM::Verbatim.new("1 + 1\n")
427
453
  verb.format = :ruby
@@ -372,6 +372,20 @@ rdoc_include:
372
372
  assert_equal 1, out.scan(/test generator options:/).length
373
373
  end
374
374
 
375
+ def test_parse_format_for_extra_generator
376
+ RDoc::RDoc::GENERATORS['test'] = Class.new do
377
+ def self.setup_options options
378
+ op = options.option_parser
379
+
380
+ op.separator 'test generator options:'
381
+ end
382
+ end
383
+
384
+ @options.setup_generator 'test'
385
+
386
+ assert_equal @options.generator_name, 'test'
387
+ end
388
+
375
389
  def test_parse_ignore_invalid
376
390
  out, err = capture_io do
377
391
  @options.parse %w[--ignore-invalid --bogus]
@@ -409,6 +423,39 @@ rdoc_include:
409
423
  assert_empty out
410
424
  end
411
425
 
426
+ def test_parse_ignore_invalid_no_quiet
427
+ out, err = capture_io do
428
+ assert_raises SystemExit do
429
+ @options.parse %w[--quiet --no-ignore-invalid --bogus=arg --bobogus --visibility=extended]
430
+ end
431
+ end
432
+
433
+ refute_match %r%^Usage: %, err
434
+ assert_match %r%^invalid options: --bogus=arg, --bobogus, --visibility=extended%, err
435
+
436
+ assert_empty out
437
+ end
438
+
439
+ def test_ignore_needless_arg
440
+ out, err = capture_io do
441
+ @options.parse %w[--ri=foo]
442
+ end
443
+
444
+ assert_match %r%^invalid options: --ri=foo%, err
445
+
446
+ assert_empty out
447
+ end
448
+
449
+ def test_ignore_missing_arg
450
+ out, err = capture_io do
451
+ @options.parse %w[--copy-files]
452
+ end
453
+
454
+ assert_match %r%^invalid options: --copy-files%, err
455
+
456
+ assert_empty out
457
+ end
458
+
412
459
  def test_parse_main
413
460
  out, err = capture_io do
414
461
  @options.parse %w[--main MAIN]
@@ -468,6 +515,13 @@ rdoc_include:
468
515
  end
469
516
  end
470
517
 
518
+ def test_parse_ri_site
519
+ @options.parse %w[--ri-site]
520
+
521
+ assert_equal RDoc::Generator::RI, @options.generator
522
+ assert_equal RDoc::RI::Paths.site_dir, @options.op_dir
523
+ end
524
+
471
525
  def test_parse_root
472
526
  assert_equal Pathname(Dir.pwd), @options.root
473
527
 
@@ -639,5 +693,16 @@ rdoc_include:
639
693
  end
640
694
  end
641
695
 
696
+ def test_version
697
+ out, _ = capture_io do
698
+ begin
699
+ @options.parse %w[--version]
700
+ rescue SystemExit
701
+ end
702
+ end
703
+
704
+ assert out.include?(RDoc::VERSION)
705
+ end
706
+
642
707
  end
643
708
 
@@ -110,6 +110,21 @@ class TestRDocParser < RDoc::TestCase
110
110
  end
111
111
  end
112
112
 
113
+ def test_class_for_modeline
114
+ temp_dir do
115
+ content = "# -*- rdoc -*-\n= NEWS\n"
116
+
117
+ open 'NEWS', 'w' do |io| io.write content end
118
+ app = @store.add_file 'NEWS'
119
+
120
+ parser = @RP.for app, 'NEWS', content, @options, :stats
121
+
122
+ assert_kind_of RDoc::Parser::Simple, parser
123
+
124
+ assert_equal "= NEWS\n", parser.content
125
+ end
126
+ end
127
+
113
128
  def test_can_parse_modeline
114
129
  readme_ext = File.join Dir.tmpdir, "README.EXT.#{$$}"
115
130
 
@@ -1000,6 +1000,36 @@ init_gi_repository (void)
1000
1000
  assert_equal 2, klass.method_list.length
1001
1001
  end
1002
1002
 
1003
+ def test_find_body_cast
1004
+ content = <<-EOF
1005
+ /*
1006
+ * a comment for other_function
1007
+ */
1008
+ VALUE
1009
+ other_function() {
1010
+ }
1011
+
1012
+ void
1013
+ Init_Foo(void) {
1014
+ VALUE foo = rb_define_class("Foo", rb_cObject);
1015
+
1016
+ rb_define_method(foo, "my_method", (METHOD)other_function, 0);
1017
+ }
1018
+ EOF
1019
+
1020
+ klass = util_get_class content, 'foo'
1021
+ other_function = klass.method_list.first
1022
+
1023
+ assert_equal 'my_method', other_function.name
1024
+ assert_equal "a comment for other_function",
1025
+ other_function.comment.text
1026
+ assert_equal '()', other_function.params
1027
+
1028
+ code = other_function.token_stream.first.text
1029
+
1030
+ assert_equal "VALUE\nother_function() {\n}", code
1031
+ end
1032
+
1003
1033
  def test_find_body_define
1004
1034
  content = <<-EOF
1005
1035
  #define something something_else
@@ -1669,6 +1699,80 @@ void Init(void) {
1669
1699
  assert_equal expected, @store.c_singleton_class_variables
1670
1700
  end
1671
1701
 
1702
+ def test_scan_method_copy
1703
+ parser = util_parser <<-C
1704
+ /*
1705
+ * call-seq:
1706
+ * pathname.to_s -> string
1707
+ * pathname.to_path -> string
1708
+ *
1709
+ * Return the path as a String.
1710
+ *
1711
+ * to_path is implemented so Pathname objects are usable with File.open, etc.
1712
+ */
1713
+ static VALUE
1714
+ path_to_s(VALUE self) { }
1715
+
1716
+ /*
1717
+ * call-seq:
1718
+ * str[index] -> new_str or nil
1719
+ * str[start, length] -> new_str or nil
1720
+ * str.slice(index) -> new_str or nil
1721
+ * str.slice(start, length) -> new_str or nil
1722
+ */
1723
+ static VALUE
1724
+ path_aref_m(int argc, VALUE *argv, VALUE str) { }
1725
+
1726
+ /*
1727
+ * call-seq:
1728
+ * string <=> other_string -> -1, 0, +1 or nil
1729
+ */
1730
+ static VALUE
1731
+ path_cmp_m(VALUE str1, VALUE str2) { }
1732
+
1733
+ Init_pathname()
1734
+ {
1735
+ rb_cPathname = rb_define_class("Pathname", rb_cObject);
1736
+
1737
+ rb_define_method(rb_cPathname, "to_s", path_to_s, 0);
1738
+ rb_define_method(rb_cPathname, "to_path", path_to_s, 0);
1739
+ rb_define_method(rb_cPathname, "[]", path_aref_m, -1);
1740
+ rb_define_method(rb_cPathname, "slice", path_aref_m, -1);
1741
+ rb_define_method(rb_cPathname, "<=>", path_cmp_m, 1);
1742
+ }
1743
+ C
1744
+
1745
+ parser.scan
1746
+
1747
+ pathname = @store.classes_hash['Pathname']
1748
+
1749
+ to_path = pathname.method_list.find { |m| m.name == 'to_path' }
1750
+ assert_equal "pathname.to_path -> string", to_path.call_seq
1751
+
1752
+ to_s = pathname.method_list.find { |m| m.name == 'to_s' }
1753
+ assert_equal "pathname.to_s -> string", to_s.call_seq
1754
+
1755
+ index_expected = <<-EXPECTED.chomp
1756
+ str[index] -> new_str or nil
1757
+ str[start, length] -> new_str or nil
1758
+ EXPECTED
1759
+
1760
+ index = pathname.method_list.find { |m| m.name == '[]' }
1761
+ assert_equal index_expected, index.call_seq, '[]'
1762
+
1763
+ slice_expected = <<-EXPECTED.chomp
1764
+ str.slice(index) -> new_str or nil
1765
+ str.slice(start, length) -> new_str or nil
1766
+ EXPECTED
1767
+
1768
+ slice = pathname.method_list.find { |m| m.name == 'slice' }
1769
+ assert_equal slice_expected, slice.call_seq
1770
+
1771
+ spaceship = pathname.method_list.find { |m| m.name == '<=>' }
1772
+ assert_equal "string <=> other_string -> -1, 0, +1 or nil",
1773
+ spaceship.call_seq
1774
+ end
1775
+
1672
1776
  def test_scan_order_dependent
1673
1777
  parser = util_parser <<-C
1674
1778
  void a(void) {
@@ -2780,6 +2780,30 @@ end
2780
2780
  assert c.documented?
2781
2781
  end
2782
2782
 
2783
+ def test_scan_duplicate_module
2784
+ content = <<-CONTENT
2785
+ # comment a
2786
+ module Foo
2787
+ end
2788
+
2789
+ # comment b
2790
+ module Foo
2791
+ end
2792
+ CONTENT
2793
+
2794
+ util_parser content
2795
+
2796
+ @parser.scan
2797
+
2798
+ foo = @top_level.modules.first
2799
+
2800
+ expected = [
2801
+ RDoc::Comment.new('comment b', @top_level)
2802
+ ]
2803
+
2804
+ assert_equal expected, foo.comment_location.map { |c, l| c }
2805
+ end
2806
+
2783
2807
  def test_scan_meta_method_block
2784
2808
  content = <<-CONTENT
2785
2809
  class C
@@ -162,6 +162,23 @@ class TestRDocRDoc < RDoc::TestCase
162
162
  end
163
163
  end
164
164
 
165
+ def test_parse_file_binary
166
+ @rdoc.store = RDoc::Store.new
167
+
168
+ root = File.dirname __FILE__
169
+
170
+ @rdoc.options.root = Pathname root
171
+
172
+ out, err = capture_io do
173
+ Dir.chdir root do
174
+ assert_nil @rdoc.parse_file 'binary.dat'
175
+ end
176
+ end
177
+
178
+ assert_empty out
179
+ assert_empty err
180
+ end
181
+
165
182
  def test_parse_file_page_dir
166
183
  @rdoc.store = RDoc::Store.new
167
184
 
@@ -939,7 +939,10 @@ Foo::Bar#bother
939
939
  tty = Object.new
940
940
  def tty.tty?() true; end
941
941
 
942
- driver = RDoc::RI::Driver.new
942
+ @options.delete :use_stdout
943
+ @options.delete :formatter
944
+
945
+ driver = RDoc::RI::Driver.new @options
943
946
 
944
947
  assert_instance_of @RM::ToAnsi, driver.formatter(tty)
945
948
 
@@ -162,6 +162,18 @@ Line 2
162
162
  assert_equal expected, tokens
163
163
  end
164
164
 
165
+ def test_class_tokenize_heredoc_missing_end
166
+ e = assert_raises RDoc::RubyLex::Error do
167
+ RDoc::RubyLex.tokenize <<-'RUBY', nil
168
+ >> string1 = <<-TXT
169
+ >" That's swell
170
+ >" TXT
171
+ RUBY
172
+ end
173
+
174
+ assert_equal 'Missing terminating TXT for string', e.message
175
+ end
176
+
165
177
  def test_class_tokenize_heredoc_percent_N
166
178
  tokens = RDoc::RubyLex.tokenize <<-'RUBY', nil
167
179
  a b <<-U
@@ -23,7 +23,9 @@ class TestRDocServlet < RDoc::TestCase
23
23
  @stores = {}
24
24
  @cache = Hash.new { |hash, store| hash[store] = {} }
25
25
 
26
- @s = RDoc::Servlet.new @server, @stores, @cache
26
+ @extra_dirs = [File.join(@tempdir, 'extra1'), File.join(@tempdir, 'extra2')]
27
+
28
+ @s = RDoc::Servlet.new @server, @stores, @cache, nil, @extra_dirs
27
29
 
28
30
  @req = WEBrick::HTTPRequest.new :Logger => nil
29
31
  @res = WEBrick::HTTPResponse.new :HTTPVersion => '1.0'
@@ -298,8 +300,13 @@ class TestRDocServlet < RDoc::TestCase
298
300
 
299
301
  def test_installed_docs
300
302
  touch_system_cache_path
303
+ touch_extra_cache_path
301
304
 
302
305
  expected = [
306
+ ['My Extra Documentation', 'extra-1/', true, :extra,
307
+ @extra_dirs[0]],
308
+ ['Extra Documentation', 'extra-2/', false, :extra,
309
+ @extra_dirs[1]],
303
310
  ['Ruby Documentation', 'ruby/', true, :system,
304
311
  @system_dir],
305
312
  ['Site Documentation', 'site/', false, :site,
@@ -329,6 +336,8 @@ class TestRDocServlet < RDoc::TestCase
329
336
  paths = @s.ri_paths
330
337
 
331
338
  expected = [
339
+ [@extra_dirs[0], :extra],
340
+ [@extra_dirs[1], :extra],
332
341
  [@system_dir, :system],
333
342
  [File.join(@base, 'site'), :site],
334
343
  [RDoc::RI::Paths::HOMEDIR, :home],
@@ -347,6 +356,7 @@ class TestRDocServlet < RDoc::TestCase
347
356
 
348
357
  def test_root_search
349
358
  touch_system_cache_path
359
+ touch_extra_cache_path
350
360
 
351
361
  @s.root_search @req, @res
352
362
 
@@ -359,12 +369,16 @@ class TestRDocServlet < RDoc::TestCase
359
369
  expected = {
360
370
  'index' => {
361
371
  'searchIndex' => %w[
372
+ My\ Extra\ Documentation
362
373
  Ruby\ Documentation
363
374
  ],
364
375
  'longSearchIndex' => %w[
376
+ My\ Extra\ Documentation
365
377
  Ruby\ Documentation
366
378
  ],
367
379
  'info' => [
380
+ ['My Extra Documentation', '', @extra_dirs[0], '',
381
+ 'My Extra Documentation'],
368
382
  ['Ruby Documentation', '', 'ruby', '',
369
383
  'Documentation for the Ruby standard library'],
370
384
  ],
@@ -454,6 +468,13 @@ class TestRDocServlet < RDoc::TestCase
454
468
  assert_equal :site, store.type
455
469
  end
456
470
 
471
+ def test_store_for_extra
472
+ store = @s.store_for 'extra-1'
473
+
474
+ assert_equal @extra_dirs.first, store.path
475
+ assert_equal :extra, store.type
476
+ end
477
+
457
478
  def touch_system_cache_path
458
479
  store = RDoc::Store.new @system_dir
459
480
  store.title = 'Standard Library Documentation'
@@ -463,5 +484,14 @@ class TestRDocServlet < RDoc::TestCase
463
484
  store.save
464
485
  end
465
486
 
487
+ def touch_extra_cache_path
488
+ store = RDoc::Store.new @extra_dirs.first
489
+ store.title = 'My Extra Documentation'
490
+
491
+ FileUtils.mkdir_p File.dirname store.cache_path
492
+
493
+ store.save
494
+ end
495
+
466
496
  end
467
497