rdoc 2.2.1 → 2.3.0

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.

Files changed (95) hide show
  1. data.tar.gz.sig +2 -0
  2. data/.document +4 -0
  3. data/History.txt +35 -0
  4. data/Manifest.txt +36 -15
  5. data/README.txt +11 -27
  6. data/Rakefile +3 -0
  7. data/lib/rdoc.rb +1 -1
  8. data/lib/rdoc/cache.rb +32 -0
  9. data/lib/rdoc/code_objects.rb +121 -59
  10. data/lib/rdoc/generator.rb +196 -133
  11. data/lib/rdoc/generator/darkfish.rb +471 -0
  12. data/lib/rdoc/generator/html.rb +71 -60
  13. data/lib/rdoc/generator/html/html.rb +115 -115
  14. data/lib/rdoc/generator/html/one_page_html.rb +56 -56
  15. data/lib/rdoc/generator/ri.rb +2 -0
  16. data/lib/rdoc/generator/template/darkfish/.document +0 -0
  17. data/lib/rdoc/generator/template/darkfish/classpage.rhtml +302 -0
  18. data/lib/rdoc/generator/template/darkfish/filepage.rhtml +114 -0
  19. data/lib/rdoc/generator/template/darkfish/images/brick.png +0 -0
  20. data/lib/rdoc/generator/template/darkfish/images/brick_link.png +0 -0
  21. data/lib/rdoc/generator/template/darkfish/images/bug.png +0 -0
  22. data/lib/rdoc/generator/template/darkfish/images/bullet_black.png +0 -0
  23. data/lib/rdoc/generator/template/darkfish/images/bullet_toggle_minus.png +0 -0
  24. data/lib/rdoc/generator/template/darkfish/images/bullet_toggle_plus.png +0 -0
  25. data/lib/rdoc/generator/template/darkfish/images/date.png +0 -0
  26. data/lib/rdoc/generator/template/darkfish/images/find.png +0 -0
  27. data/lib/rdoc/generator/template/darkfish/images/loadingAnimation.gif +0 -0
  28. data/lib/rdoc/generator/template/darkfish/images/macFFBgHack.png +0 -0
  29. data/lib/rdoc/generator/template/darkfish/images/package.png +0 -0
  30. data/lib/rdoc/generator/template/darkfish/images/page_green.png +0 -0
  31. data/lib/rdoc/generator/template/darkfish/images/page_white_text.png +0 -0
  32. data/lib/rdoc/generator/template/darkfish/images/page_white_width.png +0 -0
  33. data/lib/rdoc/generator/template/darkfish/images/plugin.png +0 -0
  34. data/lib/rdoc/generator/template/darkfish/images/ruby.png +0 -0
  35. data/lib/rdoc/generator/template/darkfish/images/tag_green.png +0 -0
  36. data/lib/rdoc/generator/template/darkfish/images/wrench.png +0 -0
  37. data/lib/rdoc/generator/template/darkfish/images/wrench_orange.png +0 -0
  38. data/lib/rdoc/generator/template/darkfish/images/zoom.png +0 -0
  39. data/lib/rdoc/generator/template/darkfish/index.rhtml +57 -0
  40. data/lib/rdoc/generator/template/darkfish/js/darkfish.js +116 -0
  41. data/lib/rdoc/generator/template/darkfish/js/jquery.js +32 -0
  42. data/lib/rdoc/generator/template/darkfish/js/quicksearch.js +114 -0
  43. data/lib/rdoc/generator/template/darkfish/js/thickbox-compressed.js +10 -0
  44. data/lib/rdoc/generator/template/darkfish/rdoc.css +696 -0
  45. data/lib/rdoc/generator/xml.rb +19 -12
  46. data/lib/rdoc/generator/xml/rdf.rb +50 -50
  47. data/lib/rdoc/generator/xml/xml.rb +58 -58
  48. data/lib/rdoc/known_classes.rb +0 -1
  49. data/lib/rdoc/markup/preprocess.rb +4 -3
  50. data/lib/rdoc/markup/to_html.rb +4 -1
  51. data/lib/rdoc/markup/to_html_crossref.rb +28 -31
  52. data/lib/rdoc/options.rb +25 -20
  53. data/lib/rdoc/parser.rb +10 -2
  54. data/lib/rdoc/parser/c.rb +38 -29
  55. data/lib/rdoc/parser/f95.rb +32 -32
  56. data/lib/rdoc/parser/ruby.rb +5 -2
  57. data/lib/rdoc/parser/simple.rb +1 -0
  58. data/lib/rdoc/rdoc.rb +99 -47
  59. data/lib/rdoc/ri/cache.rb +6 -6
  60. data/lib/rdoc/ri/display.rb +22 -75
  61. data/lib/rdoc/ri/driver.rb +237 -78
  62. data/lib/rdoc/stats.rb +91 -28
  63. data/lib/rdoc/template.rb +6 -2
  64. data/test/test.ja.rdoc +8 -0
  65. data/test/test.ja.txt +8 -0
  66. data/test/test_attribute_manager.rb +9 -6
  67. data/test/test_rdoc_markup.rb +4 -2
  68. data/test/test_rdoc_markup_attribute_manager.rb +13 -3
  69. data/test/test_rdoc_markup_to_html.rb +18 -2
  70. data/test/test_rdoc_markup_to_html_crossref.rb +186 -249
  71. data/test/test_rdoc_parser.rb +17 -1
  72. data/test/test_rdoc_parser_c.rb +65 -10
  73. data/test/test_rdoc_parser_perl.rb +4 -2
  74. data/test/test_rdoc_parser_ruby.rb +6 -4
  75. data/test/test_rdoc_ri_attribute_formatter.rb +4 -2
  76. data/test/test_rdoc_ri_default_display.rb +8 -4
  77. data/test/test_rdoc_ri_driver.rb +4 -2
  78. data/test/test_rdoc_ri_formatter.rb +6 -4
  79. data/test/test_rdoc_ri_overstrike_formatter.rb +4 -2
  80. metadata +84 -33
  81. metadata.gz.sig +0 -0
  82. data/lib/rdoc/generator/chm.rb +0 -113
  83. data/lib/rdoc/generator/chm/chm.rb +0 -100
  84. data/lib/rdoc/generator/html/frameless.rb +0 -92
  85. data/lib/rdoc/generator/html/hefss.rb +0 -150
  86. data/lib/rdoc/generator/html/kilmer.rb +0 -151
  87. data/lib/rdoc/generator/html/kilmerfactory.rb +0 -427
  88. data/lib/rdoc/generator/texinfo.rb +0 -81
  89. data/lib/rdoc/generator/texinfo/class.texinfo.erb +0 -44
  90. data/lib/rdoc/generator/texinfo/file.texinfo.erb +0 -6
  91. data/lib/rdoc/generator/texinfo/method.texinfo.erb +0 -6
  92. data/lib/rdoc/generator/texinfo/texinfo.erb +0 -28
  93. data/test/rdoc_markup_to_html_crossref_reference.rb +0 -31
  94. data/test/test_rdoc_info_formatting.rb +0 -175
  95. data/test/test_rdoc_info_sections.rb +0 -136
@@ -1,4 +1,5 @@
1
1
  require 'rdoc'
2
+ require 'thread'
2
3
 
3
4
  ##
4
5
  # Simple stats collector
@@ -9,45 +10,69 @@ class RDoc::Stats
9
10
  attr_reader :num_files
10
11
  attr_reader :num_methods
11
12
  attr_reader :num_modules
13
+ attr_reader :total_files
12
14
 
13
- def initialize(verbosity = 1)
15
+ def initialize(total_files, verbosity = 1)
16
+ @lock = Mutex.new
17
+
14
18
  @num_classes = 0
15
19
  @num_files = 0
16
20
  @num_methods = 0
17
21
  @num_modules = 0
22
+ @total_files = total_files
18
23
 
19
24
  @start = Time.now
20
25
 
21
26
  @display = case verbosity
22
27
  when 0 then Quiet.new
23
- when 1 then Normal.new
28
+ when 1 then Normal.new(total_files)
24
29
  else Verbose.new
25
30
  end
26
31
  end
32
+
33
+ def begin_adding(number_of_workers)
34
+ @display.begin_adding(number_of_workers)
35
+ end
27
36
 
28
37
  def add_alias(as)
29
- @display.print_alias as
30
- @num_methods += 1
38
+ @lock.synchronize do
39
+ @display.print_alias as
40
+ @num_methods += 1
41
+ end
31
42
  end
32
43
 
33
44
  def add_class(klass)
34
- @display.print_class klass
35
- @num_classes += 1
45
+ @lock.synchronize do
46
+ @display.print_class klass
47
+ @num_classes += 1
48
+ end
36
49
  end
37
50
 
38
51
  def add_file(file)
39
- @display.print_file file
40
- @num_files += 1
52
+ @lock.synchronize do
53
+ @display.print_file @num_files, file
54
+ @num_files += 1
55
+ end
41
56
  end
42
57
 
43
58
  def add_method(method)
44
- @display.print_method method
45
- @num_methods += 1
59
+ @lock.synchronize do
60
+ @display.print_method method
61
+ @num_methods += 1
62
+ end
46
63
  end
47
64
 
48
65
  def add_module(mod)
49
- @display.print_module mod
50
- @num_modules += 1
66
+ @lock.synchronize do
67
+ @display.print_module mod
68
+ @num_modules += 1
69
+ end
70
+ end
71
+
72
+ def done_adding
73
+ @lock.synchronize do
74
+ @display.done_adding
75
+ end
51
76
  end
52
77
 
53
78
  def print
@@ -59,36 +84,71 @@ class RDoc::Stats
59
84
  end
60
85
 
61
86
  class Quiet
87
+ def begin_adding(*) end
62
88
  def print_alias(*) end
63
89
  def print_class(*) end
64
90
  def print_file(*) end
65
91
  def print_method(*) end
66
92
  def print_module(*) end
93
+ def done_adding(*) end
67
94
  end
68
-
95
+
69
96
  class Normal
70
- def print_alias(as)
71
- print 'a'
97
+ def initialize(total_files)
98
+ @total_files = total_files
72
99
  end
73
-
74
- def print_class(klass)
75
- print 'C'
100
+
101
+ def begin_adding(number_of_workers)
102
+ puts "Parsing sources with #{number_of_workers} thread(s)..."
76
103
  end
77
-
78
- def print_file(file)
79
- print "\n#{file}: "
104
+
105
+ def print_file(files_so_far, filename)
106
+ progress_bar = sprintf("%3d%% [%2d/%2d] ",
107
+ 100 * (files_so_far + 1) / @total_files,
108
+ files_so_far + 1,
109
+ @total_files)
110
+
111
+ if $stdout.tty?
112
+ # Print a progress bar, but make sure it fits on a single line. Filename
113
+ # will be truncated if necessary.
114
+ terminal_width = (ENV['COLUMNS'] || 80).to_i
115
+ max_filename_size = terminal_width - progress_bar.size
116
+ if filename.size > max_filename_size
117
+ # Turn "some_long_filename.rb" to "...ong_filename.rb"
118
+ filename = filename[(filename.size - max_filename_size) .. -1]
119
+ filename[0..2] = "..."
120
+ end
121
+
122
+ # Pad the line with whitespaces so that leftover output from the
123
+ # previous line doesn't show up.
124
+ line = "#{progress_bar}#{filename}"
125
+ padding = terminal_width - line.size
126
+ if padding > 0
127
+ line << (" " * padding)
128
+ end
129
+
130
+ $stdout.print("#{line}\r")
131
+ $stdout.flush
132
+ else
133
+ puts "#{progress_bar} #{filename}"
134
+ end
80
135
  end
81
-
82
- def print_method(method)
83
- print 'm'
136
+
137
+ def done_adding
138
+ puts "\n"
84
139
  end
85
140
 
86
- def print_module(mod)
87
- print 'M'
88
- end
141
+ def print_alias(*) end
142
+ def print_class(*) end
143
+ def print_method(*) end
144
+ def print_module(*) end
89
145
  end
90
146
 
91
147
  class Verbose
148
+ def begin_adding(number_of_workers)
149
+ puts "Parsing sources with #{number_of_workers} thread(s)..."
150
+ end
151
+
92
152
  def print_alias(as)
93
153
  puts "\t\talias #{as.new_name} #{as.old_name}"
94
154
  end
@@ -97,7 +157,7 @@ class RDoc::Stats
97
157
  puts "\tclass #{klass.full_name}"
98
158
  end
99
159
 
100
- def print_file(file)
160
+ def print_file(files_so_far, file)
101
161
  puts file
102
162
  end
103
163
 
@@ -108,6 +168,9 @@ class RDoc::Stats
108
168
  def print_module(mod)
109
169
  puts "\tmodule #{mod.full_name}"
110
170
  end
171
+
172
+ def done_adding
173
+ end
111
174
  end
112
175
 
113
176
  end
@@ -53,8 +53,12 @@ class RDoc::TemplatePage
53
53
  b = binding
54
54
  template_include = ""
55
55
 
56
- @templates.reverse_each do |template|
57
- template_include = ERB.new(template).result b
56
+ @compiled_templates ||= @templates.map do |template|
57
+ ERB.new(template)
58
+ end
59
+
60
+ @compiled_templates.reverse_each do |template|
61
+ template_include = template.result(b)
58
62
  end
59
63
 
60
64
  io.write template_include
@@ -0,0 +1,8 @@
1
+ こんにちは!
2
+
3
+ 初めまして。アーロンと申します。
4
+
5
+ どんな食べ物が好きですか?私はフランスの料理が大好きです。
6
+ 日本の料理も大好きです。
7
+
8
+ 食べ物を食べるのが大好きだけど、お皿を洗うのが大嫌いです。
@@ -0,0 +1,8 @@
1
+ こんにちは!
2
+
3
+ 初めまして。アーロンと申します。
4
+
5
+ どんな食べ物が好きですか?私はフランスの料理が大好きです。
6
+ 日本の料理も大好きです。
7
+
8
+ 食べ物を食べるのが大好きだけど、お皿を洗うのが大嫌いです。
@@ -1,15 +1,16 @@
1
- require 'test/unit'
1
+ require 'rubygems'
2
+ require 'minitest/unit'
2
3
  require 'rdoc/markup/attribute_manager'
3
4
 
4
- class TestAttributeManager < Test::Unit::TestCase
5
+ class TestAttributeManager < MiniTest::Unit::TestCase
5
6
 
6
7
  def setup
7
8
  @am = RDoc::Markup::AttributeManager.new
8
9
  @klass = RDoc::Markup::AttributeManager
9
10
  end
10
-
11
+
11
12
  def teardown
12
- silently do
13
+ silently do
13
14
  @klass.const_set(:MATCHING_WORD_PAIRS, {})
14
15
  @klass.const_set(:WORD_PAIR_MAP, {})
15
16
  @klass.const_set(:HTML_TAGS, {})
@@ -34,9 +35,9 @@ class TestAttributeManager < Test::Unit::TestCase
34
35
  assert_equal(4,word_pairs.size)
35
36
  assert(word_pairs.has_key?("x"))
36
37
  end
37
-
38
+
38
39
  def test_add_invalid_word_pair
39
- assert_raise ArgumentError do
40
+ assert_raises ArgumentError do
40
41
  @am.add_word_pair("<", "<", :TEST)
41
42
  end
42
43
  end
@@ -71,3 +72,5 @@ class TestAttributeManager < Test::Unit::TestCase
71
72
  end
72
73
 
73
74
  end
75
+
76
+ MiniTest::Unit.autorun
@@ -1,8 +1,9 @@
1
- require 'test/unit'
1
+ require 'rubygems'
2
+ require 'minitest/unit'
2
3
  require 'rdoc/markup'
3
4
  require 'rdoc/markup/to_test'
4
5
 
5
- class TestRDocMarkup < Test::Unit::TestCase
6
+ class TestRDocMarkup < MiniTest::Unit::TestCase
6
7
 
7
8
  def basic_conv(str)
8
9
  sm = RDoc::Markup.new
@@ -611,3 +612,4 @@ class TestRDocMarkup < Test::Unit::TestCase
611
612
 
612
613
  end
613
614
 
615
+ MiniTest::Unit.autorun
@@ -1,10 +1,14 @@
1
- require "test/unit"
1
+ require "rubygems"
2
+ require "minitest/unit"
2
3
  require "rdoc/markup/inline"
3
4
  require "rdoc/markup/to_html_crossref"
4
5
 
5
- class TestRDocMarkupAttributeManager < Test::Unit::TestCase
6
+ class TestRDocMarkupAttributeManager < MiniTest::Unit::TestCase
6
7
 
7
8
  def setup
9
+ @orig_special = RDoc::Markup::AttributeManager::SPECIAL
10
+ RDoc::Markup::AttributeManager::SPECIAL.replace Hash.new
11
+
8
12
  @am = RDoc::Markup::AttributeManager.new
9
13
 
10
14
  @bold_on = @am.changed_attribute_by_name([], [:BOLD])
@@ -28,6 +32,10 @@ class TestRDocMarkupAttributeManager < Test::Unit::TestCase
28
32
  @wombat_off = @am.changed_attribute_by_name([:WOMBAT], [])
29
33
  end
30
34
 
35
+ def teardown
36
+ RDoc::Markup::AttributeManager::SPECIAL.replace @orig_special
37
+ end
38
+
31
39
  def crossref(text)
32
40
  crossref_bitmap = RDoc::Markup::Attribute.bitmap_for(:_SPECIAL_) |
33
41
  RDoc::Markup::Attribute.bitmap_for(:CROSSREF)
@@ -53,7 +61,7 @@ class TestRDocMarkupAttributeManager < Test::Unit::TestCase
53
61
  end
54
62
 
55
63
  def test_add_word_pair_angle
56
- e = assert_raise ArgumentError do
64
+ e = assert_raises ArgumentError do
57
65
  @am.add_word_pair '<', '>', 'angles'
58
66
  end
59
67
 
@@ -222,3 +230,5 @@ class TestRDocMarkupAttributeManager < Test::Unit::TestCase
222
230
  end
223
231
 
224
232
  end
233
+
234
+ MiniTest::Unit.autorun
@@ -1,14 +1,28 @@
1
- require 'test/unit'
1
+ require 'rubygems'
2
+ require 'minitest/unit'
2
3
  require 'rdoc/markup'
3
4
  require 'rdoc/markup/to_html'
4
5
 
5
- class TestRDocMarkupToHtml < Test::Unit::TestCase
6
+ class TestRDocMarkupToHtml < MiniTest::Unit::TestCase
6
7
 
7
8
  def setup
8
9
  @am = RDoc::Markup::AttributeManager.new
9
10
  @th = RDoc::Markup::ToHtml.new
10
11
  end
11
12
 
13
+ def test_class_gen_relative_url
14
+ def gen(from, to)
15
+ RDoc::Markup::ToHtml.gen_relative_url from, to
16
+ end
17
+
18
+ assert_equal 'a.html', gen('a.html', 'a.html')
19
+ assert_equal 'b.html', gen('a.html', 'b.html')
20
+
21
+ assert_equal 'd.html', gen('a/c.html', 'a/d.html')
22
+ assert_equal '../a.html', gen('a/c.html', 'a.html')
23
+ assert_equal 'a/c.html', gen('a.html', 'a/c.html')
24
+ end
25
+
12
26
  def test_tt_formatting
13
27
  assert_equal "<p>\n<tt>--</tt> &#8212; <tt>cats'</tt> cats&#8217;\n</p>\n",
14
28
  util_format("<tt>--</tt> -- <tt>cats'</tt> cats'")
@@ -40,3 +54,5 @@ class TestRDocMarkupToHtml < Test::Unit::TestCase
40
54
  end
41
55
 
42
56
  end
57
+
58
+ MiniTest::Unit.autorun
@@ -1,288 +1,225 @@
1
- require 'test/unit'
1
+ require 'rubygems'
2
+ require 'minitest/unit'
2
3
  require 'rdoc/generator'
4
+ require 'rdoc/stats'
5
+ require 'rdoc/code_objects'
3
6
  require 'rdoc/markup/to_html_crossref'
7
+ require 'rdoc/parser/ruby'
4
8
 
5
9
  require 'pathname'
6
10
 
7
- class TestRDocMarkupToHtmlCrossref < Test::Unit::TestCase
8
-
9
- #
10
- # This method parses a source file and returns a Hash mapping
11
- # class names (Strings) to RDoc::Generator::Class instances
12
- # (classes), which can be used to create RDoc::Markup::ToHtmlCrossref
13
- # instances. The unit tests only test against classes starting with
14
- # Ref_, so this method only includes such classes in the Hash.
15
- #
16
- def create_class_hash
17
- # The relative gem would help here...
18
- # @source_file_name must be cleaned because rdoc does not deal
19
- # well with paths containing "." or "..".
20
- curr_file = Pathname.new(__FILE__)
21
- @source_file_name = curr_file.dirname + "rdoc_markup_to_html_crossref_reference.rb"
22
- @source_file_name = @source_file_name.cleanpath.to_s
11
+ class TestRDocMarkupToHtmlCrossref < MiniTest::Unit::TestCase
23
12
 
13
+ XREF_DATA = <<-XREF_DATA
14
+ class C1
15
+ def self.m
16
+ end
17
+
18
+ def m
19
+ end
20
+ end
21
+
22
+ class C2
23
+ class C3
24
+ def m
25
+ end
26
+
27
+ class H1
28
+ def m?
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ class C3
35
+ class H1
36
+ end
37
+
38
+ class H2
39
+ end
40
+ end
41
+
42
+ class C4
43
+ class C4
44
+ end
45
+ end
46
+ XREF_DATA
47
+
48
+ def setup
24
49
  RDoc::TopLevel.reset
25
50
 
26
- # Reset RDoc::Generator::Method so that the method sequence number starts
27
- # at 1, making the method sequence numbers for the methods in the Ref_
28
- # predicable.
29
51
  RDoc::Generator::Method.reset
30
- top_level = RDoc::TopLevel.new @source_file_name
31
-
52
+ top_level = RDoc::TopLevel.new 'xref_data.rb'
53
+
32
54
  options = RDoc::Options.new
33
55
  options.quiet = true
34
-
35
- # If this is false, then RDoc::Generator::Method will attempt to create
36
- # an HTML file containing the method source code when being instantiated,
37
- # which does not work in the context of this unit test.
38
- #
39
- # RDoc::Generator::Method needs to be refactored so that this does *not*
40
- # happen as part of instantiation.
41
- options.inline_source = true
56
+ options.inline_source = true # don't build HTML files
42
57
 
43
58
  stats = RDoc::Stats.new 0
44
59
 
45
- parser = RDoc::Parser::Ruby.new(top_level,
46
- @source_file_name,
47
- IO.read(@source_file_name),
48
- options,
49
- stats)
60
+ parser = RDoc::Parser::Ruby.new top_level, 'xref_data.rb', XREF_DATA,
61
+ options, stats
50
62
  top_levels = []
51
- top_levels.push(parser.scan())
63
+ top_levels.push parser.scan
52
64
 
53
- files, classes = RDoc::Generator::Context.build_indices(top_levels, options)
65
+ files, classes = RDoc::Generator::Context.build_indices top_levels, options
66
+
67
+ @class_hash = {}
54
68
 
55
- class_hash = {}
56
69
  classes.each do |klass|
57
- if(klass.name.include?("Ref_"))
58
- class_hash[klass.name] = klass
59
- end
70
+ @class_hash[klass.name] = klass
60
71
  end
61
72
 
62
- return class_hash
73
+ @klass = @class_hash['C1']
74
+ @xref = RDoc::Markup::ToHtmlCrossref.new 'index.html', @klass, true
63
75
  end
64
76
 
65
- #
66
- # This method uses xref to cross-reference String reference and
67
- # asserts that xref.convert(reference) is equal
68
- # to String expected_result.
69
- #
70
- def verify_convert(xref, reference, expected_result)
71
- # Everything converted in the tests will be within paragraph markup, so
72
- # add paragraph markup to the expected result.
73
- actual_expected_result = "<p>\n#{expected_result}\n</p>\n"
74
-
75
- result = xref.convert(reference)
76
-
77
- # RDoc::Markup::ToHtml word-wraps lines. It is tricky to predict where
78
- # a line will be wrapped except that it will happen on a space, so replace
79
- # all newlines with spaces in order to not have to worry about this.
80
- actual_expected_result.gsub!(/\n/, " ")
81
- result.gsub!(/\n/, " ")
82
-
83
- assert_equal actual_expected_result, result
77
+ def assert_ref(path, ref)
78
+ assert_equal "<p>\n<a href=\"#{path}\">#{ref}</a>\n</p>\n",
79
+ @xref.convert(ref)
84
80
  end
85
81
 
86
- #
87
- # This method verifies that xref generates no cross-reference link for
88
- # String reference.
89
- #
90
- def verify_no_crossref(xref, reference)
91
- if(reference[0, 1] == "\\") # Remove the markup suppression character
92
- expected_result = reference[1, reference.length() - 1]
93
- else
94
- expected_result = reference
95
- end
82
+ def refute_ref(body, ref)
83
+ assert_equal "<p>\n#{body}\n</p>\n", @xref.convert(ref)
84
+ end
85
+
86
+ def test_handle_special_CROSSREF_C2
87
+ @klass = @class_hash['C2']
88
+ @xref = RDoc::Markup::ToHtmlCrossref.new 'classes/C2.html', @klass, true
89
+
90
+ refute_ref '#m', '#m'
96
91
 
97
- verify_convert(xref, reference, expected_result)
92
+ assert_ref 'C2/C3.html', 'C2::C3'
93
+ assert_ref 'C2/C3.html#M000003', 'C2::C3#m'
94
+ assert_ref 'C2/C3/H1.html', 'C3::H1'
95
+ assert_ref 'C4.html', 'C4'
96
+
97
+ # TODO there is a C3::H2 in the top-level namespace and RDoc should follow
98
+ # constant scoping rules
99
+ refute_ref 'C3::H2', 'C3::H2'
100
+ refute_ref 'H1', 'H1'
98
101
  end
99
102
 
100
- #
101
- # This method verifies that xref generates a cross-reference link to
102
- # class_name (String) for String reference.
103
- #
104
- def verify_class_crossref(xref, reference, class_name)
105
- class_file_name = class_name.gsub(/::/, "/")
106
-
107
- result = "<a href=\"../classes/#{class_file_name}.html\">#{reference}</a>"
103
+ def test_handle_special_CROSSREF_C2_C3
104
+ @klass = @class_hash['C2::C3']
105
+ @xref = RDoc::Markup::ToHtmlCrossref.new 'classes/C2/C3.html', @klass, true
106
+
107
+ assert_ref 'C3.html#M000003', '#m'
108
+
109
+ assert_ref 'C3.html', 'C3'
110
+ assert_ref 'C3.html#M000003', 'C3#m'
111
+
112
+ assert_ref 'C3/H1.html', 'H1'
113
+ assert_ref 'C3/H1.html', 'C3::H1'
108
114
 
109
- verify_convert xref, reference, result
115
+ assert_ref '../C4.html', 'C4'
116
+
117
+ refute_ref 'C3::H2', 'C3::H2'
118
+ end
119
+
120
+ def test_handle_special_CROSSREF_C3
121
+ @klass = @class_hash['C3']
122
+ @xref = RDoc::Markup::ToHtmlCrossref.new 'classes/C3.html', @klass, true
123
+
124
+ assert_ref 'C3.html', 'C3'
125
+
126
+ refute_ref '#m', '#m'
127
+ refute_ref 'C3#m', 'C3#m'
128
+
129
+ assert_ref 'C3/H1.html', 'H1'
130
+
131
+ assert_ref 'C3/H1.html', 'C3::H1'
132
+ assert_ref 'C3/H2.html', 'C3::H2'
133
+
134
+ assert_ref 'C4.html', 'C4'
110
135
  end
111
136
 
112
- #
113
- # This method verifies that xref generates a cross-reference link to method
114
- # method_seq (String, e.g, "M000001") in class_name (String) for
115
- # String reference.
116
- #
117
- def verify_method_crossref(xref, reference, class_name, method_seq)
118
- class_file_name = class_name.gsub(/::/, "/")
119
-
120
- result = "<a href=\"../classes/#{class_file_name}.html##{method_seq}\">#{reference}</a>"
121
-
122
- verify_convert xref, reference, result
137
+ def test_handle_special_CROSSREF_C4
138
+ @klass = @class_hash['C4']
139
+ @xref = RDoc::Markup::ToHtmlCrossref.new 'classes/C4.html', @klass, true
140
+
141
+ # C4 ref inside a C4 containing a C4 should resolve to the contained class
142
+ assert_ref 'C4/C4.html', 'C4'
123
143
  end
124
144
 
125
- #
126
- # This method verifies that xref generates a cross-reference link to
127
- # file_name (String) for String reference.
128
- #
129
- def verify_file_crossref(xref, reference, file_name)
130
- generated_document_path = Pathname.new("../files/#{file_name.gsub(/\./, '_')}.html").cleanpath.to_s
131
- result = "<a href=\"#{generated_document_path}\">#{reference}</a>"
145
+ def test_handle_special_CROSSREF_C4_C4
146
+ @klass = @class_hash['C4::C4']
147
+ @xref = RDoc::Markup::ToHtmlCrossref.new 'classes/C4/C4.html', @klass, true
132
148
 
133
- verify_convert xref, reference, result
149
+ # A C4 reference inside a C4 class contained within a C4 class should
150
+ # resolve to the inner C4 class.
151
+ assert_ref 'C4.html', 'C4'
134
152
  end
135
153
 
136
- #
137
- # This method verifies that several invariant cross-references are
138
- # (or are not) generated.
139
- #
140
- def verify_invariant_crossrefs(xref)
141
- # bogus does not exist and so no cross-reference should be generated.
142
- verify_no_crossref xref, "bogus"
143
- verify_no_crossref xref, "\\bogus"
144
-
145
- # Ref_Class1 is in the top-level namespace, and so a cross-reference always
146
- # should be generated, unless markup is suppressed.
147
- verify_class_crossref xref, "Ref_Class1", "Ref_Class1"
148
- verify_no_crossref xref, "\\Ref_Class1"
149
-
150
- # Ref_Class2 is in the top-level namespace, and so a cross-reference always
151
- # should be generated for it and for its nested classes.
152
- verify_class_crossref xref, "Ref_Class2", "Ref_Class2"
153
- verify_class_crossref xref, "Ref_Class2::Ref_Class3", "Ref_Class2::Ref_Class3"
154
- verify_method_crossref xref, "Ref_Class2::Ref_Class3#method", "Ref_Class2::Ref_Class3", "M000001"
155
- verify_method_crossref xref, "Ref_Class2::Ref_Class3#method()", "Ref_Class2::Ref_Class3", "M000001"
156
- verify_method_crossref xref, "Ref_Class2::Ref_Class3.method()", "Ref_Class2::Ref_Class3", "M000001"
157
- verify_method_crossref xref, "Ref_Class2::Ref_Class3.method(*)", "Ref_Class2::Ref_Class3", "M000001"
158
- verify_class_crossref xref, "Ref_Class2::Ref_Class3::Helper1", "Ref_Class2::Ref_Class3::Helper1"
159
- verify_method_crossref xref, "Ref_Class2::Ref_Class3::Helper1#method?", "Ref_Class2::Ref_Class3::Helper1", "M000002"
160
-
161
- # The hyphen character is not a valid class/method separator character, so
162
- # rdoc just generates a class cross-reference (perhaps it should not
163
- # generate anything?).
164
- result = "<a href=\"../classes/Ref_Class2/Ref_Class3.html\">Ref_Class2::Ref_Class3</a>;method(*)"
165
- verify_convert xref, "Ref_Class2::Ref_Class3;method(*)", result
166
-
167
- # There is one Ref_Class3 nested in Ref_Class2 and one defined in the
168
- # top-level namespace; regardless, ::Ref_Class3 (Ref_Class3 relative
169
- # to the top-level namespace) always should generate a link to the
170
- # top-level Ref_Class3 (unless of course cross-references are suppressed).
171
- verify_class_crossref xref, "::Ref_Class3", "Ref_Class3"
172
- verify_no_crossref xref, "\\::Ref_Class3"
173
- verify_class_crossref xref, "::Ref_Class3::Helper1", "Ref_Class3::Helper1"
174
- verify_class_crossref xref, "::Ref_Class3::Helper2", "Ref_Class3::Helper2"
175
-
176
- #
177
- # Ref_Class3::Helper1 does not have method method.
178
- #
179
- verify_no_crossref xref, "::Ref_Class3::Helper1#method"
180
- verify_no_crossref xref, "\\::Ref_Class3::Helper1#method"
181
-
182
- # References to Ref_Class2 relative to the top-level namespace always should
183
- # generate links to Ref_Class2.
184
- verify_method_crossref xref, "::Ref_Class2::Ref_Class3#method", "Ref_Class2::Ref_Class3", "M000001"
185
- verify_method_crossref xref, "::Ref_Class2::Ref_Class3#method()", "Ref_Class2::Ref_Class3", "M000001"
186
- verify_method_crossref xref, "::Ref_Class2::Ref_Class3#method(*)", "Ref_Class2::Ref_Class3", "M000001"
187
- verify_class_crossref xref, "::Ref_Class2::Ref_Class3::Helper1", "Ref_Class2::Ref_Class3::Helper1"
188
- verify_no_crossref xref, "\\::Ref_Class2::Ref_Class3#method(*)"
189
-
190
- # Suppressing cross-references always should suppress the generation of
191
- # links.
192
- verify_no_crossref xref, "\\#method"
193
- verify_no_crossref xref, "\\#method()"
194
- verify_no_crossref xref, "\\#method(*)"
195
-
196
- # Links never should be generated for words solely consisting of lowercase
197
- # letters, because too many links would get generated by mistake (i.e., the
198
- # word "new" always would be a link).
199
- verify_no_crossref xref, "method"
200
-
201
- # A link always should be generated for a file name.
202
- verify_file_crossref xref, @source_file_name, @source_file_name
203
-
204
- # References should be generated correctly for a class scoped within
205
- # a class of the same name.
206
- verify_class_crossref xref, "Ref_Class4::Ref_Class4", "Ref_Class4::Ref_Class4"
154
+ def test_handle_special_CROSSREF_class
155
+ assert_ref 'classes/C1.html', 'C1'
156
+ refute_ref 'H1', 'H1'
157
+
158
+ assert_ref 'classes/C2.html', 'C2'
159
+ assert_ref 'classes/C2/C3.html', 'C2::C3'
160
+ assert_ref 'classes/C2/C3/H1.html', 'C2::C3::H1'
161
+
162
+ assert_ref 'classes/C3.html', '::C3'
163
+ assert_ref 'classes/C3/H1.html', '::C3::H1'
164
+
165
+ assert_ref 'classes/C4/C4.html', 'C4::C4'
207
166
  end
208
167
 
209
- def test_handle_special_CROSSREF_no_underscore
210
- class_hash = create_class_hash
211
-
212
- # Note that we instruct the ToHtmlCrossref instance to show hashes so that
213
- # an exception won't have to be made for words starting with a '#'.
214
- # I'm also not convinced that the current behavior of the rdoc code
215
- # is correct since, without this, it strips the leading # from all
216
- # words, whether or not they end up as cross-references.
217
- #
218
- # After the behavior has been sorted out, this can be changed.
219
- #
220
- # Create a variety of RDoc::Markup::ToHtmlCrossref instances, for
221
- # different classes, and test the cross-references generated by
222
- # each.
223
- klass = class_hash["Ref_Class1"]
224
- xref = RDoc::Markup::ToHtmlCrossref.new 'from_path', klass, true
225
- verify_invariant_crossrefs xref
226
- verify_class_crossref xref, "Ref_Class3", "Ref_Class3"
227
- verify_no_crossref xref, "Ref_Class3#method"
228
- verify_no_crossref xref, "#method"
229
- verify_class_crossref xref, "Ref_Class3::Helper1", "Ref_Class3::Helper1"
230
- verify_class_crossref xref, "Ref_Class3::Helper2", "Ref_Class3::Helper2"
231
- verify_no_crossref xref, "Helper1"
232
- verify_class_crossref xref, "Ref_Class4", "Ref_Class4"
233
-
234
- klass = class_hash["Ref_Class2"]
235
- xref = RDoc::Markup::ToHtmlCrossref.new 'from_path', klass, true
236
- verify_invariant_crossrefs xref
237
- verify_class_crossref xref, "Ref_Class3", "Ref_Class2::Ref_Class3"
238
- verify_method_crossref xref, "Ref_Class3#method", "Ref_Class2::Ref_Class3", "M000001"
239
- verify_no_crossref xref, "#method"
240
- verify_class_crossref xref, "Ref_Class3::Helper1", "Ref_Class2::Ref_Class3::Helper1"
241
- verify_class_crossref xref, "Ref_Class4", "Ref_Class4"
242
-
243
- # This one possibly is an rdoc bug...
244
- # Ref_Class2 has a nested Ref_Class3, but
245
- # Ref_Class2::Ref_Class3::Helper2 does not exist.
246
- # On the other hand, there is a Ref_Class3::Helper2
247
- # in the top-level namespace... Should rdoc stop
248
- # looking if it finds one class match?
249
- verify_no_crossref xref, "Ref_Class3::Helper2"
250
- verify_no_crossref xref, "Helper1"
251
-
252
- klass = class_hash["Ref_Class2::Ref_Class3"]
253
- xref = RDoc::Markup::ToHtmlCrossref.new 'from_path', klass, true
254
- verify_invariant_crossrefs xref
255
- verify_class_crossref xref, "Ref_Class3", "Ref_Class2::Ref_Class3"
256
- verify_method_crossref xref, "Ref_Class3#method", "Ref_Class2::Ref_Class3", "M000001"
257
- verify_method_crossref xref, "#method", "Ref_Class2::Ref_Class3", "M000001"
258
- verify_class_crossref xref, "Ref_Class3::Helper1", "Ref_Class2::Ref_Class3::Helper1"
259
- verify_no_crossref xref, "Ref_Class3::Helper2"
260
- verify_class_crossref xref, "Helper1", "Ref_Class2::Ref_Class3::Helper1"
261
- verify_class_crossref xref, "Ref_Class4", "Ref_Class4"
262
-
263
- klass = class_hash["Ref_Class3"]
264
- xref = RDoc::Markup::ToHtmlCrossref.new 'from_path', klass, true
265
- verify_invariant_crossrefs xref
266
- verify_class_crossref xref, "Ref_Class3", "Ref_Class3"
267
- verify_no_crossref xref, "Ref_Class3#method"
268
- verify_no_crossref xref, "#method"
269
- verify_class_crossref xref, "Ref_Class3::Helper1", "Ref_Class3::Helper1"
270
- verify_class_crossref xref, "Ref_Class3::Helper2", "Ref_Class3::Helper2"
271
- verify_class_crossref xref, "Helper1", "Ref_Class3::Helper1"
272
- verify_class_crossref xref, "Ref_Class4", "Ref_Class4"
273
-
274
- klass = class_hash["Ref_Class4"]
275
- xref = RDoc::Markup::ToHtmlCrossref.new 'from_path', klass, true
276
- verify_invariant_crossrefs xref
277
- # A Ref_Class4 reference inside a Ref_Class4 class containing a
278
- # Ref_Class4 class should resolve to the contained class.
279
- verify_class_crossref xref, "Ref_Class4", "Ref_Class4::Ref_Class4"
280
-
281
- klass = class_hash["Ref_Class4::Ref_Class4"]
282
- xref = RDoc::Markup::ToHtmlCrossref.new 'from_path', klass, true
283
- verify_invariant_crossrefs xref
284
- # A Ref_Class4 reference inside a Ref_Class4 class contained within
285
- # a Ref_Class4 class should resolve to the inner Ref_Class4 class.
286
- verify_class_crossref xref, "Ref_Class4", "Ref_Class4::Ref_Class4"
168
+ def test_handle_special_CROSSREF_file
169
+ assert_ref 'files/xref_data_rb.html', 'xref_data.rb'
287
170
  end
171
+
172
+ def test_handle_special_CROSSREF_method
173
+ refute_ref 'm', 'm'
174
+ assert_ref 'classes/C1.html#M000001', '#m'
175
+
176
+ assert_ref 'classes/C1.html#M000001', 'C1#m'
177
+ assert_ref 'classes/C1.html#M000001', 'C1#m()'
178
+ assert_ref 'classes/C1.html#M000001', 'C1#m(*)'
179
+
180
+ assert_ref 'classes/C1.html#M000001', 'C1.m'
181
+ assert_ref 'classes/C1.html#M000001', 'C1.m()'
182
+ assert_ref 'classes/C1.html#M000001', 'C1.m(*)'
183
+
184
+ # HACK should this work
185
+ #assert_ref 'classes/C1.html#M000001', 'C1::m'
186
+ #assert_ref 'classes/C1.html#M000001', 'C1::m()'
187
+ #assert_ref 'classes/C1.html#M000001', 'C1::m(*)'
188
+
189
+ assert_ref 'classes/C2/C3.html#M000003', 'C2::C3#m'
190
+
191
+ assert_ref 'classes/C2/C3.html#M000003', 'C2::C3.m'
192
+
193
+ assert_ref 'classes/C2/C3/H1.html#M000004', 'C2::C3::H1#m?'
194
+
195
+ assert_ref 'classes/C2/C3.html#M000003', '::C2::C3#m'
196
+ assert_ref 'classes/C2/C3.html#M000003', '::C2::C3#m()'
197
+ assert_ref 'classes/C2/C3.html#M000003', '::C2::C3#m(*)'
198
+ end
199
+
200
+ def test_handle_special_CROSSREF_no_ref
201
+ assert_equal '', @xref.convert('')
202
+
203
+ refute_ref 'bogus', 'bogus'
204
+ refute_ref 'bogus', '\bogus'
205
+
206
+ refute_ref '#n', '\#n'
207
+ refute_ref '#n()', '\#n()'
208
+ refute_ref '#n(*)', '\#n(*)'
209
+
210
+ refute_ref 'C1', '\C1'
211
+ refute_ref '::C3', '\::C3'
212
+
213
+ refute_ref '::C3::H1#n', '::C3::H1#n'
214
+ refute_ref '::C3::H1#n(*)', '::C3::H1#n(*)'
215
+ refute_ref '::C3::H1#n', '\::C3::H1#n'
216
+ end
217
+
218
+ def test_handle_special_CROSSREF_special
219
+ assert_equal "<p>\n<a href=\"classes/C2/C3.html\">C2::C3</a>;method(*)\n</p>\n",
220
+ @xref.convert('C2::C3;method(*)')
221
+ end
222
+
288
223
  end
224
+
225
+ MiniTest::Unit.autorun