rdoc 3.5.3 → 3.6

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.

@@ -7,6 +7,18 @@ require 'fileutils'
7
7
  # The store manages reading and writing ri data for a project (gem, path,
8
8
  # etc.) and maintains a cache of methods, classes and ancestors in the
9
9
  # store.
10
+ #
11
+ # The store maintains a #cache of its contents for faster lookup. After
12
+ # adding items to the store it must be flushed using #save_cache. The cache
13
+ # contains the following structures:
14
+ #
15
+ # @cache = {
16
+ # :class_methods => {}, # class name => class methods
17
+ # :instance_methods => {}, # class name => instance methods
18
+ # :attributes => {}, # class name => attributes
19
+ # :modules => [], # classes and modules in this store
20
+ # :ancestors => {}, # class name => ancestor names
21
+ # }
10
22
 
11
23
  class RDoc::RI::Store
12
24
 
@@ -403,9 +403,11 @@ class RDoc::RubyLex
403
403
  res = ''
404
404
  nil until (ch = getc) == "\n"
405
405
 
406
- until peek_equal?("=end") && peek(4) =~ /\s/ do
407
- until (ch = getc) == "\n" do res << ch end
406
+ until ( peek_equal?("=end") && peek(4) =~ /\s/ ) do
407
+ (ch = getc)
408
+ res << ch
408
409
  end
410
+
409
411
  gets # consume =end
410
412
 
411
413
  @ltype = nil
@@ -31,7 +31,7 @@ class RDoc::Stats
31
31
 
32
32
  @coverage_level = 0
33
33
  @doc_items = nil
34
- @fully_documented = nil
34
+ @fully_documented = false
35
35
  @num_params = 0
36
36
  @percent_doc = nil
37
37
  @start = Time.now
@@ -5,46 +5,43 @@
5
5
  class RDoc::Stats::Normal < RDoc::Stats::Quiet
6
6
 
7
7
  def begin_adding # :nodoc:
8
- puts "Parsing sources..."
8
+ puts "Parsing sources..." if $stdout.tty?
9
9
  end
10
10
 
11
11
  ##
12
12
  # Prints a file with a progress bar
13
13
 
14
14
  def print_file files_so_far, filename
15
+ return unless $stdout.tty?
16
+
15
17
  progress_bar = sprintf("%3d%% [%2d/%2d] ",
16
18
  100 * files_so_far / @num_files,
17
19
  files_so_far,
18
20
  @num_files)
19
21
 
20
- if $stdout.tty? then
21
- # Print a progress bar, but make sure it fits on a single line. Filename
22
- # will be truncated if necessary.
23
- terminal_width = (ENV['COLUMNS'] || 80).to_i
24
- max_filename_size = terminal_width - progress_bar.size
25
-
26
- if filename.size > max_filename_size then
27
- # Turn "some_long_filename.rb" to "...ong_filename.rb"
28
- filename = filename[(filename.size - max_filename_size) .. -1]
29
- filename[0..2] = "..."
30
- end
31
-
32
- # Pad the line with whitespaces so that leftover output from the
33
- # previous line doesn't show up.
34
- line = "#{progress_bar}#{filename}"
35
- padding = terminal_width - line.size
36
- line << (" " * padding) if padding > 0
37
-
38
- $stdout.print("#{line}\r")
39
- else
40
- $stdout.puts "#{progress_bar} #{filename}"
22
+ # Print a progress bar, but make sure it fits on a single line. Filename
23
+ # will be truncated if necessary.
24
+ terminal_width = (ENV['COLUMNS'] || 80).to_i
25
+ max_filename_size = terminal_width - progress_bar.size
26
+
27
+ if filename.size > max_filename_size then
28
+ # Turn "some_long_filename.rb" to "...ong_filename.rb"
29
+ filename = filename[(filename.size - max_filename_size) .. -1]
30
+ filename[0..2] = "..."
41
31
  end
42
32
 
33
+ # Pad the line with whitespaces so that leftover output from the
34
+ # previous line doesn't show up.
35
+ line = "#{progress_bar}#{filename}"
36
+ padding = terminal_width - line.size
37
+ line << (" " * padding) if padding > 0
38
+
39
+ $stdout.print("#{line}\r")
43
40
  $stdout.flush
44
41
  end
45
42
 
46
43
  def done_adding # :nodoc:
47
- puts
44
+ puts if $stdout.tty?
48
45
  end
49
46
 
50
47
  end
@@ -37,9 +37,8 @@ require 'rake'
37
37
  require 'rake/tasklib'
38
38
 
39
39
  ##
40
- # Create a documentation task that will generate the RDoc files for a project.
41
- #
42
- # The RDoc::Task will create the following targets:
40
+ # RDoc::Task creates the following rake tasks to generate and clean up RDoc
41
+ # output:
43
42
  #
44
43
  # [rdoc]
45
44
  # Main task for this RDoc task.
@@ -56,12 +55,12 @@ require 'rake/tasklib'
56
55
  # gem 'rdoc'
57
56
  # require 'rdoc/task'
58
57
  #
59
- # RDoc::Task.new do |rd|
60
- # rd.main = "README.rdoc"
61
- # rd.rdoc_files.include("README.rdoc", "lib/**/*.rb")
58
+ # RDoc::Task.new do |rdoc|
59
+ # rdoc.main = "README.rdoc"
60
+ # rdoc.rdoc_files.include("README.rdoc", "lib/**/*.rb")
62
61
  # end
63
62
  #
64
- # The +rd+ object passed to the block is an RDoc::Task object. See the
63
+ # The +rdoc+ object passed to the block is an RDoc::Task object. See the
65
64
  # attributes list for the RDoc::Task class for available customization options.
66
65
  #
67
66
  # == Specifying different task names
@@ -73,10 +72,10 @@ require 'rake/tasklib'
73
72
  # gem 'rdoc'
74
73
  # require 'rdoc/task'
75
74
  #
76
- # RDoc::Task.new :rdoc_dev do |rd|
77
- # rd.main = "README.doc"
78
- # rd.rdoc_files.include("README.rdoc", "lib/**/*.rb")
79
- # rd.options << "--all"
75
+ # RDoc::Task.new :rdoc_dev do |rdoc|
76
+ # rdoc.main = "README.doc"
77
+ # rdoc.rdoc_files.include("README.rdoc", "lib/**/*.rb")
78
+ # rdoc.options << "--all"
80
79
  # end
81
80
  #
82
81
  # The tasks would then be named :<em>rdoc_dev</em>,
@@ -61,25 +61,17 @@ module RDoc::Text
61
61
  # Flush +text+ left based on the shortest line
62
62
 
63
63
  def flush_left text
64
- indents = []
64
+ indent = 9999
65
65
 
66
66
  text.each_line do |line|
67
- indents << (line =~ /[^\s]/ || 9999)
67
+ line_indent = line =~ /\S/ || 9999
68
+ indent = line_indent if indent > line_indent
68
69
  end
69
70
 
70
- indent = indents.min
71
-
72
- flush = []
73
-
74
71
  empty = ''
75
72
  empty.force_encoding text.encoding if Object.const_defined? :Encoding
76
73
 
77
- text.each_line do |line|
78
- line[/^ {0,#{indent}}/] = empty
79
- flush << line
80
- end
81
-
82
- flush.join
74
+ text.gsub(/^ {0,#{indent}}/, empty)
83
75
  end
84
76
 
85
77
  ##
@@ -8,6 +8,10 @@ class TestRDocClassModule < XrefTestCase
8
8
  @RM = RDoc::Markup
9
9
  end
10
10
 
11
+ def test_ancestors
12
+ assert_equal [@parent], @child.ancestors
13
+ end
14
+
11
15
  def test_comment_equals
12
16
  cm = RDoc::ClassModule.new 'Klass'
13
17
  cm.comment = '# comment 1'
@@ -23,6 +27,16 @@ class TestRDocClassModule < XrefTestCase
23
27
  assert_equal "comment 1\n---\ncomment 2\n---\n* comment 3", cm.comment
24
28
  end
25
29
 
30
+ def test_each_ancestor
31
+ ancestors = []
32
+
33
+ @child.each_ancestor do |mod|
34
+ ancestors << mod
35
+ end
36
+
37
+ assert_equal [@parent], ancestors
38
+ end
39
+
26
40
  # handle making a short module alias of yourself
27
41
 
28
42
  def test_find_class_named
@@ -36,6 +50,7 @@ class TestRDocClassModule < XrefTestCase
36
50
  cm1.comment = 'klass 1'
37
51
  cm1.add_attribute RDoc::Attr.new(nil, 'a1', 'RW', '')
38
52
  cm1.add_attribute RDoc::Attr.new(nil, 'a3', 'R', '')
53
+ cm1.add_attribute RDoc::Attr.new(nil, 'a4', 'R', '')
39
54
  cm1.add_constant RDoc::Constant.new('C1', nil, '')
40
55
  cm1.add_include RDoc::Include.new('I1', '')
41
56
  cm1.add_method RDoc::AnyMethod.new(nil, 'm1')
@@ -46,6 +61,7 @@ class TestRDocClassModule < XrefTestCase
46
61
  @RM::Paragraph.new('klass 2')))
47
62
  cm2.add_attribute RDoc::Attr.new(nil, 'a2', 'RW', '')
48
63
  cm2.add_attribute RDoc::Attr.new(nil, 'a3', 'W', '')
64
+ cm2.add_attribute RDoc::Attr.new(nil, 'a4', 'R', '')
49
65
  cm2.add_constant RDoc::Constant.new('C2', nil, '')
50
66
  cm2.add_include RDoc::Include.new('I2', '')
51
67
  cm2.add_method RDoc::AnyMethod.new(nil, 'm2')
@@ -62,6 +78,7 @@ class TestRDocClassModule < XrefTestCase
62
78
  RDoc::Attr.new(nil, 'a1', 'RW', ''),
63
79
  RDoc::Attr.new(nil, 'a2', 'RW', ''),
64
80
  RDoc::Attr.new(nil, 'a3', 'RW', ''),
81
+ RDoc::Attr.new(nil, 'a4', 'R', ''),
65
82
  ]
66
83
 
67
84
  expected.each do |a| a.parent = cm1 end
@@ -119,6 +119,16 @@ class TestRDocCodeObject < XrefTestCase
119
119
  assert @co.document_children
120
120
  end
121
121
 
122
+ def test_each_parent
123
+ parents = []
124
+
125
+ @parent_m.each_parent do |code_object|
126
+ parents << code_object
127
+ end
128
+
129
+ assert_equal [@parent, @xref_data], parents
130
+ end
131
+
122
132
  def test_full_name_equals
123
133
  @co.full_name = 'hi'
124
134
 
@@ -143,6 +143,16 @@ class TestRDocContext < XrefTestCase
143
143
  assert_equal [incl], @context.includes
144
144
  end
145
145
 
146
+ def test_add_include_twice
147
+ incl1 = RDoc::Include.new 'Name', 'comment'
148
+ @context.add_include incl1
149
+
150
+ incl2 = RDoc::Include.new 'Name', 'comment'
151
+ @context.add_include incl2
152
+
153
+ assert_equal [incl1], @context.includes
154
+ end
155
+
146
156
  def test_add_method
147
157
  meth = RDoc::AnyMethod.new nil, 'old_name'
148
158
  meth.visibility = nil
@@ -438,5 +448,146 @@ class TestRDocContext < XrefTestCase
438
448
  assert_equal expected, @c1.methods_by_type(separate)
439
449
  end
440
450
 
451
+ def test_methods_matching
452
+ methods = []
453
+
454
+ @parent.methods_matching 'm' do |m|
455
+ methods << m
456
+ end
457
+
458
+ assert_equal [@parent_m], methods
459
+ end
460
+
461
+ def test_methods_matching_singleton
462
+ methods = []
463
+
464
+ @parent.methods_matching 'm', true do |m|
465
+ methods << m
466
+ end
467
+
468
+ assert_equal [@parent__m], methods
469
+ end
470
+
471
+ def test_methods_matching_inherit
472
+ methods = []
473
+
474
+ @child.methods_matching 'm' do |m|
475
+ methods << m
476
+ end
477
+
478
+ assert_equal [@parent_m], methods
479
+ end
480
+
481
+ def test_remove_invisible_private
482
+ util_visibilities
483
+
484
+ @vis.remove_invisible :private
485
+
486
+ assert_equal [@pub, @prot, @priv], @vis.method_list
487
+ assert_equal [@apub, @aprot, @apriv], @vis.attributes
488
+ end
489
+
490
+ def test_remove_invisible_protected
491
+ util_visibilities
492
+
493
+ @vis.remove_invisible :protected
494
+
495
+ assert_equal [@pub, @prot], @vis.method_list
496
+ assert_equal [@apub, @aprot], @vis.attributes
497
+ end
498
+
499
+ def test_remove_invisible_public
500
+ util_visibilities
501
+
502
+ @vis.remove_invisible :public
503
+
504
+ assert_equal [@pub], @vis.method_list
505
+ assert_equal [@apub], @vis.attributes
506
+ end
507
+
508
+ def test_remove_invisible_public_force
509
+ util_visibilities
510
+
511
+ @priv.force_documentation = true
512
+ @prot.force_documentation = true
513
+ @apriv.force_documentation = true
514
+ @aprot.force_documentation = true
515
+
516
+ @vis.remove_invisible :public
517
+
518
+ assert_equal [@pub, @prot, @priv], @vis.method_list
519
+ assert_equal [@apub, @aprot, @apriv], @vis.attributes
520
+ end
521
+
522
+ def test_remove_invisible_in_protected
523
+ util_visibilities
524
+
525
+ methods = [@pub, @prot, @priv]
526
+
527
+ @c1.remove_invisible_in methods, :protected
528
+
529
+ assert_equal [@pub, @prot], methods
530
+ end
531
+
532
+ def test_remove_invisible_in_protected_force
533
+ util_visibilities
534
+
535
+ @priv.force_documentation = true
536
+
537
+ methods = [@pub, @prot, @priv]
538
+
539
+ @c1.remove_invisible_in methods, :protected
540
+
541
+ assert_equal [@pub, @prot, @priv], methods
542
+ end
543
+
544
+ def test_remove_invisible_in_public
545
+ util_visibilities
546
+
547
+ methods = [@pub, @prot, @priv]
548
+
549
+ @c1.remove_invisible_in methods, :public
550
+
551
+ assert_equal [@pub], methods
552
+ end
553
+
554
+ def test_remove_invisible_in_public_force
555
+ util_visibilities
556
+
557
+ @prot.force_documentation = true
558
+ @priv.force_documentation = true
559
+
560
+ methods = [@pub, @prot, @priv]
561
+
562
+ @c1.remove_invisible_in methods, :public
563
+
564
+ assert_equal [@pub, @prot, @priv], methods
565
+ end
566
+
567
+ def util_visibilities
568
+ @pub = RDoc::AnyMethod.new nil, 'pub'
569
+ @prot = RDoc::AnyMethod.new nil, 'prot'
570
+ @priv = RDoc::AnyMethod.new nil, 'priv'
571
+
572
+ @apub = RDoc::Attr.new nil, 'pub', 'RW', nil
573
+ @aprot = RDoc::Attr.new nil, 'prot', 'RW', nil
574
+ @apriv = RDoc::Attr.new nil, 'priv', 'RW', nil
575
+
576
+ @vis = RDoc::NormalClass.new 'Vis'
577
+ @vis.add_method @pub
578
+ @vis.add_method @prot
579
+ @vis.add_method @priv
580
+
581
+ @vis.add_attribute @apub
582
+ @vis.add_attribute @aprot
583
+ @vis.add_attribute @apriv
584
+
585
+ @prot.visibility = :protected
586
+ @priv.visibility = :private
587
+
588
+ @aprot.visibility = :protected
589
+ @apriv.visibility = :private
590
+ end
591
+
441
592
  end
442
593
 
@@ -26,9 +26,6 @@ class TestRDocEncoding < MiniTest::Unit::TestCase
26
26
  @tempfile.write expected
27
27
  @tempfile.flush
28
28
 
29
- # FIXME 1.9 fix on windoze
30
- expected.gsub!("\n", "\r\n") if RUBY_VERSION =~ /^1.9/ && RUBY_PLATFORM =~ /mswin|mingw/
31
-
32
29
  contents = RDoc::Encoding.read_file @tempfile.path, Encoding::UTF_8
33
30
  assert_equal "hi everybody", contents
34
31
  assert_equal Encoding::UTF_8, contents.encoding
@@ -55,9 +52,6 @@ class TestRDocEncoding < MiniTest::Unit::TestCase
55
52
  @tempfile.write "# coding: utf-8\n\317\200" # pi
56
53
  @tempfile.flush
57
54
 
58
- # FIXME 1.9 fix on windoze
59
- expected.gsub!("\n", "\r\n") if RUBY_VERSION =~ /^1.9/ && RUBY_PLATFORM =~ /mswin|mingw/
60
-
61
55
  contents = :junk
62
56
 
63
57
  _, err = capture_io do
@@ -78,9 +72,6 @@ class TestRDocEncoding < MiniTest::Unit::TestCase
78
72
  @tempfile.write expected
79
73
  @tempfile.flush
80
74
 
81
- # FIXME 1.9 fix on windoze
82
- expected.gsub!("\n", "\r\n") if RUBY_VERSION =~ /^1.9/ && RUBY_PLATFORM =~ /win32|mingw32/
83
-
84
75
  contents = RDoc::Encoding.read_file @tempfile.path, Encoding::UTF_8
85
76
  assert_equal "hi everybody", contents
86
77
  assert_equal Encoding::UTF_8, contents.encoding
@@ -92,9 +83,6 @@ class TestRDocEncoding < MiniTest::Unit::TestCase
92
83
  @tempfile.write "# coding: utf-8\n\317\200" # pi
93
84
  @tempfile.flush
94
85
 
95
- # FIXME 1.9 fix on windoze
96
- expected.gsub!("\n", "\r\n") if RUBY_VERSION =~ /^1.9/ && RUBY_PLATFORM =~ /mswin|mingw/
97
-
98
86
  contents = RDoc::Encoding.read_file @tempfile.path, Encoding::US_ASCII, true
99
87
 
100
88
  assert_equal '?', contents