rdoc 3.12.2 → 4.0.0.preview2

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 (200) hide show
  1. checksums.yaml +6 -6
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/.autotest +3 -2
  5. data/DEVELOPERS.rdoc +53 -0
  6. data/History.rdoc +159 -25
  7. data/LEGAL.rdoc +12 -0
  8. data/Manifest.txt +56 -3
  9. data/README.rdoc +87 -19
  10. data/Rakefile +11 -2
  11. data/TODO.rdoc +20 -13
  12. data/bin/rdoc +4 -0
  13. data/lib/gauntlet_rdoc.rb +1 -1
  14. data/lib/rdoc.rb +32 -71
  15. data/lib/rdoc/any_method.rb +75 -21
  16. data/lib/rdoc/attr.rb +49 -10
  17. data/lib/rdoc/class_module.rb +182 -32
  18. data/lib/rdoc/code_object.rb +54 -12
  19. data/lib/rdoc/comment.rb +8 -1
  20. data/lib/rdoc/constant.rb +100 -6
  21. data/lib/rdoc/context.rb +93 -41
  22. data/lib/rdoc/context/section.rb +143 -28
  23. data/lib/rdoc/cross_reference.rb +58 -50
  24. data/lib/rdoc/encoding.rb +34 -29
  25. data/lib/rdoc/erb_partial.rb +18 -0
  26. data/lib/rdoc/extend.rb +117 -0
  27. data/lib/rdoc/generator.rb +11 -6
  28. data/lib/rdoc/generator/darkfish.rb +250 -62
  29. data/lib/rdoc/generator/json_index.rb +20 -12
  30. data/lib/rdoc/generator/markup.rb +10 -12
  31. data/lib/rdoc/generator/ri.rb +7 -60
  32. data/lib/rdoc/generator/template/darkfish/_head.rhtml +7 -7
  33. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +16 -0
  34. data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +1 -1
  35. data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +14 -0
  36. data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +1 -1
  37. data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +13 -0
  38. data/lib/rdoc/generator/template/darkfish/class.rhtml +15 -1
  39. data/lib/rdoc/generator/template/darkfish/images/arrow_up.png +0 -0
  40. data/lib/rdoc/generator/template/darkfish/index.rhtml +3 -3
  41. data/lib/rdoc/generator/template/darkfish/js/darkfish.js +7 -9
  42. data/lib/rdoc/generator/template/darkfish/page.rhtml +2 -0
  43. data/lib/rdoc/generator/template/darkfish/rdoc.css +31 -0
  44. data/lib/rdoc/generator/template/darkfish/servlet_not_found.rhtml +18 -0
  45. data/lib/rdoc/generator/template/darkfish/servlet_root.rhtml +37 -0
  46. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +3 -3
  47. data/lib/rdoc/include.rb +12 -3
  48. data/lib/rdoc/markdown.kpeg +1186 -0
  49. data/lib/rdoc/markdown.rb +16336 -0
  50. data/lib/rdoc/markdown/entities.rb +2128 -0
  51. data/lib/rdoc/markdown/literals_1_8.kpeg +18 -0
  52. data/lib/rdoc/markdown/literals_1_8.rb +454 -0
  53. data/lib/rdoc/markdown/literals_1_9.kpeg +22 -0
  54. data/lib/rdoc/markdown/literals_1_9.rb +417 -0
  55. data/lib/rdoc/markup.rb +69 -10
  56. data/lib/rdoc/markup/attr_changer.rb +2 -5
  57. data/lib/rdoc/markup/attribute_manager.rb +23 -14
  58. data/lib/rdoc/markup/attributes.rb +70 -0
  59. data/lib/rdoc/markup/block_quote.rb +14 -0
  60. data/lib/rdoc/markup/document.rb +20 -4
  61. data/lib/rdoc/markup/formatter.rb +17 -6
  62. data/lib/rdoc/markup/formatter_test_case.rb +93 -24
  63. data/lib/rdoc/markup/hard_break.rb +31 -0
  64. data/lib/rdoc/markup/heading.rb +1 -1
  65. data/lib/rdoc/markup/indented_paragraph.rb +14 -0
  66. data/lib/rdoc/markup/list.rb +23 -4
  67. data/lib/rdoc/markup/list_item.rb +17 -4
  68. data/lib/rdoc/markup/paragraph.rb +14 -0
  69. data/lib/rdoc/markup/parser.rb +107 -60
  70. data/lib/rdoc/markup/raw.rb +4 -4
  71. data/lib/rdoc/markup/special.rb +3 -3
  72. data/lib/rdoc/markup/to_ansi.rb +7 -1
  73. data/lib/rdoc/markup/to_html.rb +42 -14
  74. data/lib/rdoc/markup/to_html_crossref.rb +10 -9
  75. data/lib/rdoc/markup/to_html_snippet.rb +20 -4
  76. data/lib/rdoc/markup/to_joined_paragraph.rb +68 -0
  77. data/lib/rdoc/markup/to_label.rb +20 -1
  78. data/lib/rdoc/markup/to_markdown.rb +134 -0
  79. data/lib/rdoc/markup/to_rdoc.rb +36 -5
  80. data/lib/rdoc/markup/to_table_of_contents.rb +6 -1
  81. data/lib/rdoc/markup/to_tt_only.rb +11 -2
  82. data/lib/rdoc/markup/verbatim.rb +19 -0
  83. data/lib/rdoc/method_attr.rb +33 -19
  84. data/lib/rdoc/normal_class.rb +26 -7
  85. data/lib/rdoc/normal_module.rb +10 -5
  86. data/lib/rdoc/options.rb +95 -21
  87. data/lib/rdoc/parser.rb +6 -2
  88. data/lib/rdoc/parser/c.rb +212 -97
  89. data/lib/rdoc/parser/markdown.rb +23 -0
  90. data/lib/rdoc/parser/ruby.rb +115 -35
  91. data/lib/rdoc/parser/ruby_tools.rb +8 -3
  92. data/lib/rdoc/rd.rb +8 -4
  93. data/lib/rdoc/rd/block_parser.rb +1 -1
  94. data/lib/rdoc/rd/block_parser.ry +1 -1
  95. data/lib/rdoc/rdoc.rb +45 -21
  96. data/lib/rdoc/ri/driver.rb +322 -76
  97. data/lib/rdoc/ri/paths.rb +90 -31
  98. data/lib/rdoc/ri/store.rb +2 -353
  99. data/lib/rdoc/ruby_lex.rb +5 -21
  100. data/lib/rdoc/ruby_token.rb +2 -3
  101. data/lib/rdoc/rubygems_hook.rb +21 -9
  102. data/lib/rdoc/servlet.rb +302 -0
  103. data/lib/rdoc/stats.rb +28 -20
  104. data/lib/rdoc/store.rb +881 -0
  105. data/lib/rdoc/task.rb +2 -1
  106. data/lib/rdoc/test_case.rb +103 -1
  107. data/lib/rdoc/text.rb +5 -4
  108. data/lib/rdoc/tom_doc.rb +17 -16
  109. data/lib/rdoc/top_level.rb +43 -285
  110. data/test/MarkdownTest_1.0.3/Amps and angle encoding.text +21 -0
  111. data/test/MarkdownTest_1.0.3/Auto links.text +13 -0
  112. data/test/MarkdownTest_1.0.3/Backslash escapes.text +120 -0
  113. data/test/MarkdownTest_1.0.3/Blockquotes with code blocks.text +11 -0
  114. data/test/MarkdownTest_1.0.3/Code Blocks.text +14 -0
  115. data/test/MarkdownTest_1.0.3/Code Spans.text +6 -0
  116. data/test/MarkdownTest_1.0.3/Hard-wrapped paragraphs with list-like lines.text +8 -0
  117. data/test/MarkdownTest_1.0.3/Horizontal rules.text +67 -0
  118. data/test/MarkdownTest_1.0.3/Inline HTML (Advanced).text +15 -0
  119. data/test/MarkdownTest_1.0.3/Inline HTML (Simple).text +69 -0
  120. data/test/MarkdownTest_1.0.3/Inline HTML comments.text +13 -0
  121. data/test/MarkdownTest_1.0.3/Links, inline style.text +12 -0
  122. data/test/MarkdownTest_1.0.3/Links, reference style.text +71 -0
  123. data/test/MarkdownTest_1.0.3/Links, shortcut references.text +20 -0
  124. data/test/MarkdownTest_1.0.3/Literal quotes in titles.text +7 -0
  125. data/test/MarkdownTest_1.0.3/Markdown Documentation - Basics.text +306 -0
  126. data/test/MarkdownTest_1.0.3/Markdown Documentation - Syntax.text +888 -0
  127. data/test/MarkdownTest_1.0.3/Nested blockquotes.text +5 -0
  128. data/test/MarkdownTest_1.0.3/Ordered and unordered lists.text +131 -0
  129. data/test/MarkdownTest_1.0.3/Strong and em together.text +7 -0
  130. data/test/MarkdownTest_1.0.3/Tabs.text +21 -0
  131. data/test/MarkdownTest_1.0.3/Tidyness.text +5 -0
  132. data/test/test_attribute_manager.rb +7 -4
  133. data/test/test_rdoc_any_method.rb +84 -13
  134. data/test/test_rdoc_attr.rb +59 -9
  135. data/test/test_rdoc_class_module.rb +670 -73
  136. data/test/test_rdoc_code_object.rb +21 -1
  137. data/test/test_rdoc_comment.rb +1 -1
  138. data/test/test_rdoc_constant.rb +132 -0
  139. data/test/test_rdoc_context.rb +84 -18
  140. data/test/test_rdoc_context_section.rb +99 -15
  141. data/test/test_rdoc_cross_reference.rb +1 -1
  142. data/test/test_rdoc_encoding.rb +17 -1
  143. data/test/test_rdoc_extend.rb +94 -0
  144. data/test/test_rdoc_generator_darkfish.rb +45 -19
  145. data/test/test_rdoc_generator_json_index.rb +27 -7
  146. data/test/test_rdoc_generator_markup.rb +3 -3
  147. data/test/test_rdoc_generator_ri.rb +11 -9
  148. data/test/test_rdoc_include.rb +12 -0
  149. data/test/test_rdoc_markdown.rb +977 -0
  150. data/test/test_rdoc_markdown_test.rb +1891 -0
  151. data/test/test_rdoc_markup.rb +1 -1
  152. data/test/test_rdoc_markup_attribute_manager.rb +2 -2
  153. data/test/test_rdoc_markup_attributes.rb +39 -0
  154. data/test/test_rdoc_markup_document.rb +16 -1
  155. data/test/test_rdoc_markup_formatter.rb +7 -4
  156. data/test/test_rdoc_markup_hard_break.rb +31 -0
  157. data/test/test_rdoc_markup_indented_paragraph.rb +14 -0
  158. data/test/test_rdoc_markup_paragraph.rb +15 -1
  159. data/test/test_rdoc_markup_parser.rb +152 -89
  160. data/test/test_rdoc_markup_to_ansi.rb +23 -2
  161. data/test/test_rdoc_markup_to_bs.rb +24 -0
  162. data/test/test_rdoc_markup_to_html.rb +50 -19
  163. data/test/test_rdoc_markup_to_html_crossref.rb +23 -5
  164. data/test/test_rdoc_markup_to_html_snippet.rb +49 -8
  165. data/test/test_rdoc_markup_to_joined_paragraph.rb +32 -0
  166. data/test/test_rdoc_markup_to_label.rb +63 -1
  167. data/test/test_rdoc_markup_to_markdown.rb +352 -0
  168. data/test/test_rdoc_markup_to_rdoc.rb +22 -2
  169. data/test/test_rdoc_markup_to_table_of_contents.rb +44 -39
  170. data/test/test_rdoc_markup_to_tt_only.rb +20 -0
  171. data/test/test_rdoc_markup_verbatim.rb +13 -0
  172. data/test/test_rdoc_method_attr.rb +5 -0
  173. data/test/test_rdoc_normal_class.rb +24 -5
  174. data/test/test_rdoc_normal_module.rb +1 -1
  175. data/test/test_rdoc_options.rb +21 -6
  176. data/test/test_rdoc_parser.rb +24 -0
  177. data/test/test_rdoc_parser_c.rb +151 -26
  178. data/test/test_rdoc_parser_markdown.rb +55 -0
  179. data/test/test_rdoc_parser_rd.rb +2 -2
  180. data/test/test_rdoc_parser_ruby.rb +468 -109
  181. data/test/test_rdoc_parser_simple.rb +2 -2
  182. data/test/test_rdoc_rd_block_parser.rb +0 -4
  183. data/test/test_rdoc_rdoc.rb +110 -22
  184. data/test/test_rdoc_ri_driver.rb +415 -80
  185. data/test/test_rdoc_ri_paths.rb +122 -13
  186. data/test/test_rdoc_ruby_lex.rb +5 -61
  187. data/test/test_rdoc_ruby_token.rb +19 -0
  188. data/test/test_rdoc_rubygems_hook.rb +64 -43
  189. data/test/test_rdoc_servlet.rb +429 -0
  190. data/test/test_rdoc_stats.rb +83 -24
  191. data/test/{test_rdoc_ri_store.rb → test_rdoc_store.rb} +395 -22
  192. data/test/test_rdoc_task.rb +2 -2
  193. data/test/test_rdoc_text.rb +37 -11
  194. data/test/test_rdoc_tom_doc.rb +59 -62
  195. data/test/test_rdoc_top_level.rb +71 -113
  196. data/test/xref_test_case.rb +7 -9
  197. metadata +122 -39
  198. metadata.gz.sig +0 -0
  199. data/CVE-2013-0256.rdoc +0 -49
  200. data/lib/rdoc/markup/attribute.rb +0 -51
@@ -0,0 +1,55 @@
1
+ require 'rdoc/test_case'
2
+
3
+ class TestRDocParserMarkdown < RDoc::TestCase
4
+
5
+ def setup
6
+ super
7
+
8
+ @RP = RDoc::Parser
9
+
10
+ @tempfile = Tempfile.new self.class.name
11
+ filename = @tempfile.path
12
+
13
+ @top_level = @store.add_file filename
14
+ @fn = filename
15
+ @options = RDoc::Options.new
16
+ @stats = RDoc::Stats.new @store, 0
17
+ end
18
+
19
+ def teardown
20
+ super
21
+
22
+ @tempfile.close
23
+ end
24
+
25
+ def test_file
26
+ assert_kind_of RDoc::Parser::Text, util_parser('')
27
+ end
28
+
29
+ def test_class_can_parse
30
+ assert_equal @RP::Markdown, @RP.can_parse('foo.md')
31
+ assert_equal @RP::Markdown, @RP.can_parse('foo.md.ja')
32
+
33
+ assert_equal @RP::Markdown, @RP.can_parse('foo.markdown')
34
+ assert_equal @RP::Markdown, @RP.can_parse('foo.markdown.ja')
35
+ end
36
+
37
+ def test_scan
38
+ parser = util_parser 'it *really* works'
39
+
40
+ expected =
41
+ @RM::Document.new(
42
+ @RM::Paragraph.new('it _really_ works'))
43
+ expected.file = @top_level
44
+
45
+ parser.scan
46
+
47
+ assert_equal expected, @top_level.comment.parse
48
+ end
49
+
50
+ def util_parser content
51
+ RDoc::Parser::Markdown.new @top_level, @fn, content, @options, @stats
52
+ end
53
+
54
+ end
55
+
@@ -10,10 +10,10 @@ class TestRDocParserRd < RDoc::TestCase
10
10
  @tempfile = Tempfile.new self.class.name
11
11
  filename = @tempfile.path
12
12
 
13
- @top_level = RDoc::TopLevel.new filename
13
+ @top_level = @store.add_file filename
14
14
  @fn = filename
15
15
  @options = RDoc::Options.new
16
- @stats = RDoc::Stats.new 0
16
+ @stats = RDoc::Stats.new @store, 0
17
17
  end
18
18
 
19
19
  def teardown
@@ -14,14 +14,16 @@ class TestRDocParserRuby < RDoc::TestCase
14
14
  @tempfile2 = Tempfile.new self.class.name
15
15
  @filename2 = @tempfile2.path
16
16
 
17
- util_top_level
17
+ @top_level = @store.add_file @filename
18
+ @top_level2 = @store.add_file @filename2
19
+
18
20
  @options = RDoc::Options.new
19
21
  @options.quiet = true
20
22
  @options.option_parser = OptionParser.new
21
23
 
22
24
  @comment = RDoc::Comment.new '', @top_level
23
25
 
24
- @stats = RDoc::Stats.new 0
26
+ @stats = RDoc::Stats.new @store, 0
25
27
  end
26
28
 
27
29
  def teardown
@@ -68,6 +70,45 @@ class C; end
68
70
  assert_equal Encoding::CP852, comment.text.encoding
69
71
  end
70
72
 
73
+ def test_get_class_or_module
74
+ ctxt = RDoc::Context.new
75
+ ctxt.store = @store
76
+
77
+ cont, name_t, given_name = util_parser('A') .get_class_or_module ctxt
78
+
79
+ assert_equal ctxt, cont
80
+ assert_equal 'A', name_t.text
81
+ assert_equal 'A', given_name
82
+
83
+ cont, name_t, given_name = util_parser('A::B') .get_class_or_module ctxt
84
+
85
+ assert_equal @store.find_module_named('A'), cont
86
+ assert_equal 'B', name_t.text
87
+ assert_equal 'A::B', given_name
88
+
89
+ cont, name_t, given_name = util_parser('A:: B').get_class_or_module ctxt
90
+
91
+ assert_equal @store.find_module_named('A'), cont
92
+ assert_equal 'B', name_t.text
93
+ assert_equal 'A::B', given_name
94
+
95
+ assert_raises NoMethodError do
96
+ util_parser("A::\nB").get_class_or_module ctxt
97
+ end
98
+ end
99
+
100
+ def test_get_class_specification
101
+ assert_equal 'A', util_parser('A') .get_class_specification
102
+ assert_equal 'A::B', util_parser('A::B').get_class_specification
103
+ assert_equal '::A', util_parser('::A').get_class_specification
104
+
105
+ assert_equal 'self', util_parser('self').get_class_specification
106
+
107
+ assert_equal '', util_parser('').get_class_specification
108
+
109
+ assert_equal '', util_parser('$g').get_class_specification
110
+ end
111
+
71
112
  def test_get_symbol_or_name
72
113
  util_parser "* & | + 5 / 4"
73
114
 
@@ -160,7 +201,7 @@ class C; end
160
201
 
161
202
  section = @top_level.current_section
162
203
  assert_equal 'new section', section.title
163
- assert_equal "# woo stuff\n", section.comment.text
204
+ assert_equal [comment("# woo stuff\n", @top_level)], section.comments
164
205
 
165
206
  assert_empty comment
166
207
  end
@@ -564,6 +605,19 @@ end
564
605
  assert_equal 1, foo.line
565
606
  end
566
607
 
608
+ def test_parse_class_single_root
609
+ comment = RDoc::Comment.new "##\n# my class\n", @top_level
610
+
611
+ util_parser "class << ::Foo\nend"
612
+
613
+ tk = @parser.get_tk
614
+
615
+ @parser.parse_class @top_level, RDoc::Parser::Ruby::NORMAL, tk, comment
616
+
617
+ foo = @store.all_modules.first
618
+ assert_equal 'Foo', foo.full_name
619
+ end
620
+
567
621
  def test_parse_class_stopdoc
568
622
  @top_level.stop_doc
569
623
 
@@ -630,7 +684,6 @@ end
630
684
  end
631
685
 
632
686
  def test_parse_class_nested_superclass
633
- util_top_level
634
687
  foo = @top_level.add_module RDoc::NormalModule, 'Foo'
635
688
 
636
689
  util_parser "class Bar < Super\nend"
@@ -701,7 +754,22 @@ end
701
754
 
702
755
  @parser.parse_class @top_level, false, @parser.get_tk, @comment
703
756
 
704
- assert_equal %w[A B], RDoc::TopLevel.classes.map { |c| c.full_name }
757
+ assert_equal %w[A B], @store.all_classes.map { |c| c.full_name }.sort
758
+ end
759
+
760
+ def test_parse_class_colon3_self_reference
761
+ code = <<-CODE
762
+ class A::B
763
+ class ::A
764
+ end
765
+ end
766
+ CODE
767
+
768
+ util_parser code
769
+
770
+ @parser.parse_class @top_level, false, @parser.get_tk, @comment
771
+
772
+ assert_equal %w[A A::B], @store.all_classes.map { |c| c.full_name }.sort
705
773
  end
706
774
 
707
775
  def test_parse_class_single
@@ -720,21 +788,42 @@ end
720
788
 
721
789
  @parser.parse_class @top_level, false, @parser.get_tk, @comment
722
790
 
723
- assert_equal %w[A], RDoc::TopLevel.classes.map { |c| c.full_name }
724
- assert_equal %w[A::B A::d], RDoc::TopLevel.modules.map { |c| c.full_name }
791
+ assert_equal %w[A], @store.all_classes.map { |c| c.full_name }
725
792
 
726
- b = RDoc::TopLevel.modules.first
793
+ modules = @store.all_modules.sort_by { |c| c.full_name }
794
+ assert_equal %w[A::B A::d], modules.map { |c| c.full_name }
795
+
796
+ b = modules.first
727
797
  assert_equal 10, b.offset
728
798
  assert_equal 2, b.line
729
799
 
730
800
  # make sure method/alias was not added to enclosing class/module
731
- a = RDoc::TopLevel.all_classes_hash['A']
801
+ a = @store.classes_hash['A']
732
802
  assert_empty a.method_list
733
803
 
734
804
  # make sure non-constant-named module will be removed from documentation
735
- d = RDoc::TopLevel.all_modules_hash['A::d']
805
+ d = @store.modules_hash['A::d']
736
806
  assert d.remove_from_documentation?
807
+ end
737
808
 
809
+ def test_parse_class_single_gvar
810
+ code = <<-CODE
811
+ class << $g
812
+ def m
813
+ end
814
+ end
815
+ CODE
816
+
817
+ util_parser code
818
+
819
+ @parser.parse_class @top_level, false, @parser.get_tk, ''
820
+
821
+ assert_empty @store.all_classes
822
+ mod = @store.all_modules.first
823
+
824
+ refute mod.document_self
825
+
826
+ assert_empty mod.method_list
738
827
  end
739
828
 
740
829
  # TODO this is really a Context#add_class test
@@ -754,11 +843,14 @@ end
754
843
 
755
844
  @parser.parse_module @top_level, false, @parser.get_tk, @comment
756
845
 
757
- assert_equal %w[A], RDoc::TopLevel.modules.map { |c| c.full_name }
758
- assert_equal %w[A::B A::C A::Object], RDoc::TopLevel.classes.map { |c| c.full_name }.sort
759
- assert_equal 'Object', RDoc::TopLevel.classes_hash['A::B'].superclass
760
- assert_equal 'Object', RDoc::TopLevel.classes_hash['A::Object'].superclass
761
- assert_equal 'A::Object', RDoc::TopLevel.classes_hash['A::C'].superclass.full_name
846
+ assert_equal %w[A],
847
+ @store.all_modules.map { |c| c.full_name }
848
+ assert_equal %w[A::B A::C A::Object],
849
+ @store.all_classes.map { |c| c.full_name }.sort
850
+
851
+ assert_equal 'Object', @store.classes_hash['A::B'].superclass
852
+ assert_equal 'Object', @store.classes_hash['A::Object'].superclass
853
+ assert_equal 'A::Object', @store.classes_hash['A::C'].superclass.full_name
762
854
  end
763
855
 
764
856
  def test_parse_class_mistaken_for_module
@@ -781,7 +873,7 @@ end
781
873
 
782
874
  @parser.scan
783
875
 
784
- assert_equal %w[Foo::Baz], RDoc::TopLevel.modules_hash.keys
876
+ assert_equal %w[Foo::Baz], @store.modules_hash.keys
785
877
  assert_empty @top_level.modules
786
878
 
787
879
  foo = @top_level.classes.first
@@ -795,9 +887,9 @@ end
795
887
  end
796
888
 
797
889
  def test_parse_class_definition_encountered_after_class_reference
798
- # The code below is not strictly legal Ruby (Foo must have been defined
799
- # before Foo.bar is encountered), but RDoc might encounter Foo.bar before
800
- # Foo if they live in different files.
890
+ # The code below is not legal Ruby (Foo must have been defined before
891
+ # Foo.bar is encountered), but RDoc might encounter Foo.bar before Foo if
892
+ # they live in different files.
801
893
 
802
894
  code = <<-EOF
803
895
  def Foo.bar
@@ -811,9 +903,8 @@ end
811
903
 
812
904
  @parser.scan
813
905
 
814
- assert_empty RDoc::TopLevel.modules_hash
815
- # HACK why does it fail?
816
- #assert_empty @top_level.modules
906
+ assert_empty @store.modules_hash
907
+ assert_empty @store.all_modules
817
908
 
818
909
  foo = @top_level.classes.first
819
910
  assert_equal 'Foo', foo.full_name
@@ -934,9 +1025,10 @@ EOF
934
1025
  assert_equal klass.current_section, foo.section
935
1026
 
936
1027
  stream = [
937
- tk(:COMMENT, 1, 1, nil, "# File #{@top_level.absolute_name}, line 1"),
1028
+ tk(:COMMENT, 0, 1, 1, nil,
1029
+ "# File #{@top_level.relative_name}, line 1"),
938
1030
  RDoc::Parser::Ruby::NEWLINE_TOKEN,
939
- tk(:SPACE, 1, 1, nil, ''),
1031
+ tk(:SPACE, 0, 1, 1, nil, ''),
940
1032
  ]
941
1033
 
942
1034
  assert_equal stream, foo.token_stream
@@ -959,8 +1051,6 @@ EOF
959
1051
  end
960
1052
 
961
1053
  def test_parse_constant
962
- util_top_level
963
-
964
1054
  klass = @top_level.add_class RDoc::NormalClass, 'Foo'
965
1055
 
966
1056
  util_parser "A = v"
@@ -978,8 +1068,6 @@ EOF
978
1068
  end
979
1069
 
980
1070
  def test_parse_constant_attrasgn
981
- util_top_level
982
-
983
1071
  klass = @top_level.add_class RDoc::NormalClass, 'Foo'
984
1072
 
985
1073
  util_parser "A[k] = v"
@@ -992,9 +1080,8 @@ EOF
992
1080
  end
993
1081
 
994
1082
  def test_parse_constant_alias
995
- util_top_level
996
1083
  klass = @top_level.add_class RDoc::NormalClass, 'Foo'
997
- cB = klass.add_class RDoc::NormalClass, 'B'
1084
+ klass.add_class RDoc::NormalClass, 'B'
998
1085
 
999
1086
  util_parser "A = B"
1000
1087
 
@@ -1002,15 +1089,15 @@ EOF
1002
1089
 
1003
1090
  @parser.parse_constant klass, tk, @comment
1004
1091
 
1005
- assert_equal cB, klass.find_module_named('A')
1092
+ assert_equal 'Foo::A', klass.find_module_named('A').full_name
1006
1093
  end
1007
1094
 
1008
1095
  def test_parse_constant_alias_same_name
1009
1096
  foo = @top_level.add_class RDoc::NormalClass, 'Foo'
1010
- top_bar = @top_level.add_class RDoc::NormalClass, 'Bar'
1097
+ @top_level.add_class RDoc::NormalClass, 'Bar'
1011
1098
  bar = foo.add_class RDoc::NormalClass, 'Bar'
1012
1099
 
1013
- assert RDoc::TopLevel.find_class_or_module('::Bar')
1100
+ assert @store.find_class_or_module('::Bar')
1014
1101
 
1015
1102
  util_parser "A = ::Bar"
1016
1103
 
@@ -1018,12 +1105,10 @@ EOF
1018
1105
 
1019
1106
  @parser.parse_constant foo, tk, @comment
1020
1107
 
1021
- assert_equal top_bar, bar.find_module_named('A')
1108
+ assert_equal 'A', bar.find_module_named('A').full_name
1022
1109
  end
1023
1110
 
1024
1111
  def test_parse_constant_stopdoc
1025
- util_top_level
1026
-
1027
1112
  klass = @top_level.add_class RDoc::NormalClass, 'Foo'
1028
1113
  klass.stop_doc
1029
1114
 
@@ -1056,6 +1141,26 @@ EOF
1056
1141
  assert_equal @top_level, incl.file
1057
1142
  end
1058
1143
 
1144
+ def test_parse_extend
1145
+ klass = RDoc::NormalClass.new 'C'
1146
+ klass.parent = @top_level
1147
+
1148
+ comment = RDoc::Comment.new "# my extend\n", @top_level
1149
+
1150
+ util_parser "extend I"
1151
+
1152
+ @parser.get_tk # extend
1153
+
1154
+ @parser.parse_extend klass, comment
1155
+
1156
+ assert_equal 1, klass.extends.length
1157
+
1158
+ ext = klass.extends.first
1159
+ assert_equal 'I', ext.name
1160
+ assert_equal 'my extend', ext.comment.text
1161
+ assert_equal @top_level, ext.file
1162
+ end
1163
+
1059
1164
  def test_parse_meta_method
1060
1165
  klass = RDoc::NormalClass.new 'Foo'
1061
1166
  klass.parent = @top_level
@@ -1093,16 +1198,17 @@ EOF
1093
1198
  assert_equal klass.current_section, foo.section
1094
1199
 
1095
1200
  stream = [
1096
- tk(:COMMENT, 1, 1, nil, "# File #{@top_level.absolute_name}, line 1"),
1201
+ tk(:COMMENT, 0, 1, 1, nil,
1202
+ "# File #{@top_level.relative_name}, line 1"),
1097
1203
  RDoc::Parser::Ruby::NEWLINE_TOKEN,
1098
- tk(:SPACE, 1, 1, nil, ''),
1099
- tk(:IDENTIFIER, 1, 0, 'add_my_method', 'add_my_method'),
1100
- tk(:SPACE, 1, 13, nil, ' '),
1101
- tk(:SYMBOL, 1, 14, nil, ':foo'),
1102
- tk(:COMMA, 1, 18, nil, ','),
1103
- tk(:SPACE, 1, 19, nil, ' '),
1104
- tk(:SYMBOL, 1, 20, nil, ':bar'),
1105
- tk(:NL, 1, 24, nil, "\n"),
1204
+ tk(:SPACE, 0, 1, 1, nil, ''),
1205
+ tk(:IDENTIFIER, 0, 1, 0, 'add_my_method', 'add_my_method'),
1206
+ tk(:SPACE, 0, 1, 13, nil, ' '),
1207
+ tk(:SYMBOL, 0, 1, 14, nil, ':foo'),
1208
+ tk(:COMMA, 0, 1, 18, nil, ','),
1209
+ tk(:SPACE, 0, 1, 19, nil, ' '),
1210
+ tk(:SYMBOL, 0, 1, 20, nil, ':bar'),
1211
+ tk(:NL, 0, 1, 24, nil, "\n"),
1106
1212
  ]
1107
1213
 
1108
1214
  assert_equal stream, foo.token_stream
@@ -1126,7 +1232,23 @@ end
1126
1232
 
1127
1233
  @parser.parse_meta_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment
1128
1234
 
1129
- assert_nil @parser.get_tk
1235
+ assert_equal tk(:NL, 0, 3, 3, 3, "\n"), @parser.get_tk
1236
+ end
1237
+
1238
+ def test_parse_meta_method_define_method
1239
+ klass = RDoc::NormalClass.new 'Foo'
1240
+ comment = RDoc::Comment.new "##\n# my method\n", @top_level
1241
+
1242
+ util_parser "define_method :foo do end"
1243
+
1244
+ tk = @parser.get_tk
1245
+
1246
+ @parser.parse_meta_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment
1247
+
1248
+ foo = klass.method_list.first
1249
+ assert_equal 'foo', foo.name
1250
+ assert_equal 'my method', foo.comment.text
1251
+ assert_equal @top_level, foo.file
1130
1252
  end
1131
1253
 
1132
1254
  def test_parse_meta_method_name
@@ -1274,19 +1396,20 @@ end
1274
1396
  assert_equal klass.current_section, foo.section
1275
1397
 
1276
1398
  stream = [
1277
- tk(:COMMENT, 1, 1, nil, "# File #{@top_level.absolute_name}, line 1"),
1399
+ tk(:COMMENT, 0, 1, 1, nil,
1400
+ "# File #{@top_level.relative_name}, line 1"),
1278
1401
  RDoc::Parser::Ruby::NEWLINE_TOKEN,
1279
- tk(:SPACE, 1, 1, nil, ''),
1280
- tk(:DEF, 1, 0, 'def', 'def'),
1281
- tk(:SPACE, 1, 3, nil, ' '),
1282
- tk(:IDENTIFIER, 1, 4, 'foo', 'foo'),
1283
- tk(:LPAREN, 1, 7, nil, '('),
1284
- tk(:RPAREN, 1, 8, nil, ')'),
1285
- tk(:SPACE, 1, 9, nil, ' '),
1286
- tk(:COLON, 1, 10, nil, ':'),
1287
- tk(:IDENTIFIER, 1, 11, 'bar', 'bar'),
1288
- tk(:SPACE, 1, 14, nil, ' '),
1289
- tk(:END, 1, 15, 'end', 'end'),
1402
+ tk(:SPACE, 0, 1, 1, nil, ''),
1403
+ tk(:DEF, 0, 1, 0, 'def', 'def'),
1404
+ tk(:SPACE, 3, 1, 3, nil, ' '),
1405
+ tk(:IDENTIFIER, 4, 1, 4, 'foo', 'foo'),
1406
+ tk(:LPAREN, 7, 1, 7, nil, '('),
1407
+ tk(:RPAREN, 8, 1, 8, nil, ')'),
1408
+ tk(:SPACE, 9, 1, 9, nil, ' '),
1409
+ tk(:COLON, 10, 1, 10, nil, ':'),
1410
+ tk(:IDENTIFIER, 11, 1, 11, 'bar', 'bar'),
1411
+ tk(:SPACE, 14, 1, 14, nil, ' '),
1412
+ tk(:END, 15, 1, 15, 'end', 'end'),
1290
1413
  ]
1291
1414
 
1292
1415
  assert_equal stream, foo.token_stream
@@ -1305,6 +1428,21 @@ end
1305
1428
  assert klass.aliases.empty?
1306
1429
  end
1307
1430
 
1431
+ def test_parse_method_ampersand
1432
+ klass = RDoc::NormalClass.new 'Foo'
1433
+ klass.parent = @top_level
1434
+
1435
+ util_parser "def self.&\nend"
1436
+
1437
+ tk = @parser.get_tk
1438
+
1439
+ @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, @comment
1440
+
1441
+ ampersand = klass.method_list.first
1442
+ assert_equal '&', ampersand.name
1443
+ assert ampersand.singleton
1444
+ end
1445
+
1308
1446
  def test_parse_method_false
1309
1447
  util_parser "def false.foo() :bar end"
1310
1448
 
@@ -1312,7 +1450,7 @@ end
1312
1450
 
1313
1451
  @parser.parse_method @top_level, RDoc::Parser::Ruby::NORMAL, tk, @comment
1314
1452
 
1315
- klass = RDoc::TopLevel.find_class_named 'FalseClass'
1453
+ klass = @store.find_class_named 'FalseClass'
1316
1454
 
1317
1455
  foo = klass.method_list.first
1318
1456
  assert_equal 'foo', foo.name
@@ -1328,7 +1466,7 @@ end
1328
1466
 
1329
1467
  @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, @comment
1330
1468
 
1331
- assert klass.method_list.empty?
1469
+ assert_empty klass.method_list
1332
1470
  end
1333
1471
 
1334
1472
  def test_parse_method_gvar
@@ -1341,6 +1479,22 @@ end
1341
1479
  assert @top_level.method_list.empty?
1342
1480
  end
1343
1481
 
1482
+ def test_parse_method_gvar_insane
1483
+ util_parser "def $stdout.foo() class << $other; end; end"
1484
+
1485
+ tk = @parser.get_tk
1486
+
1487
+ @parser.parse_method @top_level, RDoc::Parser::Ruby::NORMAL, tk, @comment
1488
+
1489
+ assert @top_level.method_list.empty?
1490
+
1491
+ assert_empty @store.all_classes
1492
+
1493
+ assert_equal 1, @store.all_modules.length
1494
+
1495
+ refute @store.all_modules.first.document_self
1496
+ end
1497
+
1344
1498
  def test_parse_method_internal_gvar
1345
1499
  klass = RDoc::NormalClass.new 'Foo'
1346
1500
  klass.parent = @top_level
@@ -1387,7 +1541,7 @@ end
1387
1541
 
1388
1542
  @parser.parse_method @top_level, RDoc::Parser::Ruby::NORMAL, tk, @comment
1389
1543
 
1390
- klass = RDoc::TopLevel.find_class_named 'NilClass'
1544
+ klass = @store.find_class_named 'NilClass'
1391
1545
 
1392
1546
  foo = klass.method_list.first
1393
1547
  assert_equal 'foo', foo.name
@@ -1436,6 +1590,21 @@ end
1436
1590
  assert_equal '(arg1, arg2, arg3)', foo.params
1437
1591
  end
1438
1592
 
1593
+ def test_parse_method_star
1594
+ klass = RDoc::NormalClass.new 'Foo'
1595
+ klass.parent = @top_level
1596
+
1597
+ util_parser "def self.*\nend"
1598
+
1599
+ tk = @parser.get_tk
1600
+
1601
+ @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, @comment
1602
+
1603
+ ampersand = klass.method_list.first
1604
+ assert_equal '*', ampersand.name
1605
+ assert ampersand.singleton
1606
+ end
1607
+
1439
1608
  def test_parse_method_stopdoc
1440
1609
  klass = RDoc::NormalClass.new 'Foo'
1441
1610
  klass.parent = @top_level
@@ -1461,7 +1630,7 @@ end
1461
1630
 
1462
1631
  @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, @comment
1463
1632
 
1464
- object = RDoc::TopLevel.find_class_named 'Object'
1633
+ object = @store.find_class_named 'Object'
1465
1634
 
1466
1635
  foo = object.method_list.first
1467
1636
  assert_equal 'Object#foo', foo.full_name
@@ -1477,7 +1646,7 @@ end
1477
1646
 
1478
1647
  @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, @comment
1479
1648
 
1480
- object = RDoc::TopLevel.find_class_named 'Object'
1649
+ object = @store.find_class_named 'Object'
1481
1650
 
1482
1651
  foo = object.method_list.first
1483
1652
  assert_equal 'Object::foo', foo.full_name
@@ -1490,7 +1659,7 @@ end
1490
1659
 
1491
1660
  @parser.parse_method @top_level, RDoc::Parser::Ruby::NORMAL, tk, @comment
1492
1661
 
1493
- klass = RDoc::TopLevel.find_class_named 'TrueClass'
1662
+ klass = @store.find_class_named 'TrueClass'
1494
1663
 
1495
1664
  foo = klass.method_list.first
1496
1665
  assert_equal 'foo', foo.name
@@ -1515,6 +1684,16 @@ end
1515
1684
  assert_equal "def \317\211", omega.text
1516
1685
  end
1517
1686
 
1687
+ def test_parse_method_or_yield_parameters_hash
1688
+ util_parser "({})\n"
1689
+
1690
+ m = RDoc::AnyMethod.new nil, 'm'
1691
+
1692
+ result = @parser.parse_method_or_yield_parameters m
1693
+
1694
+ assert_equal '({})', result
1695
+ end
1696
+
1518
1697
  def test_parse_statements_class_if
1519
1698
  util_parser <<-CODE
1520
1699
  module Foo
@@ -1562,19 +1741,17 @@ end
1562
1741
  assert_equal 2, x.method_list.length
1563
1742
  a = x.method_list.first
1564
1743
 
1565
- rt = RDoc::RubyToken
1566
-
1567
1744
  expected = [
1568
- rt::TkCOMMENT .new( 0, 2, 1, "# File #{@filename}, line 2"),
1569
- rt::TkNL .new( 0, 0, 0, "\n"),
1570
- rt::TkSPACE .new( 0, 1, 1, ""),
1571
- rt::TkDEF .new( 8, 2, 0, "def"),
1572
- rt::TkSPACE .new(11, 2, 3, " "),
1573
- rt::TkIDENTIFIER.new(12, 2, 4, "a"),
1574
- rt::TkNL .new(13, 2, 5, "\n"),
1575
- rt::TkDREGEXP .new(14, 3, 0, "%r{#}"),
1576
- rt::TkNL .new(19, 3, 5, "\n"),
1577
- rt::TkEND .new(20, 4, 0, "end"),
1745
+ tk(:COMMENT, 0, 2, 1, nil, "# File #{@filename}, line 2"),
1746
+ tk(:NL, 0, 0, 0, nil, "\n"),
1747
+ tk(:SPACE, 0, 1, 1, nil, ''),
1748
+ tk(:DEF, 8, 2, 0, 'def', 'def'),
1749
+ tk(:SPACE, 11, 2, 3, nil, ' '),
1750
+ tk(:IDENTIFIER, 12, 2, 4, 'a', 'a'),
1751
+ tk(:NL, 13, 2, 5, nil, "\n"),
1752
+ tk(:DREGEXP, 14, 3, 0, nil, '%r{#}'),
1753
+ tk(:NL, 19, 3, 5, nil, "\n"),
1754
+ tk(:END, 20, 4, 0, 'end', 'end'),
1578
1755
  ]
1579
1756
 
1580
1757
  assert_equal expected, a.token_stream
@@ -1682,8 +1859,25 @@ EOF
1682
1859
  assert_equal 'unknown', @top_level.classes.first.external_aliases[0].old_name
1683
1860
  end
1684
1861
 
1685
- def test_parse_statements_identifier_constant
1862
+ def test_parse_statements_identifier_args
1863
+ comment = "##\n# :args: x\n# :method: b\n# my method\n"
1864
+
1865
+ util_parser "module M\n#{comment}def_delegator :a, :b, :b\nend"
1866
+
1867
+ @parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL
1868
+
1869
+ m = @top_level.modules.first
1870
+ assert_equal 'M', m.full_name
1871
+
1872
+ b = m.method_list.first
1873
+ assert_equal 'M#b', b.full_name
1874
+ assert_equal 'x', b.params
1875
+ assert_equal 'my method', b.comment.text
1686
1876
 
1877
+ assert_nil m.params, 'Module parameter not removed'
1878
+ end
1879
+
1880
+ def test_parse_statements_identifier_constant
1687
1881
  sixth_constant = <<-EOF
1688
1882
  Class.new do
1689
1883
  rule :file do
@@ -1794,6 +1988,24 @@ EOF
1794
1988
  assert_equal 'RW', foo.rw
1795
1989
  end
1796
1990
 
1991
+ def test_parse_statements_identifier_define_method
1992
+ util_parser <<-RUBY
1993
+ class C
1994
+ ##
1995
+ # :method: a
1996
+ define_method :a do end
1997
+ ##
1998
+ # :method: b
1999
+ define_method :b do end
2000
+ end
2001
+ RUBY
2002
+
2003
+ @parser.parse_statements @top_level
2004
+ c = @top_level.classes.first
2005
+
2006
+ assert_equal %w[a b], c.method_list.map { |m| m.name }
2007
+ end
2008
+
1797
2009
  def test_parse_statements_identifier_include
1798
2010
  content = "class Foo\ninclude Bar\nend"
1799
2011
 
@@ -1851,10 +2063,10 @@ end
1851
2063
 
1852
2064
  @parser.parse_statements @top_level
1853
2065
 
1854
- date, date_time = @top_level.classes
2066
+ date, date_time = @top_level.classes.sort_by { |c| c.full_name }
1855
2067
 
1856
2068
  date_now = date.method_list.first
1857
- date_time_now = date_time.method_list.first
2069
+ date_time_now = date_time.method_list.sort_by { |m| m.full_name }.first
1858
2070
 
1859
2071
  assert_equal :private, date_now.visibility
1860
2072
  assert_equal :public, date_time_now.visibility
@@ -1876,10 +2088,11 @@ end
1876
2088
 
1877
2089
  @parser.parse_statements @top_level
1878
2090
 
1879
- date, date_time = @top_level.classes
2091
+ # TODO sort classes by default
2092
+ date, date_time = @top_level.classes.sort_by { |c| c.full_name }
1880
2093
 
1881
2094
  date_now = date.method_list.first
1882
- date_time_now = date_time.method_list.first
2095
+ date_time_now = date_time.method_list.sort_by { |m| m.full_name }.first
1883
2096
 
1884
2097
  assert_equal :public, date_now.visibility, date_now.full_name
1885
2098
  assert_equal :private, date_time_now.visibility, date_time_now.full_name
@@ -1895,9 +2108,25 @@ end
1895
2108
  assert_equal 1, @top_level.requires.length
1896
2109
  end
1897
2110
 
1898
- def test_parse_statements_stopdoc_TkALIAS
1899
- util_top_level
2111
+ def test_parse_statements_identifier_yields
2112
+ comment = "##\n# :yields: x\n# :method: b\n# my method\n"
2113
+
2114
+ util_parser "module M\n#{comment}def_delegator :a, :b, :b\nend"
2115
+
2116
+ @parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL
2117
+
2118
+ m = @top_level.modules.first
2119
+ assert_equal 'M', m.full_name
2120
+
2121
+ b = m.method_list.first
2122
+ assert_equal 'M#b', b.full_name
2123
+ assert_equal 'x', b.block_params
2124
+ assert_equal 'my method', b.comment.text
1900
2125
 
2126
+ assert_nil m.params, 'Module parameter not removed'
2127
+ end
2128
+
2129
+ def test_parse_statements_stopdoc_TkALIAS
1901
2130
  klass = @top_level.add_class RDoc::NormalClass, 'Foo'
1902
2131
 
1903
2132
  util_parser "\n# :stopdoc:\nalias old new"
@@ -1909,8 +2138,6 @@ end
1909
2138
  end
1910
2139
 
1911
2140
  def test_parse_statements_stopdoc_TkIDENTIFIER_alias_method
1912
- util_top_level
1913
-
1914
2141
  klass = @top_level.add_class RDoc::NormalClass, 'Foo'
1915
2142
 
1916
2143
  util_parser "\n# :stopdoc:\nalias_method :old :new"
@@ -1922,8 +2149,6 @@ end
1922
2149
  end
1923
2150
 
1924
2151
  def test_parse_statements_stopdoc_TkIDENTIFIER_metaprogrammed
1925
- util_top_level
1926
-
1927
2152
  klass = @top_level.add_class RDoc::NormalClass, 'Foo'
1928
2153
 
1929
2154
  util_parser "\n# :stopdoc:\n# attr :meta"
@@ -1935,8 +2160,6 @@ end
1935
2160
  end
1936
2161
 
1937
2162
  def test_parse_statements_stopdoc_TkCONSTANT
1938
- util_top_level
1939
-
1940
2163
  klass = @top_level.add_class RDoc::NormalClass, 'Foo'
1941
2164
 
1942
2165
  util_parser "\n# :stopdoc:\nA = v"
@@ -1947,8 +2170,6 @@ end
1947
2170
  end
1948
2171
 
1949
2172
  def test_parse_statements_stopdoc_TkDEF
1950
- util_top_level
1951
-
1952
2173
  klass = @top_level.add_class RDoc::NormalClass, 'Foo'
1953
2174
 
1954
2175
  util_parser "\n# :stopdoc:\ndef m\n end"
@@ -1958,6 +2179,25 @@ end
1958
2179
  assert_empty klass.method_list
1959
2180
  end
1960
2181
 
2182
+ def test_parse_statements_super
2183
+ m = RDoc::AnyMethod.new '', 'm'
2184
+ util_parser 'super'
2185
+
2186
+ @parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, m
2187
+
2188
+ assert m.calls_super
2189
+ end
2190
+
2191
+ def test_parse_statements_super_no_method
2192
+ content = "super"
2193
+
2194
+ util_parser content
2195
+
2196
+ @parser.parse_statements @top_level
2197
+
2198
+ assert_nil @parser.get_tk
2199
+ end
2200
+
1961
2201
  def test_parse_statements_while_begin
1962
2202
  util_parser <<-RUBY
1963
2203
  class A
@@ -2086,6 +2326,98 @@ end
2086
2326
  assert_equal 'nth(i)', foo.block_params
2087
2327
  end
2088
2328
 
2329
+ def test_read_directive
2330
+ parser = util_parser '# :category: test'
2331
+
2332
+ directive, value = parser.read_directive %w[category]
2333
+
2334
+ assert_equal 'category', directive
2335
+ assert_equal 'test', value
2336
+
2337
+ assert_kind_of RDoc::RubyToken::TkNL, parser.get_tk
2338
+ end
2339
+
2340
+ def test_read_directive_allow
2341
+ parser = util_parser '# :category: test'
2342
+
2343
+ directive = parser.read_directive []
2344
+
2345
+ assert_nil directive
2346
+
2347
+ assert_kind_of RDoc::RubyToken::TkNL, parser.get_tk
2348
+ end
2349
+
2350
+ def test_read_directive_empty
2351
+ parser = util_parser '# test'
2352
+
2353
+ directive = parser.read_directive %w[category]
2354
+
2355
+ assert_nil directive
2356
+
2357
+ assert_kind_of RDoc::RubyToken::TkNL, parser.get_tk
2358
+ end
2359
+
2360
+ def test_read_directive_no_comment
2361
+ parser = util_parser ''
2362
+
2363
+ directive = parser.read_directive %w[category]
2364
+
2365
+ assert_nil directive
2366
+
2367
+ assert_kind_of RDoc::RubyToken::TkNL, parser.get_tk
2368
+ end
2369
+
2370
+ def test_read_directive_one_liner
2371
+ parser = util_parser '; end # :category: test'
2372
+
2373
+ directive, value = parser.read_directive %w[category]
2374
+
2375
+ assert_equal 'category', directive
2376
+ assert_equal 'test', value
2377
+
2378
+ assert_kind_of RDoc::RubyToken::TkSEMICOLON, parser.get_tk
2379
+ end
2380
+
2381
+ def test_read_documentation_modifiers
2382
+ c = RDoc::Context.new
2383
+
2384
+ parser = util_parser '# :category: test'
2385
+
2386
+ parser.read_documentation_modifiers c, %w[category]
2387
+
2388
+ assert_equal 'test', c.current_section.title
2389
+ end
2390
+
2391
+ def test_read_documentation_modifiers_notnew
2392
+ m = RDoc::AnyMethod.new nil, 'initialize'
2393
+
2394
+ parser = util_parser '# :notnew: test'
2395
+
2396
+ parser.read_documentation_modifiers m, %w[notnew]
2397
+
2398
+ assert m.dont_rename_initialize
2399
+ end
2400
+
2401
+ def test_read_documentation_modifiers_not_dash_new
2402
+ m = RDoc::AnyMethod.new nil, 'initialize'
2403
+
2404
+ parser = util_parser '# :not-new: test'
2405
+
2406
+ parser.read_documentation_modifiers m, %w[not-new]
2407
+
2408
+ assert m.dont_rename_initialize
2409
+ end
2410
+
2411
+ def test_read_documentation_modifiers_not_new
2412
+ m = RDoc::AnyMethod.new nil, 'initialize'
2413
+
2414
+ parser = util_parser '# :not_new: test'
2415
+
2416
+ parser.read_documentation_modifiers m, %w[not_new]
2417
+
2418
+ assert m.dont_rename_initialize
2419
+ end
2420
+
2089
2421
  def test_sanity_integer
2090
2422
  util_parser '1'
2091
2423
  assert_equal '1', @parser.get_tk.text
@@ -2381,11 +2713,11 @@ end
2381
2713
  assert_equal "find_by_<field>[_and_<field>...](args)\n", m.call_seq
2382
2714
 
2383
2715
  expected =
2384
- @RM::Document.new(
2385
- @RM::Heading.new(3, 'Signature'),
2386
- @RM::List.new(:NOTE,
2387
- @RM::ListItem.new('field',
2388
- @RM::Paragraph.new('A field name.'))))
2716
+ doc(
2717
+ head(3, 'Signature'),
2718
+ list(:NOTE,
2719
+ item(%w[field],
2720
+ para('A field name.'))))
2389
2721
  expected.file = @top_level
2390
2722
 
2391
2723
  assert_equal expected, m.comment.parse
@@ -2420,14 +2752,47 @@ end
2420
2752
 
2421
2753
  @parser.scan
2422
2754
 
2423
- assert_empty RDoc::TopLevel.classes
2755
+ assert_empty @store.all_classes
2424
2756
 
2425
- assert_equal 1, RDoc::TopLevel.modules.length
2426
- m = RDoc::TopLevel.modules.first
2757
+ assert_equal 1, @store.all_modules.length
2758
+ m = @store.all_modules.first
2427
2759
 
2428
2760
  assert m.ignored?
2429
2761
  end
2430
2762
 
2763
+ def test_scan_stopdoc_nested
2764
+ util_parser <<-RUBY
2765
+ # :stopdoc:
2766
+ class A::B
2767
+ end
2768
+ RUBY
2769
+
2770
+ @parser.scan
2771
+
2772
+ a = @store.modules_hash['A']
2773
+ a_b = @store.classes_hash['A::B']
2774
+
2775
+ refute a.document_self, 'A is inside stopdoc'
2776
+ assert a.ignored?, 'A is inside stopdoc'
2777
+
2778
+ refute a_b.document_self, 'A::B is inside stopdoc'
2779
+ assert a_b.ignored?, 'A::B is inside stopdoc'
2780
+ end
2781
+
2782
+ def test_scan_struct_self_brackets
2783
+ util_parser <<-RUBY
2784
+ class C < M.m
2785
+ def self.[]
2786
+ end
2787
+ end
2788
+ RUBY
2789
+
2790
+ @parser.scan
2791
+
2792
+ c = @store.find_class_named 'C'
2793
+ assert_equal %w[C::[]], c.method_list.map { |m| m.full_name }
2794
+ end
2795
+
2431
2796
  def test_stopdoc_after_comment
2432
2797
  util_parser <<-EOS
2433
2798
  module Bar
@@ -2453,14 +2818,14 @@ end
2453
2818
  assert_equal 'there', baz.comment.text
2454
2819
  end
2455
2820
 
2456
- def tk(klass, line, char, name, text)
2821
+ def tk klass, scan, line, char, name, text
2457
2822
  klass = RDoc::RubyToken.const_get "Tk#{klass.to_s.upcase}"
2458
2823
 
2459
2824
  token = if klass.instance_method(:initialize).arity == 3 then
2460
- raise ArgumentError, "name not used for #{klass}" unless name.nil?
2461
- klass.new 0, line, char
2825
+ raise ArgumentError, "name not used for #{klass}" if name
2826
+ klass.new scan, line, char
2462
2827
  else
2463
- klass.new 0, line, char, name
2828
+ klass.new scan, line, char, name
2464
2829
  end
2465
2830
 
2466
2831
  token.set_text text
@@ -2480,11 +2845,5 @@ end
2480
2845
  second_file_content, @options, @stats
2481
2846
  end
2482
2847
 
2483
- def util_top_level
2484
- RDoc::TopLevel.reset
2485
- @top_level = RDoc::TopLevel.new @filename
2486
- @top_level2 = RDoc::TopLevel.new @filename2
2487
- end
2488
-
2489
2848
  end
2490
2849