rdoc 3.9.5 → 3.10.pre.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.

Files changed (183) hide show
  1. data.tar.gz.sig +0 -0
  2. data/.autotest +6 -3
  3. data/History.txt +63 -13
  4. data/LICENSE.rdoc +57 -0
  5. data/Manifest.txt +60 -6
  6. data/Rakefile +24 -12
  7. data/TODO.rdoc +30 -0
  8. data/bin/rdoc +0 -2
  9. data/lib/rdoc.rb +55 -2
  10. data/lib/rdoc/alias.rb +0 -2
  11. data/lib/rdoc/anon_class.rb +0 -2
  12. data/lib/rdoc/any_method.rb +0 -3
  13. data/lib/rdoc/attr.rb +0 -2
  14. data/lib/rdoc/class_module.rb +40 -7
  15. data/lib/rdoc/code_object.rb +1 -3
  16. data/lib/rdoc/code_objects.rb +3 -21
  17. data/lib/rdoc/comment.rb +225 -0
  18. data/lib/rdoc/constant.rb +0 -2
  19. data/lib/rdoc/context.rb +37 -120
  20. data/lib/rdoc/context/section.rb +114 -0
  21. data/lib/rdoc/cross_reference.rb +16 -7
  22. data/lib/rdoc/encoding.rb +0 -2
  23. data/lib/rdoc/gauntlet.rb +1 -1
  24. data/lib/rdoc/generator.rb +7 -2
  25. data/lib/rdoc/generator/darkfish.rb +126 -20
  26. data/lib/rdoc/generator/json_index.rb +240 -0
  27. data/lib/rdoc/generator/markup.rb +17 -54
  28. data/lib/rdoc/generator/ri.rb +0 -3
  29. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +5 -0
  30. data/lib/rdoc/generator/template/darkfish/_head.rhtml +16 -0
  31. data/lib/rdoc/generator/template/darkfish/_sidebar_VCS_info.rhtml +18 -0
  32. data/lib/rdoc/generator/template/darkfish/_sidebar_classes.rhtml +9 -0
  33. data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +8 -0
  34. data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +16 -0
  35. data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +12 -0
  36. data/lib/rdoc/generator/template/darkfish/_sidebar_navigation.rhtml +7 -0
  37. data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +12 -0
  38. data/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml +10 -0
  39. data/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml +10 -0
  40. data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +10 -0
  41. data/lib/rdoc/generator/template/darkfish/class.rhtml +161 -0
  42. data/lib/rdoc/generator/template/darkfish/fileinfo.rhtml +32 -0
  43. data/lib/rdoc/generator/template/darkfish/images/add.png +0 -0
  44. data/lib/rdoc/generator/template/darkfish/images/delete.png +0 -0
  45. data/lib/rdoc/generator/template/darkfish/images/tag_blue.png +0 -0
  46. data/lib/rdoc/generator/template/darkfish/images/transparent.png +0 -0
  47. data/lib/rdoc/generator/template/darkfish/index.rhtml +16 -61
  48. data/lib/rdoc/generator/template/darkfish/js/darkfish.js +99 -64
  49. data/lib/rdoc/generator/template/darkfish/js/jquery.js +15 -29
  50. data/lib/rdoc/generator/template/darkfish/js/search.js +94 -0
  51. data/lib/rdoc/generator/template/darkfish/page.rhtml +16 -0
  52. data/lib/rdoc/generator/template/darkfish/rdoc.css +126 -286
  53. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +50 -0
  54. data/lib/rdoc/generator/template/json_index/js/navigation.js +142 -0
  55. data/lib/rdoc/generator/template/json_index/js/searcher.js +228 -0
  56. data/lib/rdoc/ghost_method.rb +0 -2
  57. data/lib/rdoc/include.rb +0 -2
  58. data/lib/rdoc/markup.rb +204 -43
  59. data/lib/rdoc/markup/attr_changer.rb +25 -0
  60. data/lib/rdoc/markup/attr_span.rb +29 -0
  61. data/lib/rdoc/markup/attribute.rb +51 -0
  62. data/lib/rdoc/markup/document.rb +22 -1
  63. data/lib/rdoc/markup/formatter.rb +4 -11
  64. data/lib/rdoc/markup/formatter_test_case.rb +1 -2
  65. data/lib/rdoc/markup/heading.rb +44 -0
  66. data/lib/rdoc/markup/include.rb +42 -0
  67. data/lib/rdoc/markup/inline.rb +1 -144
  68. data/lib/rdoc/markup/list.rb +2 -1
  69. data/lib/rdoc/markup/parser.rb +6 -16
  70. data/lib/rdoc/markup/pre_process.rb +64 -10
  71. data/lib/rdoc/markup/raw.rb +1 -1
  72. data/lib/rdoc/markup/special.rb +40 -0
  73. data/lib/rdoc/markup/text_formatter_test_case.rb +0 -2
  74. data/lib/rdoc/markup/to_ansi.rb +0 -2
  75. data/lib/rdoc/markup/to_bs.rb +0 -2
  76. data/lib/rdoc/markup/to_html.rb +102 -34
  77. data/lib/rdoc/markup/to_html_crossref.rb +36 -5
  78. data/lib/rdoc/markup/to_html_snippet.rb +270 -0
  79. data/lib/rdoc/markup/to_label.rb +55 -0
  80. data/lib/rdoc/markup/to_rdoc.rb +0 -3
  81. data/lib/rdoc/markup/to_table_of_contents.rb +62 -0
  82. data/lib/rdoc/markup/to_test.rb +0 -3
  83. data/lib/rdoc/markup/to_tt_only.rb +0 -3
  84. data/lib/rdoc/markup/verbatim.rb +18 -0
  85. data/lib/rdoc/meta_method.rb +0 -2
  86. data/lib/rdoc/method_attr.rb +17 -1
  87. data/lib/rdoc/normal_class.rb +0 -2
  88. data/lib/rdoc/normal_module.rb +0 -2
  89. data/lib/rdoc/options.rb +18 -3
  90. data/lib/rdoc/parser.rb +74 -42
  91. data/lib/rdoc/parser/c.rb +79 -118
  92. data/lib/rdoc/parser/rd.rb +22 -0
  93. data/lib/rdoc/parser/ruby.rb +86 -54
  94. data/lib/rdoc/parser/simple.rb +21 -9
  95. data/lib/rdoc/parser/text.rb +11 -0
  96. data/lib/rdoc/rd.rb +95 -0
  97. data/lib/rdoc/rd/block_parser.ry +638 -0
  98. data/lib/rdoc/rd/inline.rb +71 -0
  99. data/lib/rdoc/rd/inline_parser.ry +575 -0
  100. data/lib/rdoc/rdoc.rb +8 -23
  101. data/lib/rdoc/require.rb +0 -2
  102. data/lib/rdoc/ri.rb +4 -2
  103. data/lib/rdoc/ri/driver.rb +2 -6
  104. data/lib/rdoc/ri/store.rb +0 -1
  105. data/lib/rdoc/ruby_lex.rb +43 -20
  106. data/lib/rdoc/ruby_token.rb +44 -2
  107. data/lib/rdoc/single_class.rb +0 -2
  108. data/lib/rdoc/stats.rb +0 -5
  109. data/lib/rdoc/task.rb +2 -6
  110. data/lib/rdoc/test_case.rb +59 -0
  111. data/lib/rdoc/text.rb +42 -30
  112. data/lib/rdoc/token_stream.rb +45 -0
  113. data/lib/rdoc/tom_doc.rb +232 -0
  114. data/lib/rdoc/top_level.rb +36 -4
  115. data/test/test_attribute_manager.rb +26 -29
  116. data/test/test_rdoc_any_method.rb +2 -26
  117. data/test/test_rdoc_attr.rb +4 -4
  118. data/test/test_rdoc_class_module.rb +95 -12
  119. data/test/test_rdoc_code_object.rb +10 -3
  120. data/test/test_rdoc_comment.rb +504 -0
  121. data/test/test_rdoc_context.rb +60 -11
  122. data/test/test_rdoc_context_section.rb +16 -17
  123. data/test/test_rdoc_cross_reference.rb +17 -2
  124. data/test/test_rdoc_encoding.rb +4 -7
  125. data/test/test_rdoc_generator_darkfish.rb +12 -11
  126. data/test/test_rdoc_generator_json_index.rb +255 -0
  127. data/test/test_rdoc_generator_markup.rb +56 -0
  128. data/test/test_rdoc_generator_ri.rb +8 -11
  129. data/test/test_rdoc_markup.rb +9 -5
  130. data/test/test_rdoc_markup_attribute_manager.rb +5 -8
  131. data/test/test_rdoc_markup_document.rb +34 -6
  132. data/test/test_rdoc_markup_formatter.rb +11 -13
  133. data/test/test_rdoc_markup_heading.rb +20 -0
  134. data/test/test_rdoc_markup_include.rb +19 -0
  135. data/test/test_rdoc_markup_indented_paragraph.rb +4 -5
  136. data/test/test_rdoc_markup_paragraph.rb +2 -5
  137. data/test/test_rdoc_markup_parser.rb +87 -7
  138. data/test/test_rdoc_markup_pre_process.rb +60 -9
  139. data/test/test_rdoc_markup_raw.rb +4 -6
  140. data/test/test_rdoc_markup_to_ansi.rb +1 -4
  141. data/test/test_rdoc_markup_to_bs.rb +1 -4
  142. data/test/test_rdoc_markup_to_html.rb +170 -31
  143. data/test/test_rdoc_markup_to_html_crossref.rb +89 -11
  144. data/test/test_rdoc_markup_to_html_snippet.rb +668 -0
  145. data/test/test_rdoc_markup_to_label.rb +50 -0
  146. data/test/test_rdoc_markup_to_rdoc.rb +1 -4
  147. data/test/test_rdoc_markup_to_table_of_contents.rb +90 -0
  148. data/test/test_rdoc_markup_to_tt_only.rb +1 -4
  149. data/test/test_rdoc_markup_verbatim.rb +16 -0
  150. data/test/test_rdoc_method_attr.rb +16 -1
  151. data/test/test_rdoc_options.rb +17 -7
  152. data/test/test_rdoc_parser.rb +75 -6
  153. data/test/test_rdoc_parser_c.rb +56 -104
  154. data/test/test_rdoc_parser_rd.rb +52 -0
  155. data/test/test_rdoc_parser_ruby.rb +264 -323
  156. data/test/test_rdoc_parser_simple.rb +33 -17
  157. data/test/test_rdoc_rd.rb +30 -0
  158. data/test/test_rdoc_rd_block_parser.rb +527 -0
  159. data/test/test_rdoc_rd_inline.rb +63 -0
  160. data/test/test_rdoc_rd_inline_parser.rb +173 -0
  161. data/test/test_rdoc_rdoc.rb +7 -9
  162. data/test/test_rdoc_ri_driver.rb +10 -15
  163. data/test/test_rdoc_ri_paths.rb +6 -6
  164. data/test/test_rdoc_ri_store.rb +6 -13
  165. data/test/test_rdoc_ruby_lex.rb +53 -5
  166. data/test/test_rdoc_rubygems_hook.rb +2 -1
  167. data/test/test_rdoc_stats.rb +83 -103
  168. data/test/test_rdoc_task.rb +5 -4
  169. data/test/test_rdoc_text.rb +156 -11
  170. data/test/test_rdoc_token_stream.rb +42 -0
  171. data/test/test_rdoc_tom_doc.rb +458 -0
  172. data/test/test_rdoc_top_level.rb +49 -2
  173. data/test/xref_test_case.rb +4 -8
  174. metadata +217 -111
  175. metadata.gz.sig +0 -0
  176. checksums.yaml +0 -7
  177. checksums.yaml.gz.sig +0 -0
  178. data/CVE-2013-0256.rdoc +0 -49
  179. data/LICENSE.txt +0 -57
  180. data/lib/rdoc/generator/template/darkfish/classpage.rhtml +0 -321
  181. data/lib/rdoc/generator/template/darkfish/filepage.rhtml +0 -124
  182. data/lib/rdoc/generator/template/darkfish/js/quicksearch.js +0 -114
  183. data/lib/rdoc/generator/template/darkfish/js/thickbox-compressed.js +0 -10
@@ -1,5 +1,3 @@
1
- require 'rdoc/context'
2
-
3
1
  ##
4
2
  # A TopLevel context is a representation of the contents of a single file
5
3
 
@@ -118,7 +116,7 @@ class RDoc::TopLevel < RDoc::Context
118
116
  @all_files_hash.each_key do |file_name|
119
117
  tl = @all_files_hash[file_name]
120
118
 
121
- unless RDoc::Parser::Simple === tl.parser then
119
+ unless tl.text? then
122
120
  tl.modules_hash.clear
123
121
  tl.classes_hash.clear
124
122
 
@@ -313,7 +311,7 @@ class RDoc::TopLevel < RDoc::Context
313
311
  # An RDoc::TopLevel is equal to another with the same absolute_name
314
312
 
315
313
  def == other
316
- other.class === self and @absolute_name == other.absolute_name
314
+ self.class === other and @absolute_name == other.absolute_name
317
315
  end
318
316
 
319
317
  alias eql? ==
@@ -448,6 +446,16 @@ class RDoc::TopLevel < RDoc::Context
448
446
  end
449
447
  end
450
448
 
449
+ ##
450
+ # Base name of this file without the extension
451
+
452
+ def page_name
453
+ basename = File.basename @absolute_name
454
+ basename =~ /\.[^.]*$/
455
+
456
+ $` || basename
457
+ end
458
+
451
459
  ##
452
460
  # Path to this file
453
461
 
@@ -466,6 +474,30 @@ class RDoc::TopLevel < RDoc::Context
466
474
  end
467
475
  end
468
476
 
477
+ ##
478
+ # Search record used by RDoc::Generator::JsonIndex
479
+
480
+ def search_record
481
+ return unless @parser < RDoc::Parser::Text
482
+
483
+ [
484
+ page_name,
485
+ '',
486
+ page_name,
487
+ '',
488
+ path,
489
+ '',
490
+ snippet(@comment),
491
+ ]
492
+ end
493
+
494
+ ##
495
+ # Is this TopLevel from a text file instead of a source code file?
496
+
497
+ def text?
498
+ @parser.ancestors.include? RDoc::Parser::Text
499
+ end
500
+
469
501
  def to_s # :nodoc:
470
502
  "file #{full_name}"
471
503
  end
@@ -1,27 +1,24 @@
1
- require 'rubygems'
2
- require 'minitest/autorun'
3
- require 'rdoc'
4
- require 'rdoc/markup'
5
- require 'rdoc/markup/formatter'
6
- require 'rdoc/markup/attribute_manager'
1
+ require 'rdoc/test_case'
7
2
 
8
- class TestAttributeManager < MiniTest::Unit::TestCase # HACK fix test name
3
+ class TestAttributeManager < RDoc::TestCase # HACK fix test name
9
4
 
10
5
  def setup
6
+ super
7
+
11
8
  @am = RDoc::Markup::AttributeManager.new
12
9
  @klass = RDoc::Markup::AttributeManager
13
10
  @formatter = RDoc::Markup::Formatter.new
14
11
  @formatter.add_tag :BOLD, '<B>', '</B>'
15
12
  @formatter.add_tag :EM, '<EM>', '</EM>'
16
- @formatter.add_tag :TT, '<TT>', '</TT>'
13
+ @formatter.add_tag :TT, '<CODE>', '</CODE>'
17
14
  end
18
15
 
19
16
  def test_convert_attrs_ignores_code
20
- assert_equal 'foo <TT>__send__</TT> bar', output('foo <code>__send__</code> bar')
17
+ assert_equal 'foo <CODE>__send__</CODE> bar', output('foo <code>__send__</code> bar')
21
18
  end
22
19
 
23
20
  def test_convert_attrs_ignores_tt
24
- assert_equal 'foo <TT>__send__</TT> bar', output('foo <tt>__send__</tt> bar')
21
+ assert_equal 'foo <CODE>__send__</CODE> bar', output('foo <tt>__send__</tt> bar')
25
22
  end
26
23
 
27
24
  def test_convert_attrs_preserves_double
@@ -30,7 +27,7 @@ class TestAttributeManager < MiniTest::Unit::TestCase # HACK fix test name
30
27
  end
31
28
 
32
29
  def test_convert_attrs_does_not_ignore_after_tt
33
- assert_equal 'the <TT>IF:</TT><EM>key</EM> directive', output('the <tt>IF:</tt>_key_ directive')
30
+ assert_equal 'the <CODE>IF:</CODE><EM>key</EM> directive', output('the <tt>IF:</tt>_key_ directive')
34
31
  end
35
32
 
36
33
  def test_initial_word_pairs
@@ -80,31 +77,31 @@ class TestAttributeManager < MiniTest::Unit::TestCase # HACK fix test name
80
77
  end
81
78
 
82
79
  def test_escapes
83
- assert_equal '<TT>text</TT>', output('<tt>text</tt>')
84
- assert_equal '<tt>text</tt>', output('\\<tt>text</tt>')
85
- assert_equal '<tt>', output('\\<tt>')
86
- assert_equal '<TT><tt></TT>', output('<tt>\\<tt></tt>')
87
- assert_equal '<TT>\\<tt></TT>', output('<tt>\\\\<tt></tt>')
88
- assert_equal '<B>text</B>', output('*text*')
89
- assert_equal '*text*', output('\\*text*')
90
- assert_equal '\\', output('\\')
91
- assert_equal '\\text', output('\\text')
92
- assert_equal '\\\\text', output('\\\\text')
93
- assert_equal 'text \\ text', output('text \\ text')
94
-
95
- assert_equal 'and <TT>\\s</TT> matches space',
80
+ assert_equal '<CODE>text</CODE>', output('<tt>text</tt>')
81
+ assert_equal '<tt>text</tt>', output('\\<tt>text</tt>')
82
+ assert_equal '<tt>', output('\\<tt>')
83
+ assert_equal '<CODE><tt></CODE>', output('<tt>\\<tt></tt>')
84
+ assert_equal '<CODE>\\<tt></CODE>', output('<tt>\\\\<tt></tt>')
85
+ assert_equal '<B>text</B>', output('*text*')
86
+ assert_equal '*text*', output('\\*text*')
87
+ assert_equal '\\', output('\\')
88
+ assert_equal '\\text', output('\\text')
89
+ assert_equal '\\\\text', output('\\\\text')
90
+ assert_equal 'text \\ text', output('text \\ text')
91
+
92
+ assert_equal 'and <CODE>\\s</CODE> matches space',
96
93
  output('and <tt>\\s</tt> matches space')
97
- assert_equal 'use <TT><tt>text</TT></tt> for code',
94
+ assert_equal 'use <CODE><tt>text</CODE></tt> for code',
98
95
  output('use <tt>\\<tt>text</tt></tt> for code')
99
- assert_equal 'use <TT><tt>text</tt></TT> for code',
96
+ assert_equal 'use <CODE><tt>text</tt></CODE> for code',
100
97
  output('use <tt>\\<tt>text\\</tt></tt> for code')
101
98
  assert_equal 'use <tt><tt>text</tt></tt> for code',
102
99
  output('use \\<tt>\\<tt>text</tt></tt> for code')
103
- assert_equal 'use <tt><TT>text</TT></tt> for code',
100
+ assert_equal 'use <tt><CODE>text</CODE></tt> for code',
104
101
  output('use \\<tt><tt>text</tt></tt> for code')
105
- assert_equal 'use <TT>+text+</TT> for code',
102
+ assert_equal 'use <CODE>+text+</CODE> for code',
106
103
  output('use <tt>\\+text+</tt> for code')
107
- assert_equal 'use <tt><TT>text</TT></tt> for code',
104
+ assert_equal 'use <tt><CODE>text</CODE></tt> for code',
108
105
  output('use \\<tt>+text+</tt> for code')
109
106
  assert_equal 'illegal <tag>not</tag> changed',
110
107
  output('illegal <tag>not</tag> changed')
@@ -1,8 +1,6 @@
1
1
  require File.expand_path '../xref_test_case', __FILE__
2
- require 'rdoc/code_objects'
3
- require 'rdoc/generator/markup'
4
2
 
5
- class RDocAnyMethodTest < XrefTestCase
3
+ class TestRDocAnyMethod < XrefTestCase
6
4
 
7
5
  def test_aref
8
6
  m = RDoc::AnyMethod.new nil, 'method?'
@@ -47,34 +45,12 @@ method(a, b) { |c, d| ... }
47
45
  def test_markup_code
48
46
  tokens = [
49
47
  RDoc::RubyToken::TkCONSTANT. new(0, 0, 0, 'CONSTANT'),
50
- RDoc::RubyToken::TkDEF. new(0, 0, 0, 'KW'),
51
- RDoc::RubyToken::TkIVAR. new(0, 0, 0, 'IVAR'),
52
- RDoc::RubyToken::TkOp. new(0, 0, 0, 'Op'),
53
- RDoc::RubyToken::TkId. new(0, 0, 0, 'Id'),
54
- RDoc::RubyToken::TkNode. new(0, 0, 0, 'Node'),
55
- RDoc::RubyToken::TkCOMMENT. new(0, 0, 0, 'COMMENT'),
56
- RDoc::RubyToken::TkREGEXP. new(0, 0, 0, 'REGEXP'),
57
- RDoc::RubyToken::TkSTRING. new(0, 0, 0, 'STRING'),
58
- RDoc::RubyToken::TkVal. new(0, 0, 0, 'Val'),
59
- RDoc::RubyToken::TkBACKSLASH.new(0, 0, 0, '\\'),
60
48
  ]
61
49
 
62
50
  @c2_a.collect_tokens
63
51
  @c2_a.add_tokens(*tokens)
64
52
 
65
- expected = [
66
- '<span class="ruby-constant">CONSTANT</span>',
67
- '<span class="ruby-keyword">KW</span>',
68
- '<span class="ruby-ivar">IVAR</span>',
69
- '<span class="ruby-operator">Op</span>',
70
- '<span class="ruby-identifier">Id</span>',
71
- '<span class="ruby-node">Node</span>',
72
- '<span class="ruby-comment">COMMENT</span>',
73
- '<span class="ruby-regexp">REGEXP</span>',
74
- '<span class="ruby-string">STRING</span>',
75
- '<span class="ruby-value">Val</span>',
76
- '\\'
77
- ].join
53
+ expected = '<span class="ruby-constant">CONSTANT</span>'
78
54
 
79
55
  assert_equal expected, @c2_a.markup_code
80
56
  end
@@ -1,10 +1,10 @@
1
- require 'rubygems'
2
- require 'minitest/autorun'
3
- require 'rdoc/rdoc'
1
+ require 'rdoc/test_case'
4
2
 
5
- class TestRDocAttr < MiniTest::Unit::TestCase
3
+ class TestRDocAttr < RDoc::TestCase
6
4
 
7
5
  def setup
6
+ super
7
+
8
8
  @a = RDoc::Attr.new nil, 'attr', 'RW', ''
9
9
  end
10
10
 
@@ -1,14 +1,7 @@
1
- require 'pp'
2
1
  require File.expand_path '../xref_test_case', __FILE__
3
2
 
4
3
  class TestRDocClassModule < XrefTestCase
5
4
 
6
- def setup
7
- super
8
-
9
- @RM = RDoc::Markup
10
- end
11
-
12
5
  def mu_pp obj
13
6
  s = ''
14
7
  s = PP.pp obj, s
@@ -40,6 +33,14 @@ class TestRDocClassModule < XrefTestCase
40
33
  assert_equal "comment 1\n---\ncomment 2\n---\n* comment 3", cm.comment
41
34
  end
42
35
 
36
+ def test_add_comment_comment
37
+ cm = RDoc::ClassModule.new 'Klass'
38
+
39
+ cm.add_comment comment('comment'), @top_level
40
+
41
+ assert_equal 'comment', cm.comment.text
42
+ end
43
+
43
44
  def test_add_comment_stopdoc
44
45
  tl = RDoc::TopLevel.new 'file.rb'
45
46
 
@@ -70,6 +71,30 @@ class TestRDocClassModule < XrefTestCase
70
71
  assert_equal "comment 1\n---\ncomment 2\n---\n* comment 3", cm.comment
71
72
  end
72
73
 
74
+ def test_comment_equals_comment
75
+ cm = RDoc::ClassModule.new 'Klass'
76
+
77
+ cm.comment = comment 'comment'
78
+
79
+ assert_equal 'comment', cm.comment.text
80
+ end
81
+
82
+ def test_docuent_self_or_methods
83
+ assert @c1.document_self_or_methods
84
+
85
+ @c1.document_self = false
86
+
87
+ assert @c1.document_self_or_methods
88
+
89
+ @c1_m.document_self = false
90
+
91
+ assert @c1.document_self_or_methods
92
+
93
+ @c1__m.document_self = false
94
+
95
+ refute @c1.document_self_or_methods
96
+ end
97
+
73
98
  def test_each_ancestor
74
99
  ancestors = []
75
100
 
@@ -133,7 +158,7 @@ class TestRDocClassModule < XrefTestCase
133
158
 
134
159
  inner = RDoc::Markup::Document.new(
135
160
  RDoc::Markup::Paragraph.new('this is a comment'))
136
- inner.file = tl.absolute_name
161
+ inner.file = tl
137
162
 
138
163
  comment = RDoc::Markup::Document.new inner
139
164
 
@@ -550,15 +575,40 @@ class TestRDocClassModule < XrefTestCase
550
575
  cm.add_comment 'comment 2', tl2
551
576
 
552
577
  doc1 = @RM::Document.new @RM::Paragraph.new 'comment 1'
553
- doc1.file = tl1.absolute_name
578
+ doc1.file = tl1
554
579
  doc2 = @RM::Document.new @RM::Paragraph.new 'comment 2'
555
- doc2.file = tl2.absolute_name
580
+ doc2.file = tl2
556
581
 
557
582
  expected = @RM::Document.new doc1, doc2
558
583
 
559
584
  assert_equal expected, cm.parse(cm.comment_location)
560
585
  end
561
586
 
587
+ def test_parse_comment
588
+ tl1 = RDoc::TopLevel.new 'one.rb'
589
+
590
+ cm = RDoc::ClassModule.new 'Klass'
591
+ cm.comment = comment 'comment 1', tl1
592
+
593
+ doc = @RM::Document.new @RM::Paragraph.new 'comment 1'
594
+ doc.file = tl1
595
+
596
+ assert_equal doc, cm.parse(cm.comment)
597
+ end
598
+
599
+ def test_parse_comment_format
600
+ tl1 = RDoc::TopLevel.new 'one.rb'
601
+
602
+ cm = RDoc::ClassModule.new 'Klass'
603
+ cm.comment = comment 'comment ((*1*))', tl1
604
+ cm.comment.format = 'rd'
605
+
606
+ doc = @RM::Document.new @RM::Paragraph.new 'comment <em>1</em>'
607
+ doc.file = tl1
608
+
609
+ assert_equal doc, cm.parse(cm.comment)
610
+ end
611
+
562
612
  def test_parse_comment_location
563
613
  tl1 = RDoc::TopLevel.new 'one.rb'
564
614
  tl2 = RDoc::TopLevel.new 'two.rb'
@@ -570,9 +620,9 @@ class TestRDocClassModule < XrefTestCase
570
620
  cm = Marshal.load Marshal.dump cm
571
621
 
572
622
  doc1 = @RM::Document.new @RM::Paragraph.new 'comment 1'
573
- doc1.file = tl1.absolute_name
623
+ doc1.file = tl1
574
624
  doc2 = @RM::Document.new @RM::Paragraph.new 'comment 2'
575
- doc2.file = tl2.absolute_name
625
+ doc2.file = tl2
576
626
 
577
627
  assert_same cm.comment_location, cm.parse(cm.comment_location)
578
628
  end
@@ -591,6 +641,39 @@ class TestRDocClassModule < XrefTestCase
591
641
  assert_equal %w[D], parent.classes_hash.keys
592
642
  end
593
643
 
644
+ def test_search_record
645
+ @c2_c3.add_comment 'This is a comment.', @xref_data
646
+
647
+ expected = [
648
+ 'C3',
649
+ 'C2::C3',
650
+ 'C2::C3',
651
+ '',
652
+ 'C2/C3.html',
653
+ '',
654
+ "<p>This is a comment.\n"
655
+ ]
656
+
657
+ assert_equal expected, @c2_c3.search_record
658
+ end
659
+
660
+ def test_search_record_merged
661
+ @c2_c3.add_comment 'comment A', RDoc::TopLevel.new('a.rb')
662
+ @c2_c3.add_comment 'comment B', RDoc::TopLevel.new('b.rb')
663
+
664
+ expected = [
665
+ 'C3',
666
+ 'C2::C3',
667
+ 'C2::C3',
668
+ '',
669
+ 'C2/C3.html',
670
+ '',
671
+ "<p>comment A\n<p>comment B\n"
672
+ ]
673
+
674
+ assert_equal expected, @c2_c3.search_record
675
+ end
676
+
594
677
  def test_superclass
595
678
  assert_equal @c3_h1, @c3_h2.superclass
596
679
  end
@@ -1,9 +1,6 @@
1
1
  # coding: US-ASCII
2
2
 
3
- require 'rubygems'
4
- require 'minitest/autorun'
5
3
  require File.expand_path '../xref_test_case', __FILE__
6
- require 'rdoc/code_object'
7
4
 
8
5
  class TestRDocCodeObject < XrefTestCase
9
6
 
@@ -32,6 +29,16 @@ class TestRDocCodeObject < XrefTestCase
32
29
  assert_equal 'I am a comment', @co.comment
33
30
  end
34
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
+
35
42
  def test_comment_equals_document
36
43
  doc = RDoc::Markup::Document.new
37
44
  @co.comment = doc
@@ -0,0 +1,504 @@
1
+ # coding: us-ascii
2
+
3
+ require 'rdoc/test_case'
4
+
5
+ class TestRDocComment < RDoc::TestCase
6
+
7
+ def setup
8
+ super
9
+
10
+ @top_level = RDoc::TopLevel.new 'file.rb'
11
+ @comment = RDoc::Comment.new
12
+ @comment.location = @top_level
13
+ @comment.text = 'this is a comment'
14
+ end
15
+
16
+ def test_empty_eh
17
+ refute_empty @comment
18
+
19
+ @comment = ''
20
+
21
+ assert_empty @comment
22
+ end
23
+
24
+ def test_equals2
25
+ assert_equal @comment, @comment.dup
26
+
27
+ c2 = @comment.dup
28
+ c2.text = nil
29
+
30
+ refute_equal @comment, c2
31
+
32
+ c3 = @comment.dup
33
+ c3.location = nil
34
+
35
+ refute_equal @comment, c3
36
+ end
37
+
38
+ def test_extract_call_seq
39
+ m = RDoc::AnyMethod.new nil, 'm'
40
+
41
+ comment = RDoc::Comment.new <<-COMMENT, @top_level
42
+ call-seq:
43
+ bla => true or false
44
+
45
+ moar comment
46
+ COMMENT
47
+
48
+ comment.extract_call_seq m
49
+
50
+ assert_equal "bla => true or false\n", m.call_seq
51
+ end
52
+
53
+ def test_extract_call_seq_blank
54
+ m = RDoc::AnyMethod.new nil, 'm'
55
+
56
+ comment = RDoc::Comment.new <<-COMMENT, @top_level
57
+ call-seq:
58
+ bla => true or false
59
+
60
+ COMMENT
61
+
62
+ comment.extract_call_seq m
63
+
64
+ assert_equal "bla => true or false\n", m.call_seq
65
+ end
66
+
67
+ def test_extract_call_seq_commented
68
+ m = RDoc::AnyMethod.new nil, 'm'
69
+
70
+ comment = RDoc::Comment.new <<-COMMENT, @top_level
71
+ # call-seq:
72
+ # bla => true or false
73
+ #
74
+ # moar comment
75
+ COMMENT
76
+
77
+ comment.extract_call_seq m
78
+
79
+ assert_equal nil, m.call_seq
80
+ end
81
+
82
+ def test_extract_call_seq_no_blank
83
+ m = RDoc::AnyMethod.new nil, 'm'
84
+
85
+ comment = RDoc::Comment.new <<-COMMENT, @top_level
86
+ call-seq:
87
+ bla => true or false
88
+ COMMENT
89
+
90
+ comment.extract_call_seq m
91
+
92
+ assert_equal "bla => true or false\n", m.call_seq
93
+ end
94
+
95
+ def test_extract_call_seq_undent
96
+ m = RDoc::AnyMethod.new nil, 'm'
97
+
98
+ comment = RDoc::Comment.new <<-COMMENT, @top_level
99
+ call-seq:
100
+ bla => true or false
101
+ moar comment
102
+ COMMENT
103
+
104
+ comment.extract_call_seq m
105
+
106
+ assert_equal "bla => true or false\nmoar comment\n", m.call_seq
107
+ end
108
+
109
+ def test_extract_call_seq_c
110
+ comment = RDoc::Comment.new <<-COMMENT
111
+ call-seq:
112
+ commercial() -> Date <br />
113
+ commercial(cwyear, cweek=41, cwday=5, sg=nil) -> Date [ruby 1.8] <br />
114
+ commercial(cwyear, cweek=1, cwday=1, sg=nil) -> Date [ruby 1.9]
115
+
116
+ If no arguments are given:
117
+ * ruby 1.8: returns a +Date+ for 1582-10-15 (the Day of Calendar Reform in
118
+ Italy)
119
+ * ruby 1.9: returns a +Date+ for julian day 0
120
+
121
+ Otherwise, returns a +Date+ for the commercial week year, commercial week,
122
+ and commercial week day given. Ignores the 4th argument.
123
+ COMMENT
124
+
125
+ method_obj = RDoc::AnyMethod.new nil, 'blah'
126
+
127
+ comment.extract_call_seq method_obj
128
+
129
+ expected = <<-CALL_SEQ.chomp
130
+ commercial() -> Date <br />
131
+ commercial(cwyear, cweek=41, cwday=5, sg=nil) -> Date [ruby 1.8] <br />
132
+ commercial(cwyear, cweek=1, cwday=1, sg=nil) -> Date [ruby 1.9]
133
+
134
+ CALL_SEQ
135
+
136
+ assert_equal expected, method_obj.call_seq
137
+ end
138
+
139
+ def test_extract_call_seq_c_no_blank
140
+ comment = RDoc::Comment.new <<-COMMENT
141
+ call-seq:
142
+ commercial() -> Date <br />
143
+ commercial(cwyear, cweek=41, cwday=5, sg=nil) -> Date [ruby 1.8] <br />
144
+ commercial(cwyear, cweek=1, cwday=1, sg=nil) -> Date [ruby 1.9]
145
+ COMMENT
146
+
147
+ method_obj = RDoc::AnyMethod.new nil, 'blah'
148
+
149
+ comment.extract_call_seq method_obj
150
+
151
+ expected = <<-CALL_SEQ.chomp
152
+ commercial() -> Date <br />
153
+ commercial(cwyear, cweek=41, cwday=5, sg=nil) -> Date [ruby 1.8] <br />
154
+ commercial(cwyear, cweek=1, cwday=1, sg=nil) -> Date [ruby 1.9]
155
+
156
+ CALL_SEQ
157
+
158
+ assert_equal expected, method_obj.call_seq
159
+ end
160
+
161
+ def test_extract_call_seq_c_separator
162
+ comment = RDoc::Comment.new <<-'COMMENT'
163
+ call-seq:
164
+ ARGF.readlines(sep=$/) -> array
165
+ ARGF.readlines(limit) -> array
166
+ ARGF.readlines(sep, limit) -> array
167
+
168
+ ARGF.to_a(sep=$/) -> array
169
+ ARGF.to_a(limit) -> array
170
+ ARGF.to_a(sep, limit) -> array
171
+
172
+ Reads +ARGF+'s current file in its entirety, returning an +Array+ of its
173
+ lines, one line per element. Lines are assumed to be separated by _sep_.
174
+
175
+ lines = ARGF.readlines
176
+ lines[0] #=> "This is line one\n"
177
+
178
+ COMMENT
179
+
180
+ method_obj = RDoc::AnyMethod.new nil, 'blah'
181
+
182
+ comment.extract_call_seq method_obj
183
+
184
+ expected = <<-CALL_SEQ
185
+ ARGF.readlines(sep=$/) -> array
186
+ ARGF.readlines(limit) -> array
187
+ ARGF.readlines(sep, limit) -> array
188
+ ARGF.to_a(sep=$/) -> array
189
+ ARGF.to_a(limit) -> array
190
+ ARGF.to_a(sep, limit) -> array
191
+ CALL_SEQ
192
+
193
+ assert_equal expected, method_obj.call_seq
194
+
195
+ expected = <<-'COMMENT'
196
+
197
+ Reads +ARGF+'s current file in its entirety, returning an +Array+ of its
198
+ lines, one line per element. Lines are assumed to be separated by _sep_.
199
+
200
+ lines = ARGF.readlines
201
+ lines[0] #=> "This is line one\n"
202
+
203
+ COMMENT
204
+
205
+ assert_equal expected, comment.text
206
+ end
207
+
208
+ def test_force_encoding
209
+ skip "Encoding not implemented" unless Object.const_defined? :Encoding
210
+
211
+ @comment.force_encoding Encoding::UTF_8
212
+
213
+ assert_equal Encoding::UTF_8, @comment.text.encoding
214
+ end
215
+
216
+ def test_format
217
+ assert_equal 'rdoc', @comment.format
218
+ end
219
+
220
+ def test_format_equals
221
+ c = comment 'content'
222
+ document = c.parse
223
+
224
+ c.format = RDoc::RD
225
+
226
+ assert_equal RDoc::RD, c.format
227
+ refute_same document, c.parse
228
+ end
229
+
230
+ def test_initialize_copy
231
+ copy = @comment.dup
232
+
233
+ refute_same @comment.text, copy.text
234
+ assert_same @comment.location, copy.location
235
+ end
236
+
237
+ def test_location
238
+ assert_equal @top_level, @comment.location
239
+ end
240
+
241
+ def test_normalize
242
+ @comment.text = <<-TEXT
243
+ # comment
244
+ TEXT
245
+
246
+ assert_same @comment, @comment.normalize
247
+
248
+ assert_equal 'comment', @comment.text
249
+ end
250
+
251
+ def test_normalize_twice
252
+ @comment.text = <<-TEXT
253
+ # comment
254
+ TEXT
255
+
256
+ @comment.normalize
257
+
258
+ text = @comment.text
259
+
260
+ @comment.normalize
261
+
262
+ assert_same text, @comment.text, 'normalize not cached'
263
+ end
264
+
265
+ def test_normalize_document
266
+ @comment.text = nil
267
+ @comment.document = @RM::Document.new
268
+
269
+ assert_same @comment, @comment.normalize
270
+
271
+ assert_nil @comment.text
272
+ end
273
+
274
+ def test_normalize_eh
275
+ refute @comment.normalized?
276
+
277
+ @comment.normalize
278
+
279
+ assert @comment.normalized?
280
+ end
281
+
282
+ def test_text
283
+ assert_equal 'this is a comment', @comment.text
284
+ end
285
+
286
+ def test_text_equals
287
+ @comment.text = 'other'
288
+
289
+ assert_equal 'other', @comment.text
290
+ refute @comment.normalized?
291
+ end
292
+
293
+ def test_text_equals_no_text
294
+ c = RDoc::Comment.new nil, @top_level
295
+ c.document = @RM::Document.new
296
+
297
+ e = assert_raises RDoc::Error do
298
+ c.text = 'other'
299
+ end
300
+
301
+ assert_equal 'replacing document-only comment is not allowed', e.message
302
+ end
303
+
304
+ def test_text_equals_parsed
305
+ document = @comment.parse
306
+
307
+ @comment.text = 'other'
308
+
309
+ refute_equal document, @comment.parse
310
+ end
311
+
312
+ def test_tomdoc_eh
313
+ refute @comment.tomdoc?
314
+
315
+ @comment.format = 'tomdoc'
316
+
317
+ assert @comment.tomdoc?
318
+ end
319
+
320
+ def test_parse
321
+ parsed = @comment.parse
322
+
323
+ expected = @RM::Document.new(
324
+ @RM::Paragraph.new('this is a comment'))
325
+
326
+ expected.file = @top_level
327
+
328
+ assert_equal expected, parsed
329
+ assert_same parsed, @comment.parse
330
+ end
331
+
332
+ def test_parse_rd
333
+ c = comment 'it ((*works*))'
334
+ c.format = 'rd'
335
+
336
+ expected =
337
+ @RM::Document.new(
338
+ @RM::Paragraph.new('it <em>works</em>'))
339
+ expected.file = @top_level
340
+
341
+ assert_equal expected, c.parse
342
+ end
343
+
344
+ def test_remove_private_encoding
345
+ skip "Encoding not implemented" unless Object.const_defined? :Encoding
346
+
347
+ comment = RDoc::Comment.new <<-EOS, @top_level
348
+ # This is text
349
+ #--
350
+ # this is private
351
+ EOS
352
+
353
+ comment.force_encoding Encoding::IBM437
354
+
355
+ comment.remove_private
356
+
357
+ assert_equal Encoding::IBM437, comment.text.encoding
358
+ end
359
+
360
+ def test_remove_private_hash
361
+ @comment.text = <<-TEXT
362
+ #--
363
+ # private
364
+ #++
365
+ # public
366
+ TEXT
367
+
368
+ @comment.remove_private
369
+
370
+ assert_equal "# public\n", @comment.text
371
+ end
372
+
373
+ def test_remove_private_hash_trail
374
+ comment = RDoc::Comment.new <<-EOS, @top_level
375
+ # This is text
376
+ #--
377
+ # this is private
378
+ EOS
379
+
380
+ expected = RDoc::Comment.new <<-EOS, @top_level
381
+ # This is text
382
+ EOS
383
+
384
+ comment.remove_private
385
+
386
+ assert_equal expected, comment
387
+ end
388
+
389
+ def test_remove_private_long
390
+ comment = RDoc::Comment.new <<-EOS, @top_level
391
+ #-----
392
+ #++
393
+ # this is text
394
+ #-----
395
+ EOS
396
+
397
+ expected = RDoc::Comment.new <<-EOS, @top_level
398
+ # this is text
399
+ EOS
400
+
401
+ comment.remove_private
402
+
403
+ assert_equal expected, comment
404
+ end
405
+
406
+ def test_remove_private_rule
407
+ comment = RDoc::Comment.new <<-EOS, @top_level
408
+ # This is text with a rule:
409
+ # ---
410
+ # this is also text
411
+ EOS
412
+
413
+ expected = comment.dup
414
+
415
+ comment.remove_private
416
+
417
+ assert_equal expected, comment
418
+ end
419
+
420
+ def test_remove_private_star
421
+ @comment.text = <<-TEXT
422
+ /*
423
+ *--
424
+ * private
425
+ *++
426
+ * public
427
+ */
428
+ TEXT
429
+
430
+ @comment.remove_private
431
+
432
+ assert_equal "/*\n * public\n */\n", @comment.text
433
+ end
434
+
435
+ def test_remove_private_star2
436
+ @comment.text = <<-TEXT
437
+ /*--
438
+ * private
439
+ *++
440
+ * public
441
+ */
442
+ TEXT
443
+
444
+ @comment.remove_private
445
+
446
+ assert_equal "/*--\n * private\n *++\n * public\n */\n", @comment.text
447
+ end
448
+
449
+ def test_remove_private_toggle
450
+ comment = RDoc::Comment.new <<-EOS, @top_level
451
+ # This is text
452
+ #--
453
+ # this is private
454
+ #++
455
+ # This is text again.
456
+ EOS
457
+
458
+ expected = RDoc::Comment.new <<-EOS, @top_level
459
+ # This is text
460
+ # This is text again.
461
+ EOS
462
+
463
+ comment.remove_private
464
+
465
+ assert_equal expected, comment
466
+ end
467
+
468
+ def test_remove_private_toggle_encoding
469
+ skip "Encoding not implemented" unless Object.const_defined? :Encoding
470
+
471
+ comment = RDoc::Comment.new <<-EOS, @top_level
472
+ # This is text
473
+ #--
474
+ # this is private
475
+ #++
476
+ # This is text again.
477
+ EOS
478
+
479
+ comment.force_encoding Encoding::IBM437
480
+
481
+ comment.remove_private
482
+
483
+ assert_equal Encoding::IBM437, comment.text.encoding
484
+ end
485
+
486
+ def test_remove_private_toggle_encoding_ruby_bug?
487
+ skip "Encoding not implemented" unless Object.const_defined? :Encoding
488
+
489
+ comment = RDoc::Comment.new <<-EOS, @top_level
490
+ #--
491
+ # this is private
492
+ #++
493
+ # This is text again.
494
+ EOS
495
+
496
+ comment.force_encoding Encoding::IBM437
497
+
498
+ comment.remove_private
499
+
500
+ assert_equal Encoding::IBM437, comment.text.encoding
501
+ end
502
+
503
+ end
504
+