rdoc 4.3.0 → 5.0.0.beta1

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 (248) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +13 -0
  3. data/.travis.yml +23 -0
  4. data/CONTRIBUTING.rdoc +4 -3
  5. data/Gemfile +3 -0
  6. data/History.rdoc +15 -4
  7. data/LEGAL.rdoc +2 -2
  8. data/README.rdoc +1 -0
  9. data/Rakefile +41 -79
  10. data/bin/console +7 -0
  11. data/bin/setup +6 -0
  12. data/{bin → exe}/rdoc +0 -0
  13. data/{bin → exe}/ri +0 -0
  14. data/lib/rdoc.rb +2 -1
  15. data/lib/rdoc/alias.rb +1 -0
  16. data/lib/rdoc/anon_class.rb +1 -0
  17. data/lib/rdoc/any_method.rb +1 -0
  18. data/lib/rdoc/attr.rb +1 -0
  19. data/lib/rdoc/class_module.rb +1 -0
  20. data/lib/rdoc/code_object.rb +1 -0
  21. data/lib/rdoc/code_objects.rb +1 -0
  22. data/lib/rdoc/comment.rb +1 -0
  23. data/lib/rdoc/constant.rb +1 -0
  24. data/lib/rdoc/context.rb +4 -1
  25. data/lib/rdoc/context/section.rb +7 -0
  26. data/lib/rdoc/cross_reference.rb +1 -0
  27. data/lib/rdoc/encoding.rb +14 -0
  28. data/lib/rdoc/erb_partial.rb +1 -0
  29. data/lib/rdoc/erbio.rb +1 -0
  30. data/lib/rdoc/extend.rb +1 -0
  31. data/lib/rdoc/generator.rb +1 -0
  32. data/lib/rdoc/generator/darkfish.rb +1 -0
  33. data/lib/rdoc/generator/json_index.rb +1 -0
  34. data/lib/rdoc/generator/markup.rb +1 -0
  35. data/lib/rdoc/generator/pot.rb +1 -0
  36. data/lib/rdoc/generator/pot/message_extractor.rb +1 -0
  37. data/lib/rdoc/generator/pot/po.rb +1 -0
  38. data/lib/rdoc/generator/pot/po_entry.rb +1 -0
  39. data/lib/rdoc/generator/ri.rb +1 -0
  40. data/lib/rdoc/generator/template/darkfish/_head.rhtml +2 -1
  41. data/lib/rdoc/generator/template/darkfish/css/fonts.css +6 -6
  42. data/lib/rdoc/generator/template/darkfish/js/darkfish.js +7 -7
  43. data/lib/rdoc/generator/template/json_index/js/searcher.js +1 -0
  44. data/lib/rdoc/ghost_method.rb +1 -0
  45. data/lib/rdoc/i18n.rb +1 -0
  46. data/lib/rdoc/i18n/locale.rb +1 -0
  47. data/lib/rdoc/i18n/text.rb +1 -0
  48. data/lib/rdoc/include.rb +1 -0
  49. data/lib/rdoc/known_classes.rb +1 -0
  50. data/lib/rdoc/markdown.kpeg +2 -6
  51. data/lib/rdoc/markdown.rb +2 -6
  52. data/lib/rdoc/markdown/entities.rb +1 -0
  53. data/lib/rdoc/markdown/{literals_1_9.kpeg → literals.kpeg} +0 -0
  54. data/lib/rdoc/markdown/{literals_1_9.rb → literals.rb} +1 -4
  55. data/lib/rdoc/markup.rb +1 -0
  56. data/lib/rdoc/markup/attr_changer.rb +1 -0
  57. data/lib/rdoc/markup/attr_span.rb +1 -0
  58. data/lib/rdoc/markup/attribute_manager.rb +1 -0
  59. data/lib/rdoc/markup/attributes.rb +1 -0
  60. data/lib/rdoc/markup/blank_line.rb +1 -0
  61. data/lib/rdoc/markup/block_quote.rb +1 -0
  62. data/lib/rdoc/markup/document.rb +1 -0
  63. data/lib/rdoc/markup/formatter.rb +1 -0
  64. data/lib/rdoc/markup/formatter_test_case.rb +1 -4
  65. data/lib/rdoc/markup/hard_break.rb +1 -0
  66. data/lib/rdoc/markup/heading.rb +1 -0
  67. data/lib/rdoc/markup/include.rb +1 -0
  68. data/lib/rdoc/markup/indented_paragraph.rb +1 -0
  69. data/lib/rdoc/markup/inline.rb +1 -0
  70. data/lib/rdoc/markup/list.rb +1 -0
  71. data/lib/rdoc/markup/list_item.rb +1 -0
  72. data/lib/rdoc/markup/paragraph.rb +1 -0
  73. data/lib/rdoc/markup/parser.rb +1 -0
  74. data/lib/rdoc/markup/pre_process.rb +1 -0
  75. data/lib/rdoc/markup/raw.rb +1 -0
  76. data/lib/rdoc/markup/rule.rb +1 -0
  77. data/lib/rdoc/markup/special.rb +1 -0
  78. data/lib/rdoc/markup/text_formatter_test_case.rb +1 -0
  79. data/lib/rdoc/markup/to_ansi.rb +1 -0
  80. data/lib/rdoc/markup/to_bs.rb +1 -0
  81. data/lib/rdoc/markup/to_html.rb +1 -0
  82. data/lib/rdoc/markup/to_html_crossref.rb +1 -0
  83. data/lib/rdoc/markup/to_html_snippet.rb +1 -0
  84. data/lib/rdoc/markup/to_joined_paragraph.rb +1 -0
  85. data/lib/rdoc/markup/to_label.rb +1 -0
  86. data/lib/rdoc/markup/to_markdown.rb +1 -0
  87. data/lib/rdoc/markup/to_rdoc.rb +1 -0
  88. data/lib/rdoc/markup/to_table_of_contents.rb +1 -0
  89. data/lib/rdoc/markup/to_test.rb +1 -0
  90. data/lib/rdoc/markup/to_tt_only.rb +1 -0
  91. data/lib/rdoc/markup/verbatim.rb +1 -0
  92. data/lib/rdoc/meta_method.rb +1 -0
  93. data/lib/rdoc/method_attr.rb +1 -0
  94. data/lib/rdoc/mixin.rb +1 -0
  95. data/lib/rdoc/normal_class.rb +1 -0
  96. data/lib/rdoc/normal_module.rb +1 -0
  97. data/lib/rdoc/options.rb +1 -0
  98. data/lib/rdoc/parser.rb +1 -0
  99. data/lib/rdoc/parser/c.rb +76 -33
  100. data/lib/rdoc/parser/changelog.rb +7 -1
  101. data/lib/rdoc/parser/markdown.rb +1 -0
  102. data/lib/rdoc/parser/rd.rb +1 -0
  103. data/lib/rdoc/parser/ruby.rb +1 -0
  104. data/lib/rdoc/parser/ruby_tools.rb +1 -0
  105. data/lib/rdoc/parser/simple.rb +1 -0
  106. data/lib/rdoc/parser/text.rb +1 -0
  107. data/lib/rdoc/rd.rb +1 -0
  108. data/lib/rdoc/rd/inline.rb +1 -0
  109. data/lib/rdoc/rdoc.rb +2 -1
  110. data/lib/rdoc/require.rb +1 -0
  111. data/lib/rdoc/ri.rb +1 -0
  112. data/lib/rdoc/ri/driver.rb +5 -19
  113. data/lib/rdoc/ri/formatter.rb +1 -0
  114. data/lib/rdoc/ri/paths.rb +1 -0
  115. data/lib/rdoc/ri/store.rb +1 -0
  116. data/lib/rdoc/ri/task.rb +72 -0
  117. data/lib/rdoc/ruby_lex.rb +11 -17
  118. data/lib/rdoc/ruby_token.rb +1 -0
  119. data/lib/rdoc/rubygems_hook.rb +1 -0
  120. data/lib/rdoc/servlet.rb +4 -3
  121. data/lib/rdoc/single_class.rb +1 -0
  122. data/lib/rdoc/stats.rb +1 -0
  123. data/lib/rdoc/stats/normal.rb +1 -0
  124. data/lib/rdoc/stats/quiet.rb +1 -0
  125. data/lib/rdoc/stats/verbose.rb +1 -0
  126. data/lib/rdoc/store.rb +3 -9
  127. data/lib/rdoc/task.rb +1 -0
  128. data/lib/rdoc/test_case.rb +1 -10
  129. data/lib/rdoc/text.rb +1 -0
  130. data/lib/rdoc/token_stream.rb +1 -0
  131. data/lib/rdoc/tom_doc.rb +1 -0
  132. data/lib/rdoc/top_level.rb +1 -0
  133. data/rdoc.gemspec +60 -0
  134. metadata +32 -155
  135. data/Manifest.txt +0 -309
  136. data/lib/rdoc/markdown/literals_1_8.kpeg +0 -18
  137. data/lib/rdoc/markdown/literals_1_8.rb +0 -416
  138. data/test/MarkdownTest_1.0.3/Amps and angle encoding.text +0 -21
  139. data/test/MarkdownTest_1.0.3/Auto links.text +0 -13
  140. data/test/MarkdownTest_1.0.3/Backslash escapes.text +0 -120
  141. data/test/MarkdownTest_1.0.3/Blockquotes with code blocks.text +0 -11
  142. data/test/MarkdownTest_1.0.3/Code Blocks.text +0 -14
  143. data/test/MarkdownTest_1.0.3/Code Spans.text +0 -6
  144. data/test/MarkdownTest_1.0.3/Hard-wrapped paragraphs with list-like lines.text +0 -8
  145. data/test/MarkdownTest_1.0.3/Horizontal rules.text +0 -67
  146. data/test/MarkdownTest_1.0.3/Inline HTML (Advanced).text +0 -15
  147. data/test/MarkdownTest_1.0.3/Inline HTML (Simple).text +0 -69
  148. data/test/MarkdownTest_1.0.3/Inline HTML comments.text +0 -13
  149. data/test/MarkdownTest_1.0.3/Links, inline style.text +0 -12
  150. data/test/MarkdownTest_1.0.3/Links, reference style.text +0 -71
  151. data/test/MarkdownTest_1.0.3/Links, shortcut references.text +0 -20
  152. data/test/MarkdownTest_1.0.3/Literal quotes in titles.text +0 -7
  153. data/test/MarkdownTest_1.0.3/Markdown Documentation - Basics.text +0 -306
  154. data/test/MarkdownTest_1.0.3/Markdown Documentation - Syntax.text +0 -888
  155. data/test/MarkdownTest_1.0.3/Nested blockquotes.text +0 -5
  156. data/test/MarkdownTest_1.0.3/Ordered and unordered lists.text +0 -131
  157. data/test/MarkdownTest_1.0.3/Strong and em together.text +0 -7
  158. data/test/MarkdownTest_1.0.3/Tabs.text +0 -21
  159. data/test/MarkdownTest_1.0.3/Tidyness.text +0 -5
  160. data/test/README +0 -1
  161. data/test/binary.dat +0 -0
  162. data/test/hidden.zip.txt +0 -1
  163. data/test/test.ja.largedoc +0 -3
  164. data/test/test.ja.rdoc +0 -10
  165. data/test/test.ja.txt +0 -8
  166. data/test/test.txt +0 -1
  167. data/test/test_rdoc_alias.rb +0 -13
  168. data/test/test_rdoc_any_method.rb +0 -460
  169. data/test/test_rdoc_attr.rb +0 -190
  170. data/test/test_rdoc_class_module.rb +0 -1492
  171. data/test/test_rdoc_code_object.rb +0 -450
  172. data/test/test_rdoc_comment.rb +0 -504
  173. data/test/test_rdoc_constant.rb +0 -181
  174. data/test/test_rdoc_context.rb +0 -901
  175. data/test/test_rdoc_context_section.rb +0 -130
  176. data/test/test_rdoc_cross_reference.rb +0 -192
  177. data/test/test_rdoc_encoding.rb +0 -227
  178. data/test/test_rdoc_extend.rb +0 -94
  179. data/test/test_rdoc_generator_darkfish.rb +0 -229
  180. data/test/test_rdoc_generator_json_index.rb +0 -324
  181. data/test/test_rdoc_generator_markup.rb +0 -59
  182. data/test/test_rdoc_generator_pot.rb +0 -91
  183. data/test/test_rdoc_generator_pot_po.rb +0 -51
  184. data/test/test_rdoc_generator_pot_po_entry.rb +0 -139
  185. data/test/test_rdoc_generator_ri.rb +0 -78
  186. data/test/test_rdoc_i18n_locale.rb +0 -73
  187. data/test/test_rdoc_i18n_text.rb +0 -123
  188. data/test/test_rdoc_include.rb +0 -108
  189. data/test/test_rdoc_markdown.rb +0 -980
  190. data/test/test_rdoc_markdown_test.rb +0 -1884
  191. data/test/test_rdoc_markup.rb +0 -95
  192. data/test/test_rdoc_markup_attribute_manager.rb +0 -364
  193. data/test/test_rdoc_markup_attributes.rb +0 -39
  194. data/test/test_rdoc_markup_document.rb +0 -207
  195. data/test/test_rdoc_markup_formatter.rb +0 -175
  196. data/test/test_rdoc_markup_hard_break.rb +0 -31
  197. data/test/test_rdoc_markup_heading.rb +0 -29
  198. data/test/test_rdoc_markup_include.rb +0 -19
  199. data/test/test_rdoc_markup_indented_paragraph.rb +0 -53
  200. data/test/test_rdoc_markup_paragraph.rb +0 -32
  201. data/test/test_rdoc_markup_parser.rb +0 -1680
  202. data/test/test_rdoc_markup_pre_process.rb +0 -473
  203. data/test/test_rdoc_markup_raw.rb +0 -22
  204. data/test/test_rdoc_markup_to_ansi.rb +0 -369
  205. data/test/test_rdoc_markup_to_bs.rb +0 -366
  206. data/test/test_rdoc_markup_to_html.rb +0 -662
  207. data/test/test_rdoc_markup_to_html_crossref.rb +0 -225
  208. data/test/test_rdoc_markup_to_html_snippet.rb +0 -711
  209. data/test/test_rdoc_markup_to_joined_paragraph.rb +0 -32
  210. data/test/test_rdoc_markup_to_label.rb +0 -112
  211. data/test/test_rdoc_markup_to_markdown.rb +0 -389
  212. data/test/test_rdoc_markup_to_rdoc.rb +0 -377
  213. data/test/test_rdoc_markup_to_table_of_contents.rb +0 -126
  214. data/test/test_rdoc_markup_to_tt_only.rb +0 -246
  215. data/test/test_rdoc_markup_verbatim.rb +0 -29
  216. data/test/test_rdoc_method_attr.rb +0 -193
  217. data/test/test_rdoc_normal_class.rb +0 -47
  218. data/test/test_rdoc_normal_module.rb +0 -42
  219. data/test/test_rdoc_options.rb +0 -766
  220. data/test/test_rdoc_parser.rb +0 -327
  221. data/test/test_rdoc_parser_c.rb +0 -1896
  222. data/test/test_rdoc_parser_changelog.rb +0 -315
  223. data/test/test_rdoc_parser_markdown.rb +0 -61
  224. data/test/test_rdoc_parser_rd.rb +0 -55
  225. data/test/test_rdoc_parser_ruby.rb +0 -3322
  226. data/test/test_rdoc_parser_simple.rb +0 -115
  227. data/test/test_rdoc_rd.rb +0 -30
  228. data/test/test_rdoc_rd_block_parser.rb +0 -535
  229. data/test/test_rdoc_rd_inline.rb +0 -63
  230. data/test/test_rdoc_rd_inline_parser.rb +0 -177
  231. data/test/test_rdoc_rdoc.rb +0 -455
  232. data/test/test_rdoc_require.rb +0 -25
  233. data/test/test_rdoc_ri_driver.rb +0 -1436
  234. data/test/test_rdoc_ri_paths.rb +0 -155
  235. data/test/test_rdoc_ruby_lex.rb +0 -421
  236. data/test/test_rdoc_ruby_token.rb +0 -19
  237. data/test/test_rdoc_rubygems_hook.rb +0 -251
  238. data/test/test_rdoc_servlet.rb +0 -534
  239. data/test/test_rdoc_single_class.rb +0 -20
  240. data/test/test_rdoc_stats.rb +0 -722
  241. data/test/test_rdoc_store.rb +0 -993
  242. data/test/test_rdoc_task.rb +0 -173
  243. data/test/test_rdoc_text.rb +0 -557
  244. data/test/test_rdoc_token_stream.rb +0 -42
  245. data/test/test_rdoc_tom_doc.rb +0 -520
  246. data/test/test_rdoc_top_level.rb +0 -287
  247. data/test/xref_data.rb +0 -76
  248. data/test/xref_test_case.rb +0 -67
@@ -1,315 +0,0 @@
1
- require 'rdoc/test_case'
2
-
3
- class TestRDocParserChangeLog < RDoc::TestCase
4
-
5
- def setup
6
- super
7
-
8
- @tempfile = Tempfile.new 'ChangeLog'
9
- @top_level = @store.add_file @tempfile.path
10
- @options = RDoc::Options.new
11
- @stats = RDoc::Stats.new @store, 0
12
- end
13
-
14
- def teardown
15
- @tempfile.close!
16
- end
17
-
18
- def test_class_can_parse
19
- parser = RDoc::Parser::ChangeLog
20
-
21
- temp_dir do
22
- FileUtils.touch 'ChangeLog'
23
- assert_equal parser, parser.can_parse('ChangeLog')
24
-
25
- assert_equal parser, parser.can_parse(@tempfile.path)
26
-
27
- FileUtils.touch 'ChangeLog.rb'
28
- assert_equal RDoc::Parser::Ruby, parser.can_parse('ChangeLog.rb')
29
- end
30
- end
31
-
32
- def test_continue_entry_body
33
- parser = util_parser
34
-
35
- entry_body = ['a']
36
-
37
- parser.continue_entry_body entry_body, 'b'
38
-
39
- assert_equal ['a b'], entry_body
40
- end
41
-
42
- def test_continue_entry_body_empty
43
- parser = util_parser
44
-
45
- entry_body = []
46
-
47
- parser.continue_entry_body entry_body, ''
48
-
49
- assert_empty entry_body
50
- end
51
-
52
- def test_continue_entry_body_function
53
- parser = util_parser
54
-
55
- entry_body = ['file: (func1)']
56
-
57
- parser.continue_entry_body entry_body, '(func2): blah'
58
-
59
- assert_equal ['file: (func1, func2): blah'], entry_body
60
- end
61
-
62
- def test_create_document
63
- parser = util_parser
64
-
65
- groups = {
66
- '2012-12-04' => [
67
- ['Tue Dec 4 08:33:46 2012 Eric Hodel <drbrain@segment7.net>',
68
- %w[a:one b:two]],
69
- ['Tue Dec 4 08:32:10 2012 Eric Hodel <drbrain@segment7.net>',
70
- %w[c:three d:four]]],
71
- '2012-12-03' => [
72
- ['Mon Dec 3 20:28:02 2012 Koichi Sasada <ko1@atdot.net>',
73
- %w[e:five f:six]]],
74
- }
75
-
76
- expected =
77
- doc(
78
- head(1, File.basename(@tempfile.path)),
79
- blank_line,
80
- head(2, '2012-12-04'),
81
- blank_line,
82
- head(3, 'Tue Dec 4 08:33:46 2012 Eric Hodel <drbrain@segment7.net>'),
83
- blank_line,
84
- list(:NOTE, item('a', para('one')), item('b', para('two'))),
85
- head(3, 'Tue Dec 4 08:32:10 2012 Eric Hodel <drbrain@segment7.net>'),
86
- blank_line,
87
- list(:NOTE, item('c', para('three')), item('d', para('four'))),
88
- head(2, '2012-12-03'),
89
- blank_line,
90
- head(3, 'Mon Dec 3 20:28:02 2012 Koichi Sasada <ko1@atdot.net>'),
91
- blank_line,
92
- list(:NOTE, item('e', para('five')), item('f', para('six'))))
93
-
94
- expected.file = @top_level
95
-
96
- document = parser.create_document(groups)
97
-
98
- assert_equal expected, document
99
-
100
- assert_equal 2, document.omit_headings_below
101
-
102
- headings = document.parts.select do |part|
103
- RDoc::Markup::Heading === part and part.level == 2
104
- end
105
-
106
- refute headings.all? { |heading| heading.text.frozen? }
107
- end
108
-
109
- def test_create_entries
110
- parser = util_parser
111
-
112
- entries = [
113
- ['Tue Dec 1 02:03:04 2012 Eric Hodel <drbrain@segment7.net>',
114
- %w[a:one b:two]],
115
- ['Tue Dec 5 06:07:08 2012 Eric Hodel <drbrain@segment7.net>',
116
- %w[c:three d:four]],
117
- ]
118
-
119
- expected = [
120
- head(3, 'Tue Dec 1 02:03:04 2012 Eric Hodel <drbrain@segment7.net>'),
121
- blank_line,
122
- list(:NOTE, item('a', para('one')), item('b', para('two'))),
123
- head(3, 'Tue Dec 5 06:07:08 2012 Eric Hodel <drbrain@segment7.net>'),
124
- blank_line,
125
- list(:NOTE, item('c', para('three')), item('d', para('four'))),
126
- ]
127
-
128
- entries = parser.create_entries(entries)
129
- assert_equal expected, entries
130
- end
131
-
132
- def test_create_entries_colons
133
- parser = util_parser
134
-
135
- entries = [
136
- ['Wed Dec 5 12:17:11 2012 Naohisa Goto <ngotogenome@gmail.com>',
137
- ['func.rb (DL::Function#bind): log stuff [ruby-core:50562]']],
138
- ]
139
-
140
- expected = [
141
- head(3,
142
- 'Wed Dec 5 12:17:11 2012 Naohisa Goto <ngotogenome@gmail.com>'),
143
- blank_line,
144
- list(:NOTE,
145
- item('func.rb (DL::Function#bind)',
146
- para('log stuff [ruby-core:50562]')))]
147
-
148
- assert_equal expected, parser.create_entries(entries)
149
- end
150
-
151
- def test_create_items
152
- parser = util_parser
153
-
154
- items = [
155
- 'README.EXT: Converted to RDoc format',
156
- 'README.EXT.ja: ditto',
157
- ]
158
-
159
- expected =
160
- list(:NOTE,
161
- item('README.EXT',
162
- para('Converted to RDoc format')),
163
- item('README.EXT.ja',
164
- para('ditto')))
165
-
166
- assert_equal expected, parser.create_items(items)
167
- end
168
-
169
- def test_group_entries
170
- parser = util_parser
171
-
172
- entries = [
173
- [ 'Tue Dec 4 08:33:46 2012 Eric Hodel <drbrain@segment7.net>',
174
- %w[one two]],
175
- [ 'Tue Dec 4 08:32:10 2012 Eric Hodel <drbrain@segment7.net>',
176
- %w[three four]],
177
- [ 'Mon Dec 3 20:28:02 2012 Koichi Sasada <ko1@atdot.net>',
178
- %w[five six]],
179
- [ '2008-01-30 H.J. Lu <hongjiu.lu@intel.com>',
180
- %w[seven eight]]]
181
-
182
- expected = {
183
- '2012-12-04' => [
184
- ['Tue Dec 4 08:33:46 2012 Eric Hodel <drbrain@segment7.net>',
185
- %w[one two]],
186
- ['Tue Dec 4 08:32:10 2012 Eric Hodel <drbrain@segment7.net>',
187
- %w[three four]]],
188
- '2012-12-03' => [
189
- ['Mon Dec 3 20:28:02 2012 Koichi Sasada <ko1@atdot.net>',
190
- %w[five six]]],
191
- '2008-01-30' => [
192
- ['2008-01-30 H.J. Lu <hongjiu.lu@intel.com>',
193
- %w[seven eight]]],
194
- }
195
-
196
- assert_equal expected, parser.group_entries(entries)
197
- end
198
-
199
- def test_parse_entries
200
- parser = util_parser <<-ChangeLog
201
- Tue Dec 4 08:33:46 2012 Eric Hodel <drbrain@segment7.net>
202
-
203
- * README.EXT: Converted to RDoc format
204
- * README.EXT.ja: ditto
205
-
206
- Mon Dec 3 20:28:02 2012 Koichi Sasada <ko1@atdot.net>
207
-
208
- * compile.c (iseq_specialized_instruction):
209
- change condition of using `opt_send_simple'.
210
- More method invocations can be simple.
211
-
212
- Other note that will be ignored
213
-
214
- ChangeLog
215
-
216
- expected = [
217
- [ 'Tue Dec 4 08:33:46 2012 Eric Hodel <drbrain@segment7.net>',
218
- [ 'README.EXT: Converted to RDoc format',
219
- 'README.EXT.ja: ditto']],
220
- [ 'Mon Dec 3 20:28:02 2012 Koichi Sasada <ko1@atdot.net>',
221
- [ 'compile.c (iseq_specialized_instruction): change condition of ' +
222
- 'using `opt_send_simple\'. More method invocations can be simple.']]]
223
-
224
- assert_equal expected, parser.parse_entries
225
- end
226
-
227
- def test_parse_entries_bad_time
228
- parser = util_parser <<-ChangeLog
229
- 2008-01-30 H.J. Lu <hongjiu.lu@intel.com>
230
-
231
- PR libffi/34612
232
- * src/x86/sysv.S (ffi_closure_SYSV): Pop 4 byte from stack when
233
- returning struct.
234
-
235
- ChangeLog
236
-
237
- expected = [
238
- [ '2008-01-30 H.J. Lu <hongjiu.lu@intel.com>',
239
- [ 'src/x86/sysv.S (ffi_closure_SYSV): Pop 4 byte from stack when ' +
240
- 'returning struct.']]
241
- ]
242
-
243
- assert_equal expected, parser.parse_entries
244
- end
245
-
246
- def test_parse_entries_gnu
247
- parser = util_parser <<-ChangeLog
248
- 1998-08-17 Richard Stallman <rms@gnu.org>
249
-
250
- * register.el (insert-register): Return nil.
251
- (jump-to-register): Likewise.
252
-
253
- * sort.el (sort-subr): Return nil.
254
-
255
- * keyboard.c (menu_bar_items, tool_bar_items)
256
- (Fexecute_extended_command): Deal with 'keymap' property.
257
- ChangeLog
258
-
259
- expected = [
260
- [ '1998-08-17 Richard Stallman <rms@gnu.org>',
261
- [ 'register.el (insert-register): Return nil.',
262
- '(jump-to-register): Likewise.',
263
- 'sort.el (sort-subr): Return nil.',
264
- 'keyboard.c (menu_bar_items, tool_bar_items, ' +
265
- 'Fexecute_extended_command): Deal with \'keymap\' property.']]]
266
-
267
- assert_equal expected, parser.parse_entries
268
- end
269
-
270
- def test_scan
271
- parser = util_parser <<-ChangeLog
272
- Tue Dec 4 08:32:10 2012 Eric Hodel <drbrain@segment7.net>
273
-
274
- * lib/rdoc/ri/driver.rb: Fixed ri page display for files with
275
- extensions.
276
- * test/rdoc/test_rdoc_ri_driver.rb: Test for above
277
-
278
- Mon Dec 3 20:37:22 2012 Koichi Sasada <ko1@atdot.net>
279
-
280
- * vm_exec.c: check VM_COLLECT_USAGE_DETAILS.
281
-
282
- ChangeLog
283
-
284
- parser.scan
285
-
286
- expected = doc(
287
- head(1, File.basename(@tempfile.path)),
288
- blank_line,
289
- head(2, '2012-12-04'),
290
- blank_line,
291
- head(3, 'Tue Dec 4 08:32:10 2012 Eric Hodel <drbrain@segment7.net>'),
292
- blank_line,
293
- list(:NOTE,
294
- item('lib/rdoc/ri/driver.rb', para('Fixed ri page display for ' +
295
- 'files with extensions.')),
296
- item('test/rdoc/test_rdoc_ri_driver.rb', para('Test for above'))),
297
- head(2, '2012-12-03'),
298
- blank_line,
299
- head(3, 'Mon Dec 3 20:37:22 2012 Koichi Sasada <ko1@atdot.net>'),
300
- blank_line,
301
- list(:NOTE,
302
- item('vm_exec.c', para('check VM_COLLECT_USAGE_DETAILS.'))))
303
-
304
- expected.file = @top_level
305
-
306
- assert_equal expected, @top_level.comment
307
- end
308
-
309
- def util_parser content = ''
310
- RDoc::Parser::ChangeLog.new \
311
- @top_level, @tempfile.path, content, @options, @stats
312
- end
313
-
314
- end
315
-
@@ -1,61 +0,0 @@
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
- temp_dir do
31
- FileUtils.touch 'foo.md'
32
- assert_equal @RP::Markdown, @RP.can_parse('foo.md')
33
- FileUtils.touch 'foo.md.ja'
34
- assert_equal @RP::Markdown, @RP.can_parse('foo.md.ja')
35
-
36
- FileUtils.touch 'foo.markdown'
37
- assert_equal @RP::Markdown, @RP.can_parse('foo.markdown')
38
- FileUtils.touch 'foo.markdown.ja'
39
- assert_equal @RP::Markdown, @RP.can_parse('foo.markdown.ja')
40
- end
41
- end
42
-
43
- def test_scan
44
- parser = util_parser 'it *really* works'
45
-
46
- expected =
47
- @RM::Document.new(
48
- @RM::Paragraph.new('it _really_ works'))
49
- expected.file = @top_level
50
-
51
- parser.scan
52
-
53
- assert_equal expected, @top_level.comment.parse
54
- end
55
-
56
- def util_parser content
57
- RDoc::Parser::Markdown.new @top_level, @fn, content, @options, @stats
58
- end
59
-
60
- end
61
-
@@ -1,55 +0,0 @@
1
- require 'rdoc/test_case'
2
-
3
- class TestRDocParserRd < 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
- temp_dir do
31
- FileUtils.touch 'foo.rd'
32
- assert_equal @RP::RD, @RP.can_parse('foo.rd')
33
-
34
- FileUtils.touch 'foo.rd.ja'
35
- assert_equal @RP::RD, @RP.can_parse('foo.rd.ja')
36
- end
37
- end
38
-
39
- def test_scan
40
- parser = util_parser 'it ((*really*)) works'
41
-
42
- expected = doc(para('it <em>really</em> 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::RD.new @top_level, @fn, content, @options, @stats
52
- end
53
-
54
- end
55
-
@@ -1,3322 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'rdoc/test_case'
4
-
5
- class TestRDocParserRuby < RDoc::TestCase
6
-
7
- def setup
8
- super
9
-
10
- @tempfile = Tempfile.new self.class.name
11
- @filename = @tempfile.path
12
-
13
- # Some tests need two paths.
14
- @tempfile2 = Tempfile.new self.class.name
15
- @filename2 = @tempfile2.path
16
-
17
- @top_level = @store.add_file @filename
18
- @top_level2 = @store.add_file @filename2
19
-
20
- @options = RDoc::Options.new
21
- @options.quiet = true
22
- @options.option_parser = OptionParser.new
23
-
24
- @comment = RDoc::Comment.new '', @top_level
25
-
26
- @stats = RDoc::Stats.new @store, 0
27
- end
28
-
29
- def teardown
30
- super
31
-
32
- @tempfile.close!
33
- @tempfile2.close!
34
- end
35
-
36
- def test_collect_first_comment
37
- p = util_parser <<-CONTENT
38
- # first
39
-
40
- # second
41
- class C; end
42
- CONTENT
43
-
44
- comment = p.collect_first_comment
45
-
46
- assert_equal RDoc::Comment.new("# first\n", @top_level), comment
47
- end
48
-
49
- def test_collect_first_comment_encoding
50
- skip "Encoding not implemented" unless Object.const_defined? :Encoding
51
-
52
- @options.encoding = Encoding::CP852
53
-
54
- p = util_parser <<-CONTENT
55
- # first
56
-
57
- # second
58
- class C; end
59
- CONTENT
60
-
61
- comment = p.collect_first_comment
62
-
63
- assert_equal Encoding::CP852, comment.text.encoding
64
- end
65
-
66
- def test_collect_first_comment_rd_hash
67
- parser = util_parser <<-CONTENT
68
- =begin
69
- first
70
- =end
71
-
72
- # second
73
- class C; end
74
- CONTENT
75
-
76
- comment = parser.collect_first_comment
77
-
78
- assert_equal RDoc::Comment.new("first\n\n", @top_level), comment
79
- end
80
-
81
- def test_get_class_or_module
82
- ctxt = RDoc::Context.new
83
- ctxt.store = @store
84
-
85
- cont, name_t, given_name = util_parser('A') .get_class_or_module ctxt
86
-
87
- assert_equal ctxt, cont
88
- assert_equal 'A', name_t.text
89
- assert_equal 'A', given_name
90
-
91
- cont, name_t, given_name = util_parser('B::C') .get_class_or_module ctxt
92
-
93
- b = @store.find_module_named('B')
94
- assert_equal b, cont
95
- assert_equal [@top_level], b.in_files
96
- assert_equal 'C', name_t.text
97
- assert_equal 'B::C', given_name
98
-
99
- cont, name_t, given_name = util_parser('D:: E').get_class_or_module ctxt
100
-
101
- assert_equal @store.find_module_named('D'), cont
102
- assert_equal 'E', name_t.text
103
- assert_equal 'D::E', given_name
104
-
105
- assert_raises NoMethodError do
106
- util_parser("A::\nB").get_class_or_module ctxt
107
- end
108
- end
109
-
110
- def test_get_class_or_module_document_children
111
- ctxt = @top_level.add_class RDoc::NormalClass, 'A'
112
- ctxt.stop_doc
113
-
114
- util_parser('B::C').get_class_or_module ctxt
115
-
116
- b = @store.find_module_named('A::B')
117
- assert b.ignored?
118
-
119
- d = @top_level.add_class RDoc::NormalClass, 'A::D'
120
-
121
- util_parser('D::E').get_class_or_module ctxt
122
-
123
- refute d.ignored?
124
- end
125
-
126
- def test_get_class_or_module_ignore_constants
127
- ctxt = RDoc::Context.new
128
- ctxt.store = @store
129
-
130
- util_parser('A') .get_class_or_module ctxt, true
131
- util_parser('A::B').get_class_or_module ctxt, true
132
-
133
- assert_empty ctxt.constants
134
- assert_empty @store.modules_hash.keys
135
- assert_empty @store.classes_hash.keys
136
- end
137
-
138
- def test_get_class_specification
139
- assert_equal 'A', util_parser('A') .get_class_specification
140
- assert_equal 'A::B', util_parser('A::B').get_class_specification
141
- assert_equal '::A', util_parser('::A').get_class_specification
142
-
143
- assert_equal 'self', util_parser('self').get_class_specification
144
-
145
- assert_equal '', util_parser('').get_class_specification
146
-
147
- assert_equal '', util_parser('$g').get_class_specification
148
- end
149
-
150
- def test_get_symbol_or_name
151
- util_parser "* & | + 5 / 4"
152
-
153
- assert_equal '*', @parser.get_symbol_or_name
154
-
155
- @parser.skip_tkspace
156
-
157
- assert_equal '&', @parser.get_symbol_or_name
158
-
159
- @parser.skip_tkspace
160
-
161
- assert_equal '|', @parser.get_symbol_or_name
162
-
163
- @parser.skip_tkspace
164
-
165
- assert_equal '+', @parser.get_symbol_or_name
166
-
167
- @parser.skip_tkspace
168
- @parser.get_tk
169
- @parser.skip_tkspace
170
-
171
- assert_equal '/', @parser.get_symbol_or_name
172
- end
173
-
174
- def test_suppress_parents
175
- a = @top_level.add_class RDoc::NormalClass, 'A'
176
- b = a.add_class RDoc::NormalClass, 'B'
177
- c = b.add_class RDoc::NormalClass, 'C'
178
-
179
- util_parser ''
180
-
181
- @parser.suppress_parents c, a
182
-
183
- assert c.suppressed?
184
- assert b.suppressed?
185
- refute a.suppressed?
186
- end
187
-
188
- def test_suppress_parents_documented
189
- a = @top_level.add_class RDoc::NormalClass, 'A'
190
- b = a.add_class RDoc::NormalClass, 'B'
191
- b.add_comment RDoc::Comment.new("hello"), @top_level
192
- c = b.add_class RDoc::NormalClass, 'C'
193
-
194
- util_parser ''
195
-
196
- @parser.suppress_parents c, a
197
-
198
- assert c.suppressed?
199
- refute b.suppressed?
200
- refute a.suppressed?
201
- end
202
-
203
- def test_look_for_directives_in_attr
204
- util_parser ""
205
-
206
- comment = RDoc::Comment.new "# :attr: my_attr\n", @top_level
207
-
208
- @parser.look_for_directives_in @top_level, comment
209
-
210
- assert_equal "# :attr: my_attr\n", comment.text
211
-
212
- comment = RDoc::Comment.new "# :attr_reader: my_method\n", @top_level
213
-
214
- @parser.look_for_directives_in @top_level, comment
215
-
216
- assert_equal "# :attr_reader: my_method\n", comment.text
217
-
218
- comment = RDoc::Comment.new "# :attr_writer: my_method\n", @top_level
219
-
220
- @parser.look_for_directives_in @top_level, comment
221
-
222
- assert_equal "# :attr_writer: my_method\n", comment.text
223
- end
224
-
225
- def test_look_for_directives_in_commented
226
- util_parser ""
227
-
228
- comment = RDoc::Comment.new <<-COMMENT, @top_level
229
- # how to make a section:
230
- # # :section: new section
231
- COMMENT
232
-
233
- @parser.look_for_directives_in @top_level, comment
234
-
235
- section = @top_level.current_section
236
- assert_equal nil, section.title
237
- assert_equal nil, section.comment
238
-
239
- assert_equal "# how to make a section:\n# # :section: new section\n",
240
- comment.text
241
- end
242
-
243
- def test_look_for_directives_in_method
244
- util_parser ""
245
-
246
- comment = RDoc::Comment.new "# :method: my_method\n", @top_level
247
-
248
- @parser.look_for_directives_in @top_level, comment
249
-
250
- assert_equal "# :method: my_method\n", comment.text
251
-
252
- comment = RDoc::Comment.new "# :singleton-method: my_method\n", @top_level
253
-
254
- @parser.look_for_directives_in @top_level, comment
255
-
256
- assert_equal "# :singleton-method: my_method\n", comment.text
257
- end
258
-
259
- def test_look_for_directives_in_section
260
- util_parser ""
261
-
262
- comment = RDoc::Comment.new <<-COMMENT, @top_level
263
- # :section: new section
264
- # woo stuff
265
- COMMENT
266
-
267
- @parser.look_for_directives_in @top_level, comment
268
-
269
- section = @top_level.current_section
270
- assert_equal 'new section', section.title
271
- assert_equal [comment("# woo stuff\n", @top_level)], section.comments
272
-
273
- assert_empty comment
274
- end
275
-
276
- def test_look_for_directives_in_unhandled
277
- util_parser ""
278
-
279
- comment = RDoc::Comment.new "# :unhandled: blah\n", @top_level
280
-
281
- @parser.look_for_directives_in @top_level, comment
282
-
283
- assert_equal 'blah', @top_level.metadata['unhandled']
284
- end
285
-
286
- def test_parse_alias
287
- klass = RDoc::NormalClass.new 'Foo'
288
- klass.parent = @top_level
289
-
290
- util_parser "alias :next= :bar"
291
-
292
- tk = @parser.get_tk
293
-
294
- alas = @parser.parse_alias klass, RDoc::Parser::Ruby::NORMAL, tk, 'comment'
295
-
296
- assert_equal 'bar', alas.old_name
297
- assert_equal 'next=', alas.new_name
298
- assert_equal klass, alas.parent
299
- assert_equal 'comment', alas.comment
300
- assert_equal @top_level, alas.file
301
- assert_equal 0, alas.offset
302
- assert_equal 1, alas.line
303
- end
304
-
305
- def test_parse_alias_singleton
306
- klass = RDoc::NormalClass.new 'Foo'
307
- klass.parent = @top_level
308
-
309
- util_parser "alias :next= :bar"
310
-
311
- tk = @parser.get_tk
312
-
313
- alas = @parser.parse_alias klass, RDoc::Parser::Ruby::SINGLE, tk, 'comment'
314
-
315
- assert_equal 'bar', alas.old_name
316
- assert_equal 'next=', alas.new_name
317
- assert_equal klass, alas.parent
318
- assert_equal 'comment', alas.comment
319
- assert_equal @top_level, alas.file
320
- assert alas.singleton
321
- end
322
-
323
- def test_parse_alias_stopdoc
324
- klass = RDoc::NormalClass.new 'Foo'
325
- klass.parent = @top_level
326
- klass.stop_doc
327
-
328
- util_parser "alias :next= :bar"
329
-
330
- tk = @parser.get_tk
331
-
332
- @parser.parse_alias klass, RDoc::Parser::Ruby::NORMAL, tk, 'comment'
333
-
334
- assert_empty klass.aliases
335
- assert_empty klass.unmatched_alias_lists
336
- end
337
-
338
- def test_parse_alias_meta
339
- klass = RDoc::NormalClass.new 'Foo'
340
- klass.parent = @top_level
341
-
342
- util_parser "alias m.chop m"
343
-
344
- tk = @parser.get_tk
345
-
346
- alas = @parser.parse_alias klass, RDoc::Parser::Ruby::NORMAL, tk, 'comment'
347
-
348
- assert_nil alas
349
- end
350
-
351
- def test_parse_attr
352
- klass = RDoc::NormalClass.new 'Foo'
353
- klass.parent = @top_level
354
-
355
- comment = RDoc::Comment.new "##\n# my attr\n", @top_level
356
-
357
- util_parser "attr :foo, :bar"
358
-
359
- tk = @parser.get_tk
360
-
361
- @parser.parse_attr klass, RDoc::Parser::Ruby::NORMAL, tk, comment
362
-
363
- assert_equal 1, klass.attributes.length
364
-
365
- foo = klass.attributes.first
366
- assert_equal 'foo', foo.name
367
- assert_equal 'my attr', foo.comment.text
368
- assert_equal @top_level, foo.file
369
- assert_equal 0, foo.offset
370
- assert_equal 1, foo.line
371
- end
372
-
373
- def test_parse_attr_stopdoc
374
- klass = RDoc::NormalClass.new 'Foo'
375
- klass.parent = @top_level
376
- klass.stop_doc
377
-
378
- comment = RDoc::Comment.new "##\n# my attr\n", @top_level
379
-
380
- util_parser "attr :foo, :bar"
381
-
382
- tk = @parser.get_tk
383
-
384
- @parser.parse_attr klass, RDoc::Parser::Ruby::NORMAL, tk, comment
385
-
386
- assert_empty klass.attributes
387
- end
388
-
389
- def test_parse_attr_accessor
390
- klass = RDoc::NormalClass.new 'Foo'
391
- klass.parent = @top_level
392
-
393
- comment = RDoc::Comment.new "##\n# my attr\n", @top_level
394
-
395
- util_parser "attr_accessor :foo, :bar"
396
-
397
- tk = @parser.get_tk
398
-
399
- @parser.parse_attr_accessor klass, RDoc::Parser::Ruby::NORMAL, tk, comment
400
-
401
- assert_equal 2, klass.attributes.length
402
-
403
- foo = klass.attributes.first
404
- assert_equal 'foo', foo.name
405
- assert_equal 'RW', foo.rw
406
- assert_equal 'my attr', foo.comment.text
407
- assert_equal @top_level, foo.file
408
- assert_equal 0, foo.offset
409
- assert_equal 1, foo.line
410
-
411
- bar = klass.attributes.last
412
- assert_equal 'bar', bar.name
413
- assert_equal 'RW', bar.rw
414
- assert_equal 'my attr', bar.comment.text
415
- end
416
-
417
- def test_parse_attr_accessor_nodoc
418
- klass = RDoc::NormalClass.new 'Foo'
419
- klass.parent = @top_level
420
-
421
- comment = RDoc::Comment.new "##\n# my attr\n", @top_level
422
-
423
- util_parser "attr_accessor :foo, :bar # :nodoc:"
424
-
425
- tk = @parser.get_tk
426
-
427
- @parser.parse_attr_accessor klass, RDoc::Parser::Ruby::NORMAL, tk, comment
428
-
429
- assert_equal 0, klass.attributes.length
430
- end
431
-
432
- def test_parse_attr_accessor_nodoc_track
433
- klass = RDoc::NormalClass.new 'Foo'
434
- klass.parent = @top_level
435
-
436
- comment = RDoc::Comment.new "##\n# my attr\n", @top_level
437
-
438
- @options.visibility = :nodoc
439
-
440
- util_parser "attr_accessor :foo, :bar # :nodoc:"
441
-
442
- tk = @parser.get_tk
443
-
444
- @parser.parse_attr_accessor klass, RDoc::Parser::Ruby::NORMAL, tk, comment
445
-
446
- refute_empty klass.attributes
447
- end
448
-
449
- def test_parse_attr_accessor_stopdoc
450
- klass = RDoc::NormalClass.new 'Foo'
451
- klass.parent = @top_level
452
- klass.stop_doc
453
-
454
- comment = RDoc::Comment.new "##\n# my attr\n", @top_level
455
-
456
- util_parser "attr_accessor :foo, :bar"
457
-
458
- tk = @parser.get_tk
459
-
460
- @parser.parse_attr_accessor klass, RDoc::Parser::Ruby::NORMAL, tk, comment
461
-
462
- assert_empty klass.attributes
463
- end
464
-
465
- def test_parse_attr_accessor_writer
466
- klass = RDoc::NormalClass.new 'Foo'
467
- klass.parent = @top_level
468
-
469
- comment = RDoc::Comment.new "##\n# my attr\n", @top_level
470
-
471
- util_parser "attr_writer :foo, :bar"
472
-
473
- tk = @parser.get_tk
474
-
475
- @parser.parse_attr_accessor klass, RDoc::Parser::Ruby::NORMAL, tk, comment
476
-
477
- assert_equal 2, klass.attributes.length
478
-
479
- foo = klass.attributes.first
480
- assert_equal 'foo', foo.name
481
- assert_equal 'W', foo.rw
482
- assert_equal "my attr", foo.comment.text
483
- assert_equal @top_level, foo.file
484
-
485
- bar = klass.attributes.last
486
- assert_equal 'bar', bar.name
487
- assert_equal 'W', bar.rw
488
- assert_equal "my attr", bar.comment.text
489
- end
490
-
491
- def test_parse_meta_attr
492
- klass = RDoc::NormalClass.new 'Foo'
493
- klass.parent = @top_level
494
-
495
- comment = RDoc::Comment.new "##\n# :attr: \n# my method\n", @top_level
496
-
497
- util_parser "add_my_method :foo, :bar"
498
-
499
- tk = @parser.get_tk
500
-
501
- @parser.parse_meta_attr klass, RDoc::Parser::Ruby::NORMAL, tk, comment
502
-
503
- assert_equal 2, klass.attributes.length
504
- foo = klass.attributes.first
505
- assert_equal 'foo', foo.name
506
- assert_equal 'RW', foo.rw
507
- assert_equal "my method", foo.comment.text
508
- assert_equal @top_level, foo.file
509
- end
510
-
511
- def test_parse_meta_attr_accessor
512
- klass = RDoc::NormalClass.new 'Foo'
513
- klass.parent = @top_level
514
-
515
- comment =
516
- RDoc::Comment.new "##\n# :attr_accessor: \n# my method\n", @top_level
517
-
518
- util_parser "add_my_method :foo, :bar"
519
-
520
- tk = @parser.get_tk
521
-
522
- @parser.parse_meta_attr klass, RDoc::Parser::Ruby::NORMAL, tk, comment
523
-
524
- assert_equal 2, klass.attributes.length
525
- foo = klass.attributes.first
526
- assert_equal 'foo', foo.name
527
- assert_equal 'RW', foo.rw
528
- assert_equal 'my method', foo.comment.text
529
- assert_equal @top_level, foo.file
530
- end
531
-
532
- def test_parse_meta_attr_named
533
- klass = RDoc::NormalClass.new 'Foo'
534
- klass.parent = @top_level
535
-
536
- comment = RDoc::Comment.new "##\n# :attr: foo\n# my method\n", @top_level
537
-
538
- util_parser "add_my_method :foo, :bar"
539
-
540
- tk = @parser.get_tk
541
-
542
- @parser.parse_meta_attr klass, RDoc::Parser::Ruby::NORMAL, tk, comment
543
-
544
- assert_equal 1, klass.attributes.length
545
- foo = klass.attributes.first
546
- assert_equal 'foo', foo.name
547
- assert_equal 'RW', foo.rw
548
- assert_equal 'my method', foo.comment.text
549
- assert_equal @top_level, foo.file
550
- end
551
-
552
- def test_parse_meta_attr_reader
553
- klass = RDoc::NormalClass.new 'Foo'
554
- klass.parent = @top_level
555
-
556
- comment =
557
- RDoc::Comment.new "##\n# :attr_reader: \n# my method\n", @top_level
558
-
559
- util_parser "add_my_method :foo, :bar"
560
-
561
- tk = @parser.get_tk
562
-
563
- @parser.parse_meta_attr klass, RDoc::Parser::Ruby::NORMAL, tk, comment
564
-
565
- foo = klass.attributes.first
566
- assert_equal 'foo', foo.name
567
- assert_equal 'R', foo.rw
568
- assert_equal 'my method', foo.comment.text
569
- assert_equal @top_level, foo.file
570
- end
571
-
572
- def test_parse_meta_attr_stopdoc
573
- klass = RDoc::NormalClass.new 'Foo'
574
- klass.parent = @top_level
575
- klass.stop_doc
576
-
577
- comment = RDoc::Comment.new "##\n# :attr: \n# my method\n", @top_level
578
-
579
- util_parser "add_my_method :foo, :bar"
580
-
581
- tk = @parser.get_tk
582
-
583
- @parser.parse_meta_attr klass, RDoc::Parser::Ruby::NORMAL, tk, comment
584
-
585
- assert_empty klass.attributes
586
- end
587
-
588
- def test_parse_meta_attr_writer
589
- klass = RDoc::NormalClass.new 'Foo'
590
- klass.parent = @top_level
591
-
592
- comment =
593
- RDoc::Comment.new "##\n# :attr_writer: \n# my method\n", @top_level
594
-
595
- util_parser "add_my_method :foo, :bar"
596
-
597
- tk = @parser.get_tk
598
-
599
- @parser.parse_meta_attr klass, RDoc::Parser::Ruby::NORMAL, tk, comment
600
-
601
- foo = klass.attributes.first
602
- assert_equal 'foo', foo.name
603
- assert_equal 'W', foo.rw
604
- assert_equal "my method", foo.comment.text
605
- assert_equal @top_level, foo.file
606
- end
607
-
608
- def test_parse_class
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 = @top_level.classes.first
618
- assert_equal 'Foo', foo.full_name
619
- assert_equal 'my class', foo.comment.text
620
- assert_equal [@top_level], foo.in_files
621
- assert_equal 0, foo.offset
622
- assert_equal 1, foo.line
623
- end
624
-
625
- def test_parse_class_singleton
626
- comment = RDoc::Comment.new "##\n# my class\n", @top_level
627
-
628
- util_parser <<-RUBY
629
- class C
630
- class << self
631
- end
632
- end
633
- RUBY
634
-
635
- tk = @parser.get_tk
636
-
637
- @parser.parse_class @top_level, RDoc::Parser::Ruby::NORMAL, tk, comment
638
-
639
- c = @top_level.classes.first
640
- assert_equal 'C', c.full_name
641
- assert_equal 0, c.offset
642
- assert_equal 1, c.line
643
- end
644
-
645
- def test_parse_class_ghost_method
646
- util_parser <<-CLASS
647
- class Foo
648
- ##
649
- # :method: blah
650
- # my method
651
- end
652
- CLASS
653
-
654
- tk = @parser.get_tk
655
-
656
- @parser.parse_class @top_level, RDoc::Parser::Ruby::NORMAL, tk, @comment
657
-
658
- foo = @top_level.classes.first
659
- assert_equal 'Foo', foo.full_name
660
-
661
- blah = foo.method_list.first
662
- assert_equal 'Foo#blah', blah.full_name
663
- assert_equal @top_level, blah.file
664
- end
665
-
666
- def test_parse_class_ghost_method_yields
667
- util_parser <<-CLASS
668
- class Foo
669
- ##
670
- # :method:
671
- # :call-seq:
672
- # yields(name)
673
- end
674
- CLASS
675
-
676
- tk = @parser.get_tk
677
-
678
- @parser.parse_class @top_level, RDoc::Parser::Ruby::NORMAL, tk, @comment
679
-
680
- foo = @top_level.classes.first
681
- assert_equal 'Foo', foo.full_name
682
-
683
- blah = foo.method_list.first
684
- assert_equal 'Foo#yields', blah.full_name
685
- assert_equal 'yields(name)', blah.call_seq
686
- assert_equal @top_level, blah.file
687
- end
688
-
689
- def test_parse_class_multi_ghost_methods
690
- util_parser <<-'CLASS'
691
- class Foo
692
- ##
693
- # :method: one
694
- #
695
- # my method
696
-
697
- ##
698
- # :method: two
699
- #
700
- # my method
701
-
702
- [:one, :two].each do |t|
703
- eval("def #{t}; \"#{t}\"; end")
704
- end
705
- end
706
- CLASS
707
-
708
- tk = @parser.get_tk
709
-
710
- @parser.parse_class @top_level, RDoc::Parser::Ruby::NORMAL, tk, @comment
711
-
712
- foo = @top_level.classes.first
713
- assert_equal 'Foo', foo.full_name
714
-
715
- assert_equal 2, foo.method_list.length
716
- end
717
-
718
- def test_parse_class_nodoc
719
- comment = RDoc::Comment.new "##\n# my class\n", @top_level
720
-
721
- util_parser "class Foo # :nodoc:\nend"
722
-
723
- tk = @parser.get_tk
724
-
725
- @parser.parse_class @top_level, RDoc::Parser::Ruby::NORMAL, tk, comment
726
-
727
- foo = @top_level.classes.first
728
- assert_equal 'Foo', foo.full_name
729
- assert_empty foo.comment
730
- assert_equal [@top_level], foo.in_files
731
- assert_equal 0, foo.offset
732
- assert_equal 1, foo.line
733
- end
734
-
735
- def test_parse_class_single_root
736
- comment = RDoc::Comment.new "##\n# my class\n", @top_level
737
-
738
- util_parser "class << ::Foo\nend"
739
-
740
- tk = @parser.get_tk
741
-
742
- @parser.parse_class @top_level, RDoc::Parser::Ruby::NORMAL, tk, comment
743
-
744
- foo = @store.all_modules.first
745
- assert_equal 'Foo', foo.full_name
746
- end
747
-
748
- def test_parse_class_stopdoc
749
- @top_level.stop_doc
750
-
751
- comment = RDoc::Comment.new "##\n# my class\n", @top_level
752
-
753
- util_parser "class Foo\nend"
754
-
755
- tk = @parser.get_tk
756
-
757
- @parser.parse_class @top_level, RDoc::Parser::Ruby::NORMAL, tk, comment
758
-
759
- assert_empty @top_level.classes.first.comment
760
- end
761
-
762
- def test_parse_multi_ghost_methods
763
- util_parser <<-'CLASS'
764
- class Foo
765
- ##
766
- # :method: one
767
- #
768
- # my method
769
-
770
- ##
771
- # :method: two
772
- #
773
- # my method
774
-
775
- [:one, :two].each do |t|
776
- eval("def #{t}; \"#{t}\"; end")
777
- end
778
- end
779
- CLASS
780
-
781
- tk = @parser.get_tk
782
-
783
- @parser.parse_class @top_level, RDoc::Parser::Ruby::NORMAL, tk, @comment
784
-
785
- foo = @top_level.classes.first
786
- assert_equal 'Foo', foo.full_name
787
-
788
- assert_equal 2, foo.method_list.length
789
- end
790
-
791
- def test_parse_const_fail_w_meta
792
- util_parser <<-CLASS
793
- class ConstFailMeta
794
- ##
795
- # :attr: one
796
- #
797
- # an attribute
798
-
799
- OtherModule.define_attr(self, :one)
800
- end
801
- CLASS
802
-
803
- tk = @parser.get_tk
804
-
805
- @parser.parse_class @top_level, RDoc::Parser::Ruby::NORMAL, tk, @comment
806
-
807
- const_fail_meta = @top_level.classes.first
808
- assert_equal 'ConstFailMeta', const_fail_meta.full_name
809
-
810
- assert_equal 1, const_fail_meta.attributes.length
811
- end
812
-
813
- def test_parse_class_nested_superclass
814
- foo = @top_level.add_module RDoc::NormalModule, 'Foo'
815
-
816
- util_parser "class Bar < Super\nend"
817
-
818
- tk = @parser.get_tk
819
-
820
- @parser.parse_class foo, RDoc::Parser::Ruby::NORMAL, tk, @comment
821
-
822
- bar = foo.classes.first
823
- assert_equal 'Super', bar.superclass
824
- end
825
-
826
- def test_parse_module
827
- comment = RDoc::Comment.new "##\n# my module\n", @top_level
828
-
829
- util_parser "module Foo\nend"
830
-
831
- tk = @parser.get_tk
832
-
833
- @parser.parse_module @top_level, RDoc::Parser::Ruby::NORMAL, tk, comment
834
-
835
- foo = @top_level.modules.first
836
- assert_equal 'Foo', foo.full_name
837
- assert_equal 'my module', foo.comment.text
838
- end
839
-
840
- def test_parse_module_nodoc
841
- @top_level.stop_doc
842
-
843
- comment = RDoc::Comment.new "##\n# my module\n", @top_level
844
-
845
- util_parser "module Foo # :nodoc:\nend"
846
-
847
- tk = @parser.get_tk
848
-
849
- @parser.parse_module @top_level, RDoc::Parser::Ruby::NORMAL, tk, comment
850
-
851
- foo = @top_level.modules.first
852
- assert_equal 'Foo', foo.full_name
853
- assert_empty foo.comment
854
- end
855
-
856
- def test_parse_module_stopdoc
857
- @top_level.stop_doc
858
-
859
- comment = RDoc::Comment.new "##\n# my module\n", @top_level
860
-
861
- util_parser "module Foo\nend"
862
-
863
- tk = @parser.get_tk
864
-
865
- @parser.parse_module @top_level, RDoc::Parser::Ruby::NORMAL, tk, comment
866
-
867
- foo = @top_level.modules.first
868
- assert_equal 'Foo', foo.full_name
869
- assert_empty foo.comment
870
- end
871
-
872
- def test_parse_class_colon3
873
- code = <<-CODE
874
- class A
875
- class ::B
876
- end
877
- end
878
- CODE
879
-
880
- util_parser code
881
-
882
- @parser.parse_class @top_level, false, @parser.get_tk, @comment
883
-
884
- assert_equal %w[A B], @store.all_classes.map { |c| c.full_name }.sort
885
- end
886
-
887
- def test_parse_class_colon3_self_reference
888
- code = <<-CODE
889
- class A::B
890
- class ::A
891
- end
892
- end
893
- CODE
894
-
895
- util_parser code
896
-
897
- @parser.parse_class @top_level, false, @parser.get_tk, @comment
898
-
899
- assert_equal %w[A A::B], @store.all_classes.map { |c| c.full_name }.sort
900
- end
901
-
902
- def test_parse_class_single
903
- code = <<-CODE
904
- class A
905
- class << B
906
- end
907
- class << d = Object.new
908
- def foo; end
909
- alias bar foo
910
- end
911
- end
912
- CODE
913
-
914
- util_parser code
915
-
916
- @parser.parse_class @top_level, false, @parser.get_tk, @comment
917
-
918
- assert_equal %w[A], @store.all_classes.map { |c| c.full_name }
919
-
920
- modules = @store.all_modules.sort_by { |c| c.full_name }
921
- assert_equal %w[A::B A::d], modules.map { |c| c.full_name }
922
-
923
- b = modules.first
924
- assert_equal 10, b.offset
925
- assert_equal 2, b.line
926
-
927
- # make sure method/alias was not added to enclosing class/module
928
- a = @store.classes_hash['A']
929
- assert_empty a.method_list
930
-
931
- # make sure non-constant-named module will be removed from documentation
932
- d = @store.modules_hash['A::d']
933
- assert d.remove_from_documentation?
934
- end
935
-
936
- def test_parse_class_single_gvar
937
- code = <<-CODE
938
- class << $g
939
- def m
940
- end
941
- end
942
- CODE
943
-
944
- util_parser code
945
-
946
- @parser.parse_class @top_level, false, @parser.get_tk, ''
947
-
948
- assert_empty @store.all_classes
949
- mod = @store.all_modules.first
950
-
951
- refute mod.document_self
952
-
953
- assert_empty mod.method_list
954
- end
955
-
956
- # TODO this is really a Context#add_class test
957
- def test_parse_class_object
958
- code = <<-CODE
959
- module A
960
- class B
961
- end
962
- class Object
963
- end
964
- class C < Object
965
- end
966
- end
967
- CODE
968
-
969
- util_parser code
970
-
971
- @parser.parse_module @top_level, false, @parser.get_tk, @comment
972
-
973
- assert_equal %w[A],
974
- @store.all_modules.map { |c| c.full_name }
975
- assert_equal %w[A::B A::C A::Object],
976
- @store.all_classes.map { |c| c.full_name }.sort
977
-
978
- assert_equal 'Object', @store.classes_hash['A::B'].superclass
979
- assert_equal 'Object', @store.classes_hash['A::Object'].superclass
980
- assert_equal 'A::Object', @store.classes_hash['A::C'].superclass.full_name
981
- end
982
-
983
- def test_parse_class_mistaken_for_module
984
- # The code below is not strictly legal Ruby (Foo must have been defined
985
- # before Foo::Bar is encountered), but RDoc might encounter Foo::Bar
986
- # before Foo if they live in different files.
987
-
988
- code = <<-RUBY
989
- class Foo::Bar
990
- end
991
-
992
- module Foo::Baz
993
- end
994
-
995
- class Foo
996
- end
997
- RUBY
998
-
999
- util_parser code
1000
-
1001
- @parser.scan
1002
-
1003
- assert_equal %w[Foo::Baz], @store.modules_hash.keys
1004
- assert_empty @top_level.modules
1005
-
1006
- foo = @top_level.classes.first
1007
- assert_equal 'Foo', foo.full_name
1008
-
1009
- bar = foo.classes.first
1010
- assert_equal 'Foo::Bar', bar.full_name
1011
-
1012
- baz = foo.modules.first
1013
- assert_equal 'Foo::Baz', baz.full_name
1014
- end
1015
-
1016
- def test_parse_class_definition_encountered_after_class_reference
1017
- # The code below is not legal Ruby (Foo must have been defined before
1018
- # Foo.bar is encountered), but RDoc might encounter Foo.bar before Foo if
1019
- # they live in different files.
1020
-
1021
- code = <<-EOF
1022
- def Foo.bar
1023
- end
1024
-
1025
- class Foo < IO
1026
- end
1027
- EOF
1028
-
1029
- util_parser code
1030
-
1031
- @parser.scan
1032
-
1033
- assert_empty @store.modules_hash
1034
- assert_empty @store.all_modules
1035
-
1036
- foo = @top_level.classes.first
1037
- assert_equal 'Foo', foo.full_name
1038
- assert_equal 'IO', foo.superclass
1039
-
1040
- bar = foo.method_list.first
1041
- assert_equal 'bar', bar.name
1042
- end
1043
-
1044
- def test_parse_module_relative_to_top_level_namespace
1045
- comment = RDoc::Comment.new <<-EOF, @top_level
1046
- #
1047
- # Weirdly named module
1048
- #
1049
- EOF
1050
-
1051
- code = <<-EOF
1052
- #{comment.text}
1053
- module ::Foo
1054
- class Helper
1055
- end
1056
- end
1057
- EOF
1058
-
1059
- util_parser code
1060
- @parser.scan()
1061
-
1062
- foo = @top_level.modules.first
1063
- assert_equal 'Foo', foo.full_name
1064
- assert_equal 'Weirdly named module', foo.comment.text
1065
-
1066
- helper = foo.classes.first
1067
- assert_equal 'Foo::Helper', helper.full_name
1068
- end
1069
-
1070
- def test_parse_comment_attr
1071
- klass = RDoc::NormalClass.new 'Foo'
1072
- klass.parent = @top_level
1073
-
1074
- comment = RDoc::Comment.new "##\n# :attr: foo\n# my attr\n", @top_level
1075
-
1076
- util_parser "\n"
1077
-
1078
- tk = @parser.get_tk
1079
-
1080
- @parser.parse_comment klass, tk, comment
1081
-
1082
- foo = klass.attributes.first
1083
- assert_equal 'foo', foo.name
1084
- assert_equal 'RW', foo.rw
1085
- assert_equal 'my attr', foo.comment.text
1086
- assert_equal @top_level, foo.file
1087
- assert_equal 0, foo.offset
1088
- assert_equal 1, foo.line
1089
-
1090
- assert_equal nil, foo.viewer
1091
- assert_equal true, foo.document_children
1092
- assert_equal true, foo.document_self
1093
- assert_equal false, foo.done_documenting
1094
- assert_equal false, foo.force_documentation
1095
- assert_equal klass, foo.parent
1096
- assert_equal :public, foo.visibility
1097
- assert_equal "\n", foo.text
1098
-
1099
- assert_equal klass.current_section, foo.section
1100
- end
1101
-
1102
- def test_parse_comment_attr_attr_reader
1103
- klass = RDoc::NormalClass.new 'Foo'
1104
- klass.parent = @top_level
1105
-
1106
- comment = RDoc::Comment.new "##\n# :attr_reader: foo\n", @top_level
1107
-
1108
- util_parser "\n"
1109
-
1110
- tk = @parser.get_tk
1111
-
1112
- @parser.parse_comment klass, tk, comment
1113
-
1114
- foo = klass.attributes.first
1115
- assert_equal 'foo', foo.name
1116
- assert_equal 'R', foo.rw
1117
- end
1118
-
1119
- def test_parse_comment_attr_stopdoc
1120
- klass = RDoc::NormalClass.new 'Foo'
1121
- klass.parent = @top_level
1122
- klass.stop_doc
1123
-
1124
- comment = RDoc::Comment.new "##\n# :attr: foo\n# my attr\n", @top_level
1125
-
1126
- util_parser "\n"
1127
-
1128
- tk = @parser.get_tk
1129
-
1130
- @parser.parse_comment klass, tk, comment
1131
-
1132
- assert_empty klass.attributes
1133
- end
1134
-
1135
- def test_parse_comment_method
1136
- klass = RDoc::NormalClass.new 'Foo'
1137
- klass.parent = @top_level
1138
-
1139
- comment = RDoc::Comment.new "##\n# :method: foo\n# my method\n", @top_level
1140
-
1141
- util_parser "\n"
1142
-
1143
- tk = @parser.get_tk
1144
-
1145
- @parser.parse_comment klass, tk, comment
1146
-
1147
- foo = klass.method_list.first
1148
- assert_equal 'foo', foo.name
1149
- assert_equal 'my method', foo.comment.text
1150
- assert_equal @top_level, foo.file
1151
- assert_equal 0, foo.offset
1152
- assert_equal 1, foo.line
1153
-
1154
- assert_equal [], foo.aliases
1155
- assert_equal nil, foo.block_params
1156
- assert_equal nil, foo.call_seq
1157
- assert_equal nil, foo.is_alias_for
1158
- assert_equal nil, foo.viewer
1159
- assert_equal true, foo.document_children
1160
- assert_equal true, foo.document_self
1161
- assert_equal '', foo.params
1162
- assert_equal false, foo.done_documenting
1163
- assert_equal false, foo.dont_rename_initialize
1164
- assert_equal false, foo.force_documentation
1165
- assert_equal klass, foo.parent
1166
- assert_equal false, foo.singleton
1167
- assert_equal :public, foo.visibility
1168
- assert_equal "\n", foo.text
1169
- assert_equal klass.current_section, foo.section
1170
-
1171
- stream = [
1172
- tk(:COMMENT, 0, 1, 1, nil,
1173
- "# File #{@top_level.relative_name}, line 1"),
1174
- RDoc::Parser::Ruby::NEWLINE_TOKEN,
1175
- tk(:SPACE, 0, 1, 1, nil, ''),
1176
- ]
1177
-
1178
- assert_equal stream, foo.token_stream
1179
- end
1180
-
1181
- def test_parse_comment_method_args
1182
- klass = RDoc::NormalClass.new 'Foo'
1183
- klass.parent = @top_level
1184
-
1185
-
1186
- util_parser "\n"
1187
-
1188
- tk = @parser.get_tk
1189
-
1190
- @parser.parse_comment klass, tk,
1191
- comment("##\n# :method: foo\n# :args: a, b\n")
1192
-
1193
- foo = klass.method_list.first
1194
- assert_equal 'foo', foo.name
1195
- assert_equal 'a, b', foo.params
1196
- end
1197
-
1198
- def test_parse_comment_method_stopdoc
1199
- klass = RDoc::NormalClass.new 'Foo'
1200
- klass.parent = @top_level
1201
- klass.stop_doc
1202
-
1203
- comment = RDoc::Comment.new "##\n# :method: foo\n# my method\n", @top_level
1204
-
1205
- util_parser "\n"
1206
-
1207
- tk = @parser.get_tk
1208
-
1209
- @parser.parse_comment klass, tk, comment
1210
-
1211
- assert_empty klass.method_list
1212
- end
1213
-
1214
- def test_parse_constant
1215
- klass = @top_level.add_class RDoc::NormalClass, 'Foo'
1216
-
1217
- util_parser "A = v"
1218
-
1219
- tk = @parser.get_tk
1220
-
1221
- @parser.parse_constant klass, tk, @comment
1222
-
1223
- foo = klass.constants.first
1224
-
1225
- assert_equal 'A', foo.name
1226
- assert_equal @top_level, foo.file
1227
- assert_equal 0, foo.offset
1228
- assert_equal 1, foo.line
1229
- end
1230
-
1231
- def test_parse_constant_attrasgn
1232
- klass = @top_level.add_class RDoc::NormalClass, 'Foo'
1233
-
1234
- util_parser "A[k] = v"
1235
-
1236
- tk = @parser.get_tk
1237
-
1238
- @parser.parse_constant klass, tk, @comment
1239
-
1240
- assert klass.constants.empty?
1241
- end
1242
-
1243
- def test_parse_constant_alias
1244
- klass = @top_level.add_class RDoc::NormalClass, 'Foo'
1245
- klass.add_class RDoc::NormalClass, 'B'
1246
-
1247
- util_parser "A = B"
1248
-
1249
- tk = @parser.get_tk
1250
-
1251
- @parser.parse_constant klass, tk, @comment
1252
-
1253
- assert_equal 'Foo::A', klass.find_module_named('A').full_name
1254
- end
1255
-
1256
- def test_parse_constant_alias_same_name
1257
- foo = @top_level.add_class RDoc::NormalClass, 'Foo'
1258
- @top_level.add_class RDoc::NormalClass, 'Bar'
1259
- bar = foo.add_class RDoc::NormalClass, 'Bar'
1260
-
1261
- assert @store.find_class_or_module('::Bar')
1262
-
1263
- util_parser "A = ::Bar"
1264
-
1265
- tk = @parser.get_tk
1266
-
1267
- @parser.parse_constant foo, tk, @comment
1268
-
1269
- assert_equal 'A', bar.find_module_named('A').full_name
1270
- end
1271
-
1272
- def test_parse_constant_in_method
1273
- klass = @top_level.add_class RDoc::NormalClass, 'Foo'
1274
-
1275
- util_parser 'A::B = v'
1276
-
1277
- tk = @parser.get_tk
1278
-
1279
- @parser.parse_constant klass, tk, @comment, true
1280
-
1281
- assert_empty klass.constants
1282
-
1283
- assert_empty @store.modules_hash.keys
1284
- assert_equal %w[Foo], @store.classes_hash.keys
1285
- end
1286
-
1287
- def test_parse_constant_rescue
1288
- klass = @top_level.add_class RDoc::NormalClass, 'Foo'
1289
-
1290
- util_parser "A => e"
1291
-
1292
- tk = @parser.get_tk
1293
-
1294
- @parser.parse_constant klass, tk, @comment
1295
-
1296
- assert_empty klass.constants
1297
- assert_empty klass.modules
1298
-
1299
- assert_empty @store.modules_hash.keys
1300
- assert_equal %w[Foo], @store.classes_hash.keys
1301
- end
1302
-
1303
- def test_parse_constant_stopdoc
1304
- klass = @top_level.add_class RDoc::NormalClass, 'Foo'
1305
- klass.stop_doc
1306
-
1307
- util_parser "A = v"
1308
-
1309
- tk = @parser.get_tk
1310
-
1311
- @parser.parse_constant klass, tk, @comment
1312
-
1313
- assert_empty klass.constants
1314
- end
1315
-
1316
- def test_parse_comment_nested
1317
- content = <<-CONTENT
1318
- A::B::C = 1
1319
- CONTENT
1320
-
1321
- util_parser content
1322
-
1323
- tk = @parser.get_tk
1324
-
1325
- parsed = @parser.parse_constant @top_level, tk, 'comment'
1326
-
1327
- assert parsed
1328
-
1329
- a = @top_level.find_module_named 'A'
1330
- b = a.find_module_named 'B'
1331
- c = b.constants.first
1332
-
1333
- assert_equal 'A::B::C', c.full_name
1334
- assert_equal 'comment', c.comment
1335
- end
1336
-
1337
- def test_parse_extend_or_include_extend
1338
- klass = RDoc::NormalClass.new 'C'
1339
- klass.parent = @top_level
1340
-
1341
- comment = RDoc::Comment.new "# my extend\n", @top_level
1342
-
1343
- util_parser "extend I"
1344
-
1345
- @parser.get_tk # extend
1346
-
1347
- @parser.parse_extend_or_include RDoc::Extend, klass, comment
1348
-
1349
- assert_equal 1, klass.extends.length
1350
-
1351
- ext = klass.extends.first
1352
- assert_equal 'I', ext.name
1353
- assert_equal 'my extend', ext.comment.text
1354
- assert_equal @top_level, ext.file
1355
- end
1356
-
1357
- def test_parse_extend_or_include_include
1358
- klass = RDoc::NormalClass.new 'C'
1359
- klass.parent = @top_level
1360
-
1361
- comment = RDoc::Comment.new "# my include\n", @top_level
1362
-
1363
- util_parser "include I"
1364
-
1365
- @parser.get_tk # include
1366
-
1367
- @parser.parse_extend_or_include RDoc::Include, klass, comment
1368
-
1369
- assert_equal 1, klass.includes.length
1370
-
1371
- incl = klass.includes.first
1372
- assert_equal 'I', incl.name
1373
- assert_equal 'my include', incl.comment.text
1374
- assert_equal @top_level, incl.file
1375
- end
1376
-
1377
- def test_parse_meta_method
1378
- klass = RDoc::NormalClass.new 'Foo'
1379
- klass.parent = @top_level
1380
-
1381
- comment = RDoc::Comment.new "##\n# my method\n", @top_level
1382
-
1383
- util_parser "add_my_method :foo, :bar\nadd_my_method :baz"
1384
-
1385
- tk = @parser.get_tk
1386
-
1387
- @parser.parse_meta_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment
1388
-
1389
- foo = klass.method_list.first
1390
- assert_equal 'foo', foo.name
1391
- assert_equal 'my method', foo.comment.text
1392
- assert_equal @top_level, foo.file
1393
- assert_equal 0, foo.offset
1394
- assert_equal 1, foo.line
1395
-
1396
- assert_equal [], foo.aliases
1397
- assert_equal nil, foo.block_params
1398
- assert_equal nil, foo.call_seq
1399
- assert_equal true, foo.document_children
1400
- assert_equal true, foo.document_self
1401
- assert_equal false, foo.done_documenting
1402
- assert_equal false, foo.dont_rename_initialize
1403
- assert_equal false, foo.force_documentation
1404
- assert_equal nil, foo.is_alias_for
1405
- assert_equal '', foo.params
1406
- assert_equal klass, foo.parent
1407
- assert_equal false, foo.singleton
1408
- assert_equal 'add_my_method :foo', foo.text
1409
- assert_equal nil, foo.viewer
1410
- assert_equal :public, foo.visibility
1411
- assert_equal klass.current_section, foo.section
1412
-
1413
- stream = [
1414
- tk(:COMMENT, 0, 1, 1, nil,
1415
- "# File #{@top_level.relative_name}, line 1"),
1416
- RDoc::Parser::Ruby::NEWLINE_TOKEN,
1417
- tk(:SPACE, 0, 1, 1, nil, ''),
1418
- tk(:IDENTIFIER, 0, 1, 0, 'add_my_method', 'add_my_method'),
1419
- tk(:SPACE, 0, 1, 13, nil, ' '),
1420
- tk(:SYMBOL, 0, 1, 14, nil, ':foo'),
1421
- tk(:COMMA, 0, 1, 18, nil, ','),
1422
- tk(:SPACE, 0, 1, 19, nil, ' '),
1423
- tk(:SYMBOL, 0, 1, 20, nil, ':bar'),
1424
- tk(:NL, 0, 1, 24, nil, "\n"),
1425
- ]
1426
-
1427
- assert_equal stream, foo.token_stream
1428
- end
1429
-
1430
- def test_parse_meta_method_block
1431
- klass = RDoc::NormalClass.new 'Foo'
1432
- klass.parent = @top_level
1433
-
1434
- comment = RDoc::Comment.new "##\n# my method\n", @top_level
1435
-
1436
- content = <<-CONTENT
1437
- inline(:my_method) do |*args|
1438
- "this method causes z to disappear"
1439
- end
1440
- CONTENT
1441
-
1442
- util_parser content
1443
-
1444
- tk = @parser.get_tk
1445
-
1446
- @parser.parse_meta_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment
1447
-
1448
- assert_equal tk(:NL, 0, 3, 3, 3, "\n"), @parser.get_tk
1449
- end
1450
-
1451
- def test_parse_meta_method_define_method
1452
- klass = RDoc::NormalClass.new 'Foo'
1453
- comment = RDoc::Comment.new "##\n# my method\n", @top_level
1454
-
1455
- util_parser "define_method :foo do end"
1456
-
1457
- tk = @parser.get_tk
1458
-
1459
- @parser.parse_meta_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment
1460
-
1461
- foo = klass.method_list.first
1462
- assert_equal 'foo', foo.name
1463
- assert_equal 'my method', foo.comment.text
1464
- assert_equal @top_level, foo.file
1465
- end
1466
-
1467
- def test_parse_meta_method_name
1468
- klass = RDoc::NormalClass.new 'Foo'
1469
- klass.parent = @top_level
1470
-
1471
- comment =
1472
- RDoc::Comment.new "##\n# :method: woo_hoo!\n# my method\n", @top_level
1473
-
1474
- util_parser "add_my_method :foo, :bar\nadd_my_method :baz"
1475
-
1476
- tk = @parser.get_tk
1477
-
1478
- @parser.parse_meta_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment
1479
-
1480
- foo = klass.method_list.first
1481
- assert_equal 'woo_hoo!', foo.name
1482
- assert_equal 'my method', foo.comment.text
1483
- assert_equal @top_level, foo.file
1484
- end
1485
-
1486
- def test_parse_meta_method_singleton
1487
- klass = RDoc::NormalClass.new 'Foo'
1488
- klass.parent = @top_level
1489
-
1490
- comment =
1491
- RDoc::Comment.new "##\n# :singleton-method:\n# my method\n", @top_level
1492
-
1493
- util_parser "add_my_method :foo, :bar\nadd_my_method :baz"
1494
-
1495
- tk = @parser.get_tk
1496
-
1497
- @parser.parse_meta_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment
1498
-
1499
- foo = klass.method_list.first
1500
- assert_equal 'foo', foo.name
1501
- assert_equal true, foo.singleton, 'singleton method'
1502
- assert_equal 'my method', foo.comment.text
1503
- assert_equal @top_level, foo.file
1504
- end
1505
-
1506
- def test_parse_meta_method_singleton_name
1507
- klass = RDoc::NormalClass.new 'Foo'
1508
- klass.parent = @top_level
1509
-
1510
- comment =
1511
- RDoc::Comment.new "##\n# :singleton-method: woo_hoo!\n# my method\n",
1512
- @top_level
1513
-
1514
- util_parser "add_my_method :foo, :bar\nadd_my_method :baz"
1515
-
1516
- tk = @parser.get_tk
1517
-
1518
- @parser.parse_meta_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment
1519
-
1520
- foo = klass.method_list.first
1521
- assert_equal 'woo_hoo!', foo.name
1522
- assert_equal true, foo.singleton, 'singleton method'
1523
- assert_equal 'my method', foo.comment.text
1524
- assert_equal @top_level, foo.file
1525
- end
1526
-
1527
- def test_parse_meta_method_string_name
1528
- klass = RDoc::NormalClass.new 'Foo'
1529
- comment = RDoc::Comment.new "##\n# my method\n", @top_level
1530
-
1531
- util_parser "add_my_method 'foo'"
1532
-
1533
- tk = @parser.get_tk
1534
-
1535
- @parser.parse_meta_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment
1536
-
1537
- foo = klass.method_list.first
1538
- assert_equal 'foo', foo.name
1539
- assert_equal 'my method', foo.comment.text
1540
- assert_equal @top_level, foo.file
1541
- end
1542
-
1543
- def test_parse_meta_method_stopdoc
1544
- klass = RDoc::NormalClass.new 'Foo'
1545
- klass.parent = @top_level
1546
- klass.stop_doc
1547
-
1548
- comment = RDoc::Comment.new "##\n# my method\n", @top_level
1549
-
1550
- util_parser "add_my_method :foo, :bar\nadd_my_method :baz"
1551
-
1552
- tk = @parser.get_tk
1553
-
1554
- @parser.parse_meta_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment
1555
-
1556
- assert_empty klass.method_list
1557
- end
1558
-
1559
- def test_parse_meta_method_unknown
1560
- klass = RDoc::NormalClass.new 'Foo'
1561
- comment = RDoc::Comment.new "##\n# my method\n", @top_level
1562
-
1563
- util_parser "add_my_method ('foo')"
1564
-
1565
- tk = @parser.get_tk
1566
-
1567
- @parser.parse_meta_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment
1568
-
1569
- foo = klass.method_list.first
1570
- assert_equal 'unknown', foo.name
1571
- assert_equal 'my method', foo.comment.text
1572
- assert_equal @top_level, foo.file
1573
- end
1574
-
1575
- def test_parse_method
1576
- klass = RDoc::NormalClass.new 'Foo'
1577
- klass.parent = @top_level
1578
-
1579
- comment = RDoc::Comment.new "##\n# my method\n", @top_level
1580
-
1581
- util_parser "def foo() :bar end"
1582
-
1583
- tk = @parser.get_tk
1584
-
1585
- @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment
1586
-
1587
- foo = klass.method_list.first
1588
- assert_equal 'foo', foo.name
1589
- assert_equal 'my method', foo.comment.text
1590
- assert_equal @top_level, foo.file
1591
- assert_equal 0, foo.offset
1592
- assert_equal 1, foo.line
1593
-
1594
- assert_equal [], foo.aliases
1595
- assert_equal nil, foo.block_params
1596
- assert_equal nil, foo.call_seq
1597
- assert_equal nil, foo.is_alias_for
1598
- assert_equal nil, foo.viewer
1599
- assert_equal true, foo.document_children
1600
- assert_equal true, foo.document_self
1601
- assert_equal '()', foo.params
1602
- assert_equal false, foo.done_documenting
1603
- assert_equal false, foo.dont_rename_initialize
1604
- assert_equal false, foo.force_documentation
1605
- assert_equal klass, foo.parent
1606
- assert_equal false, foo.singleton
1607
- assert_equal :public, foo.visibility
1608
- assert_equal 'def foo', foo.text
1609
- assert_equal klass.current_section, foo.section
1610
-
1611
- stream = [
1612
- tk(:COMMENT, 0, 1, 1, nil,
1613
- "# File #{@top_level.relative_name}, line 1"),
1614
- RDoc::Parser::Ruby::NEWLINE_TOKEN,
1615
- tk(:SPACE, 0, 1, 1, nil, ''),
1616
- tk(:DEF, 0, 1, 0, 'def', 'def'),
1617
- tk(:SPACE, 3, 1, 3, nil, ' '),
1618
- tk(:IDENTIFIER, 4, 1, 4, 'foo', 'foo'),
1619
- tk(:LPAREN, 7, 1, 7, nil, '('),
1620
- tk(:RPAREN, 8, 1, 8, nil, ')'),
1621
- tk(:SPACE, 9, 1, 9, nil, ' '),
1622
- tk(:COLON, 10, 1, 10, nil, ':'),
1623
- tk(:IDENTIFIER, 11, 1, 11, 'bar', 'bar'),
1624
- tk(:SPACE, 14, 1, 14, nil, ' '),
1625
- tk(:END, 15, 1, 15, 'end', 'end'),
1626
- ]
1627
-
1628
- assert_equal stream, foo.token_stream
1629
- end
1630
-
1631
- def test_parse_method_alias
1632
- klass = RDoc::NormalClass.new 'Foo'
1633
- klass.parent = @top_level
1634
-
1635
- util_parser "def m() alias a b; end"
1636
-
1637
- tk = @parser.get_tk
1638
-
1639
- @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, @comment
1640
-
1641
- assert klass.aliases.empty?
1642
- end
1643
-
1644
- def test_parse_method_ampersand
1645
- klass = RDoc::NormalClass.new 'Foo'
1646
- klass.parent = @top_level
1647
-
1648
- util_parser "def self.&\nend"
1649
-
1650
- tk = @parser.get_tk
1651
-
1652
- @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, @comment
1653
-
1654
- ampersand = klass.method_list.first
1655
- assert_equal '&', ampersand.name
1656
- assert ampersand.singleton
1657
- end
1658
-
1659
- def test_parse_method_constant
1660
- c = RDoc::Constant.new 'CONST', nil, ''
1661
- m = @top_level.add_class RDoc::NormalModule, 'M'
1662
- m.add_constant c
1663
-
1664
- util_parser "def CONST.m() end"
1665
-
1666
- tk = @parser.get_tk
1667
-
1668
- @parser.parse_method m, RDoc::Parser::Ruby::NORMAL, tk, @comment
1669
-
1670
- assert_empty @store.modules_hash.keys
1671
- assert_equal %w[M], @store.classes_hash.keys
1672
- end
1673
-
1674
- def test_parse_method_false
1675
- util_parser "def false.foo() :bar end"
1676
-
1677
- tk = @parser.get_tk
1678
-
1679
- @parser.parse_method @top_level, RDoc::Parser::Ruby::NORMAL, tk, @comment
1680
-
1681
- klass = @store.find_class_named 'FalseClass'
1682
-
1683
- foo = klass.method_list.first
1684
- assert_equal 'foo', foo.name
1685
- end
1686
-
1687
- def test_parse_method_funky
1688
- klass = RDoc::NormalClass.new 'Foo'
1689
- klass.parent = @top_level
1690
-
1691
- util_parser "def (blah).foo() :bar end"
1692
-
1693
- tk = @parser.get_tk
1694
-
1695
- @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, @comment
1696
-
1697
- assert_empty klass.method_list
1698
- end
1699
-
1700
- def test_parse_method_gvar
1701
- util_parser "def $stdout.foo() :bar end"
1702
-
1703
- tk = @parser.get_tk
1704
-
1705
- @parser.parse_method @top_level, RDoc::Parser::Ruby::NORMAL, tk, @comment
1706
-
1707
- assert @top_level.method_list.empty?
1708
- end
1709
-
1710
- def test_parse_method_gvar_insane
1711
- util_parser "def $stdout.foo() class << $other; end; end"
1712
-
1713
- tk = @parser.get_tk
1714
-
1715
- @parser.parse_method @top_level, RDoc::Parser::Ruby::NORMAL, tk, @comment
1716
-
1717
- assert @top_level.method_list.empty?
1718
-
1719
- assert_empty @store.all_classes
1720
-
1721
- assert_equal 1, @store.all_modules.length
1722
-
1723
- refute @store.all_modules.first.document_self
1724
- end
1725
-
1726
- def test_parse_method_internal_gvar
1727
- klass = RDoc::NormalClass.new 'Foo'
1728
- klass.parent = @top_level
1729
-
1730
- util_parser "def foo() def $blah.bar() end end"
1731
-
1732
- tk = @parser.get_tk
1733
-
1734
- @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, @comment
1735
-
1736
- assert_equal 1, klass.method_list.length
1737
- end
1738
-
1739
- def test_parse_method_internal_ivar
1740
- klass = RDoc::NormalClass.new 'Foo'
1741
- klass.parent = @top_level
1742
-
1743
- util_parser "def foo() def @blah.bar() end end"
1744
-
1745
- tk = @parser.get_tk
1746
-
1747
- @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, @comment
1748
-
1749
- assert_equal 1, klass.method_list.length
1750
- end
1751
-
1752
- def test_parse_method_internal_lvar
1753
- klass = RDoc::NormalClass.new 'Foo'
1754
- klass.parent = @top_level
1755
-
1756
- util_parser "def foo() def blah.bar() end end"
1757
-
1758
- tk = @parser.get_tk
1759
-
1760
- @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, @comment
1761
-
1762
- assert_equal 1, klass.method_list.length
1763
- end
1764
-
1765
- def test_parse_method_nil
1766
- util_parser "def nil.foo() :bar end"
1767
-
1768
- tk = @parser.get_tk
1769
-
1770
- @parser.parse_method @top_level, RDoc::Parser::Ruby::NORMAL, tk, @comment
1771
-
1772
- klass = @store.find_class_named 'NilClass'
1773
-
1774
- foo = klass.method_list.first
1775
- assert_equal 'foo', foo.name
1776
- end
1777
-
1778
- def test_parse_method_nodoc
1779
- klass = RDoc::NormalClass.new 'Foo'
1780
- klass.parent = @top_level
1781
-
1782
- util_parser "def foo # :nodoc:\nend"
1783
-
1784
- tk = @parser.get_tk
1785
-
1786
- @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment('')
1787
-
1788
- assert_empty klass.method_list
1789
- end
1790
-
1791
- def test_parse_method_nodoc_track
1792
- klass = RDoc::NormalClass.new 'Foo'
1793
- klass.parent = @top_level
1794
-
1795
- @options.visibility = :nodoc
1796
-
1797
- util_parser "def foo # :nodoc:\nend"
1798
-
1799
- tk = @parser.get_tk
1800
-
1801
- @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment('')
1802
-
1803
- refute_empty klass.method_list
1804
- end
1805
-
1806
- def test_parse_method_no_parens
1807
- klass = RDoc::NormalClass.new 'Foo'
1808
- klass.parent = @top_level
1809
-
1810
- util_parser "def foo arg1, arg2 = {}\nend"
1811
-
1812
- tk = @parser.get_tk
1813
-
1814
- @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, @comment
1815
-
1816
- foo = klass.method_list.first
1817
- assert_equal '(arg1, arg2 = {})', foo.params
1818
- assert_equal @top_level, foo.file
1819
- end
1820
-
1821
- def test_parse_method_parameters_comment
1822
- klass = RDoc::NormalClass.new 'Foo'
1823
- klass.parent = @top_level
1824
-
1825
- util_parser "def foo arg1, arg2 # some useful comment\nend"
1826
-
1827
- tk = @parser.get_tk
1828
-
1829
- @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, @comment
1830
-
1831
- foo = klass.method_list.first
1832
- assert_equal '(arg1, arg2)', foo.params
1833
- end
1834
-
1835
- def test_parse_method_parameters_comment_continue
1836
- klass = RDoc::NormalClass.new 'Foo'
1837
- klass.parent = @top_level
1838
-
1839
- util_parser "def foo arg1, arg2, # some useful comment\narg3\nend"
1840
-
1841
- tk = @parser.get_tk
1842
-
1843
- @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, @comment
1844
-
1845
- foo = klass.method_list.first
1846
- assert_equal '(arg1, arg2, arg3)', foo.params
1847
- end
1848
-
1849
- def test_parse_method_star
1850
- klass = RDoc::NormalClass.new 'Foo'
1851
- klass.parent = @top_level
1852
-
1853
- util_parser "def self.*\nend"
1854
-
1855
- tk = @parser.get_tk
1856
-
1857
- @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, @comment
1858
-
1859
- ampersand = klass.method_list.first
1860
- assert_equal '*', ampersand.name
1861
- assert ampersand.singleton
1862
- end
1863
-
1864
- def test_parse_method_stopdoc
1865
- klass = RDoc::NormalClass.new 'Foo'
1866
- klass.parent = @top_level
1867
- klass.stop_doc
1868
-
1869
- comment = RDoc::Comment.new "##\n# my method\n", @top_level
1870
-
1871
- util_parser "def foo() :bar end"
1872
-
1873
- tk = @parser.get_tk
1874
-
1875
- @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment
1876
-
1877
- assert_empty klass.method_list
1878
- end
1879
-
1880
- def test_parse_method_toplevel
1881
- klass = @top_level
1882
-
1883
- util_parser "def foo arg1, arg2\nend"
1884
-
1885
- tk = @parser.get_tk
1886
-
1887
- @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, @comment
1888
-
1889
- object = @store.find_class_named 'Object'
1890
-
1891
- foo = object.method_list.first
1892
- assert_equal 'Object#foo', foo.full_name
1893
- assert_equal @top_level, foo.file
1894
- end
1895
-
1896
- def test_parse_method_toplevel_class
1897
- klass = @top_level
1898
-
1899
- util_parser "def Object.foo arg1, arg2\nend"
1900
-
1901
- tk = @parser.get_tk
1902
-
1903
- @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, @comment
1904
-
1905
- object = @store.find_class_named 'Object'
1906
-
1907
- foo = object.method_list.first
1908
- assert_equal 'Object::foo', foo.full_name
1909
- end
1910
-
1911
- def test_parse_method_true
1912
- util_parser "def true.foo() :bar end"
1913
-
1914
- tk = @parser.get_tk
1915
-
1916
- @parser.parse_method @top_level, RDoc::Parser::Ruby::NORMAL, tk, @comment
1917
-
1918
- klass = @store.find_class_named 'TrueClass'
1919
-
1920
- foo = klass.method_list.first
1921
- assert_equal 'foo', foo.name
1922
- end
1923
-
1924
- def test_parse_method_utf8
1925
- klass = RDoc::NormalClass.new 'Foo'
1926
- klass.parent = @top_level
1927
-
1928
- method = "def ω() end"
1929
-
1930
- assert_equal Encoding::UTF_8, method.encoding if
1931
- Object.const_defined? :Encoding
1932
-
1933
- util_parser method
1934
-
1935
- tk = @parser.get_tk
1936
-
1937
- @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, @comment
1938
-
1939
- omega = klass.method_list.first
1940
- assert_equal "def \317\211", omega.text
1941
- end
1942
-
1943
- def test_parse_method_dummy
1944
- util_parser ".method() end"
1945
-
1946
- @parser.parse_method_dummy @top_level
1947
-
1948
- assert_nil @parser.get_tk
1949
- end
1950
-
1951
- def test_parse_method_or_yield_parameters_hash
1952
- util_parser "({})\n"
1953
-
1954
- m = RDoc::AnyMethod.new nil, 'm'
1955
-
1956
- result = @parser.parse_method_or_yield_parameters m
1957
-
1958
- assert_equal '({})', result
1959
- end
1960
-
1961
- def test_parse_statements_class_if
1962
- util_parser <<-CODE
1963
- module Foo
1964
- X = if TRUE then
1965
- ''
1966
- end
1967
-
1968
- def blah
1969
- end
1970
- end
1971
- CODE
1972
-
1973
- @parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil
1974
-
1975
- foo = @top_level.modules.first
1976
- assert_equal 'Foo', foo.full_name, 'module Foo'
1977
-
1978
- methods = foo.method_list
1979
- assert_equal 1, methods.length
1980
- assert_equal 'Foo#blah', methods.first.full_name
1981
- end
1982
-
1983
- def test_parse_statements_class_nested
1984
- comment = RDoc::Comment.new "##\n# my method\n", @top_level
1985
-
1986
- util_parser "module Foo\n#{comment.text}class Bar\nend\nend"
1987
-
1988
- @parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL
1989
-
1990
- foo = @top_level.modules.first
1991
- assert_equal 'Foo', foo.full_name, 'module Foo'
1992
-
1993
- bar = foo.classes.first
1994
- assert_equal 'Foo::Bar', bar.full_name, 'class Foo::Bar'
1995
- assert_equal 'my method', bar.comment.text
1996
- end
1997
-
1998
- def test_parse_statements_def_percent_string_pound
1999
- util_parser "class C\ndef a\n%r{#}\nend\ndef b() end\nend"
2000
-
2001
- @parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL
2002
-
2003
- x = @top_level.classes.first
2004
-
2005
- assert_equal 2, x.method_list.length
2006
- a = x.method_list.first
2007
-
2008
- expected = [
2009
- tk(:COMMENT, 0, 2, 1, nil, "# File #{@filename}, line 2"),
2010
- tk(:NL, 0, 0, 0, nil, "\n"),
2011
- tk(:SPACE, 0, 1, 1, nil, ''),
2012
- tk(:DEF, 8, 2, 0, 'def', 'def'),
2013
- tk(:SPACE, 11, 2, 3, nil, ' '),
2014
- tk(:IDENTIFIER, 12, 2, 4, 'a', 'a'),
2015
- tk(:NL, 13, 2, 5, nil, "\n"),
2016
- tk(:DREGEXP, 14, 3, 0, nil, '%r{#}'),
2017
- tk(:NL, 19, 3, 5, nil, "\n"),
2018
- tk(:END, 20, 4, 0, 'end', 'end'),
2019
- ]
2020
-
2021
- assert_equal expected, a.token_stream
2022
- end
2023
-
2024
- def test_parse_statements_encoding
2025
- skip "Encoding not implemented" unless Object.const_defined? :Encoding
2026
- @options.encoding = Encoding::CP852
2027
-
2028
- content = <<-EOF
2029
- class Foo
2030
- ##
2031
- # this is my method
2032
- add_my_method :foo
2033
- end
2034
- EOF
2035
-
2036
- util_parser content
2037
-
2038
- @parser.parse_statements @top_level
2039
-
2040
- foo = @top_level.classes.first.method_list.first
2041
- assert_equal 'foo', foo.name
2042
- assert_equal 'this is my method', foo.comment.text
2043
- assert_equal Encoding::CP852, foo.comment.text.encoding
2044
- end
2045
-
2046
- def test_parse_statements_enddoc
2047
- klass = @top_level.add_class RDoc::NormalClass, 'Foo'
2048
-
2049
- util_parser "\n# :enddoc:"
2050
-
2051
- @parser.parse_statements klass, RDoc::Parser::Ruby::NORMAL, nil
2052
-
2053
- assert klass.done_documenting
2054
- end
2055
-
2056
- def test_parse_statements_enddoc_top_level
2057
- util_parser "\n# :enddoc:"
2058
-
2059
- assert_throws :eof do
2060
- @parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil
2061
- end
2062
- end
2063
-
2064
- def test_parse_statements_identifier_meta_method
2065
- content = <<-EOF
2066
- class Foo
2067
- ##
2068
- # this is my method
2069
- add_my_method :foo
2070
- end
2071
- EOF
2072
-
2073
- util_parser content
2074
-
2075
- @parser.parse_statements @top_level
2076
-
2077
- foo = @top_level.classes.first.method_list.first
2078
- assert_equal 'foo', foo.name
2079
- end
2080
-
2081
- def test_parse_statements_identifier_alias_method
2082
- content = <<-RUBY
2083
- class Foo
2084
- def foo() end
2085
- alias_method :foo2, :foo
2086
- end
2087
- RUBY
2088
-
2089
- util_parser content
2090
-
2091
- @parser.parse_statements @top_level
2092
-
2093
- foo = @top_level.classes.first.method_list[0]
2094
- assert_equal 'foo', foo.name
2095
-
2096
- foo2 = @top_level.classes.first.method_list.last
2097
- assert_equal 'foo2', foo2.name
2098
- assert_equal 'foo', foo2.is_alias_for.name
2099
- assert @top_level.classes.first.aliases.empty?
2100
- end
2101
-
2102
- def test_parse_statements_identifier_alias_method_before_original_method
2103
- # This is not strictly legal Ruby code, but it simulates finding an alias
2104
- # for a method before finding the original method, which might happen
2105
- # to rdoc if the alias is in a different file than the original method
2106
- # and rdoc processes the alias' file first.
2107
- content = <<-EOF
2108
- class Foo
2109
- alias_method :foo2, :foo
2110
-
2111
- alias_method :foo3, :foo
2112
-
2113
- def foo()
2114
- end
2115
-
2116
- alias_method :foo4, :foo
2117
-
2118
- alias_method :foo5, :unknown
2119
- end
2120
- EOF
2121
-
2122
- util_parser content
2123
-
2124
- @parser.parse_statements @top_level
2125
-
2126
- foo = @top_level.classes.first.method_list[0]
2127
- assert_equal 'foo', foo.name
2128
-
2129
- foo2 = @top_level.classes.first.method_list[1]
2130
- assert_equal 'foo2', foo2.name
2131
- assert_equal 'foo', foo2.is_alias_for.name
2132
-
2133
- foo3 = @top_level.classes.first.method_list[2]
2134
- assert_equal 'foo3', foo3.name
2135
- assert_equal 'foo', foo3.is_alias_for.name
2136
-
2137
- foo4 = @top_level.classes.first.method_list.last
2138
- assert_equal 'foo4', foo4.name
2139
- assert_equal 'foo', foo4.is_alias_for.name
2140
-
2141
- assert_equal 'unknown', @top_level.classes.first.external_aliases[0].old_name
2142
- end
2143
-
2144
- def test_parse_statements_identifier_args
2145
- comment = "##\n# :args: x\n# :method: b\n# my method\n"
2146
-
2147
- util_parser "module M\n#{comment}def_delegator :a, :b, :b\nend"
2148
-
2149
- @parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL
2150
-
2151
- m = @top_level.modules.first
2152
- assert_equal 'M', m.full_name
2153
-
2154
- b = m.method_list.first
2155
- assert_equal 'M#b', b.full_name
2156
- assert_equal 'x', b.params
2157
- assert_equal 'my method', b.comment.text
2158
-
2159
- assert_nil m.params, 'Module parameter not removed'
2160
- end
2161
-
2162
- def test_parse_statements_identifier_constant
2163
- sixth_constant = <<-EOF
2164
- Class.new do
2165
- rule :file do
2166
- all(x, y, z) {
2167
- def value
2168
- find(:require).each {|r| require r.value }
2169
- find(:grammar).map {|g| g.value }
2170
- end
2171
- def min; end
2172
- }
2173
- end
2174
- end
2175
- EOF
2176
-
2177
- content = <<-EOF
2178
- class Foo
2179
- FIRST_CONSTANT = 5
2180
-
2181
- SECOND_CONSTANT = [
2182
- 1,
2183
- 2,
2184
- 3
2185
- ]
2186
-
2187
- THIRD_CONSTANT = {
2188
- :foo => 'bar',
2189
- :x => 'y'
2190
- }
2191
-
2192
- FOURTH_CONSTANT = SECOND_CONSTANT.map do |element|
2193
- element + 1
2194
- element + 2
2195
- end
2196
-
2197
- FIFTH_CONSTANT = SECOND_CONSTANT.map { |element| element + 1 }
2198
-
2199
- SIXTH_CONSTANT = #{sixth_constant}
2200
-
2201
- SEVENTH_CONSTANT = proc { |i| begin i end }
2202
- end
2203
- EOF
2204
-
2205
- util_parser content
2206
-
2207
- @parser.parse_statements @top_level
2208
-
2209
- constants = @top_level.classes.first.constants
2210
-
2211
- constant = constants[0]
2212
- assert_equal 'FIRST_CONSTANT', constant.name
2213
- assert_equal '5', constant.value
2214
- assert_equal @top_level, constant.file
2215
-
2216
- constant = constants[1]
2217
- assert_equal 'SECOND_CONSTANT', constant.name
2218
- assert_equal "[\n1,\n2,\n3\n]", constant.value
2219
- assert_equal @top_level, constant.file
2220
-
2221
- constant = constants[2]
2222
- assert_equal 'THIRD_CONSTANT', constant.name
2223
- assert_equal "{\n:foo => 'bar',\n:x => 'y'\n}", constant.value
2224
- assert_equal @top_level, constant.file
2225
-
2226
- constant = constants[3]
2227
- assert_equal 'FOURTH_CONSTANT', constant.name
2228
- assert_equal "SECOND_CONSTANT.map do |element|\nelement + 1\nelement + 2\nend", constant.value
2229
- assert_equal @top_level, constant.file
2230
-
2231
- constant = constants[4]
2232
- assert_equal 'FIFTH_CONSTANT', constant.name
2233
- assert_equal 'SECOND_CONSTANT.map { |element| element + 1 }', constant.value
2234
- assert_equal @top_level, constant.file
2235
-
2236
- # TODO: parse as class
2237
- constant = constants[5]
2238
- assert_equal 'SIXTH_CONSTANT', constant.name
2239
- assert_equal sixth_constant.lines.map(&:strip).join("\n"), constant.value
2240
- assert_equal @top_level, constant.file
2241
-
2242
- # TODO: parse as method
2243
- constant = constants[6]
2244
- assert_equal 'SEVENTH_CONSTANT', constant.name
2245
- assert_equal "proc { |i| begin i end }", constant.value
2246
- assert_equal @top_level, constant.file
2247
- end
2248
-
2249
- def test_parse_statements_identifier_attr
2250
- content = "class Foo\nattr :foo\nend"
2251
-
2252
- util_parser content
2253
-
2254
- @parser.parse_statements @top_level
2255
-
2256
- foo = @top_level.classes.first.attributes.first
2257
- assert_equal 'foo', foo.name
2258
- assert_equal 'R', foo.rw
2259
- end
2260
-
2261
- def test_parse_statements_identifier_attr_accessor
2262
- content = "class Foo\nattr_accessor :foo\nend"
2263
-
2264
- util_parser content
2265
-
2266
- @parser.parse_statements @top_level
2267
-
2268
- foo = @top_level.classes.first.attributes.first
2269
- assert_equal 'foo', foo.name
2270
- assert_equal 'RW', foo.rw
2271
- end
2272
-
2273
- def test_parse_statements_identifier_define_method
2274
- util_parser <<-RUBY
2275
- class C
2276
- ##
2277
- # :method: a
2278
- define_method :a do end
2279
- ##
2280
- # :method: b
2281
- define_method :b do end
2282
- end
2283
- RUBY
2284
-
2285
- @parser.parse_statements @top_level
2286
- c = @top_level.classes.first
2287
-
2288
- assert_equal %w[a b], c.method_list.map { |m| m.name }
2289
- end
2290
-
2291
- def test_parse_statements_identifier_include
2292
- content = "class Foo\ninclude Bar\nend"
2293
-
2294
- util_parser content
2295
-
2296
- @parser.parse_statements @top_level
2297
-
2298
- foo = @top_level.classes.first
2299
- assert_equal 'Foo', foo.name
2300
- assert_equal 1, foo.includes.length
2301
- end
2302
-
2303
- def test_parse_statements_identifier_module_function
2304
- content = "module Foo\ndef foo() end\nmodule_function :foo\nend"
2305
-
2306
- util_parser content
2307
-
2308
- @parser.parse_statements @top_level
2309
-
2310
- foo, s_foo = @top_level.modules.first.method_list
2311
- assert_equal 'foo', foo.name, 'instance method name'
2312
- assert_equal :private, foo.visibility, 'instance method visibility'
2313
- assert_equal false, foo.singleton, 'instance method singleton'
2314
-
2315
- assert_equal 'foo', s_foo.name, 'module function name'
2316
- assert_equal :public, s_foo.visibility, 'module function visibility'
2317
- assert_equal true, s_foo.singleton, 'module function singleton'
2318
- end
2319
-
2320
- def test_parse_statements_identifier_private
2321
- content = "class Foo\nprivate\ndef foo() end\nend"
2322
-
2323
- util_parser content
2324
-
2325
- @parser.parse_statements @top_level
2326
-
2327
- foo = @top_level.classes.first.method_list.first
2328
- assert_equal 'foo', foo.name
2329
- assert_equal :private, foo.visibility
2330
- end
2331
-
2332
- def test_parse_statements_identifier_public_class_method
2333
- content = <<-CONTENT
2334
- class Date
2335
- def self.now; end
2336
- private_class_method :now
2337
- end
2338
-
2339
- class DateTime < Date
2340
- public_class_method :now
2341
- end
2342
- CONTENT
2343
-
2344
- util_parser content
2345
-
2346
- @parser.parse_statements @top_level
2347
-
2348
- date, date_time = @top_level.classes.sort_by { |c| c.full_name }
2349
-
2350
- date_now = date.method_list.first
2351
- date_time_now = date_time.method_list.sort_by { |m| m.full_name }.first
2352
-
2353
- assert_equal :private, date_now.visibility
2354
- assert_equal :public, date_time_now.visibility
2355
- end
2356
-
2357
- def test_parse_statements_identifier_private_class_method
2358
- content = <<-CONTENT
2359
- class Date
2360
- def self.now; end
2361
- public_class_method :now
2362
- end
2363
-
2364
- class DateTime < Date
2365
- private_class_method :now
2366
- end
2367
- CONTENT
2368
-
2369
- util_parser content
2370
-
2371
- @parser.parse_statements @top_level
2372
-
2373
- # TODO sort classes by default
2374
- date, date_time = @top_level.classes.sort_by { |c| c.full_name }
2375
-
2376
- date_now = date.method_list.first
2377
- date_time_now = date_time.method_list.sort_by { |m| m.full_name }.first
2378
-
2379
- assert_equal :public, date_now.visibility, date_now.full_name
2380
- assert_equal :private, date_time_now.visibility, date_time_now.full_name
2381
- end
2382
-
2383
- def test_parse_statements_identifier_require
2384
- content = "require 'bar'"
2385
-
2386
- util_parser content
2387
-
2388
- @parser.parse_statements @top_level
2389
-
2390
- assert_equal 1, @top_level.requires.length
2391
- end
2392
-
2393
- def test_parse_statements_identifier_yields
2394
- comment = "##\n# :yields: x\n# :method: b\n# my method\n"
2395
-
2396
- util_parser "module M\n#{comment}def_delegator :a, :b, :b\nend"
2397
-
2398
- @parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL
2399
-
2400
- m = @top_level.modules.first
2401
- assert_equal 'M', m.full_name
2402
-
2403
- b = m.method_list.first
2404
- assert_equal 'M#b', b.full_name
2405
- assert_equal 'x', b.block_params
2406
- assert_equal 'my method', b.comment.text
2407
-
2408
- assert_nil m.params, 'Module parameter not removed'
2409
- end
2410
-
2411
- def test_parse_statements_stopdoc_TkALIAS
2412
- klass = @top_level.add_class RDoc::NormalClass, 'Foo'
2413
-
2414
- util_parser "\n# :stopdoc:\nalias old new"
2415
-
2416
- @parser.parse_statements klass, RDoc::Parser::Ruby::NORMAL, nil
2417
-
2418
- assert_empty klass.aliases
2419
- assert_empty klass.unmatched_alias_lists
2420
- end
2421
-
2422
- def test_parse_statements_stopdoc_TkIDENTIFIER_alias_method
2423
- klass = @top_level.add_class RDoc::NormalClass, 'Foo'
2424
-
2425
- util_parser "\n# :stopdoc:\nalias_method :old :new"
2426
-
2427
- @parser.parse_statements klass, RDoc::Parser::Ruby::NORMAL, nil
2428
-
2429
- assert_empty klass.aliases
2430
- assert_empty klass.unmatched_alias_lists
2431
- end
2432
-
2433
- def test_parse_statements_stopdoc_TkIDENTIFIER_metaprogrammed
2434
- klass = @top_level.add_class RDoc::NormalClass, 'Foo'
2435
-
2436
- util_parser "\n# :stopdoc:\n# attr :meta"
2437
-
2438
- @parser.parse_statements klass, RDoc::Parser::Ruby::NORMAL, nil
2439
-
2440
- assert_empty klass.method_list
2441
- assert_empty klass.attributes
2442
- end
2443
-
2444
- def test_parse_statements_stopdoc_TkCONSTANT
2445
- klass = @top_level.add_class RDoc::NormalClass, 'Foo'
2446
-
2447
- util_parser "\n# :stopdoc:\nA = v"
2448
-
2449
- @parser.parse_statements klass, RDoc::Parser::Ruby::NORMAL, nil
2450
-
2451
- assert_empty klass.constants
2452
- end
2453
-
2454
- def test_parse_statements_stopdoc_TkDEF
2455
- klass = @top_level.add_class RDoc::NormalClass, 'Foo'
2456
-
2457
- util_parser "\n# :stopdoc:\ndef m\n end"
2458
-
2459
- @parser.parse_statements klass, RDoc::Parser::Ruby::NORMAL, nil
2460
-
2461
- assert_empty klass.method_list
2462
- end
2463
-
2464
- def test_parse_statements_super
2465
- m = RDoc::AnyMethod.new '', 'm'
2466
- util_parser 'super'
2467
-
2468
- @parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, m
2469
-
2470
- assert m.calls_super
2471
- end
2472
-
2473
- def test_parse_statements_super_no_method
2474
- content = "super"
2475
-
2476
- util_parser content
2477
-
2478
- @parser.parse_statements @top_level
2479
-
2480
- assert_nil @parser.get_tk
2481
- end
2482
-
2483
- def test_parse_statements_while_begin
2484
- util_parser <<-RUBY
2485
- class A
2486
- def a
2487
- while begin a; b end
2488
- end
2489
- end
2490
-
2491
- def b
2492
- end
2493
- end
2494
- RUBY
2495
-
2496
- @parser.parse_statements @top_level
2497
-
2498
- c_a = @top_level.classes.first
2499
- assert_equal 'A', c_a.full_name
2500
-
2501
- assert_equal 1, @top_level.classes.length
2502
-
2503
- m_a = c_a.method_list.first
2504
- m_b = c_a.method_list.last
2505
-
2506
- assert_equal 'A#a', m_a.full_name
2507
- assert_equal 'A#b', m_b.full_name
2508
- end
2509
-
2510
- def test_parse_symbol_in_arg
2511
- util_parser ':blah "blah" "#{blah}" blah'
2512
-
2513
- assert_equal 'blah', @parser.parse_symbol_in_arg
2514
-
2515
- @parser.skip_tkspace
2516
-
2517
- assert_equal 'blah', @parser.parse_symbol_in_arg
2518
-
2519
- @parser.skip_tkspace
2520
-
2521
- assert_equal nil, @parser.parse_symbol_in_arg
2522
-
2523
- @parser.skip_tkspace
2524
-
2525
- assert_equal nil, @parser.parse_symbol_in_arg
2526
- end
2527
-
2528
- def test_parse_statements_alias_method
2529
- content = <<-CONTENT
2530
- class A
2531
- alias_method :a, :[] unless c
2532
- end
2533
-
2534
- B = A
2535
-
2536
- class C
2537
- end
2538
- CONTENT
2539
-
2540
- util_parser content
2541
-
2542
- @parser.parse_statements @top_level
2543
-
2544
- # HACK where are the assertions?
2545
- end
2546
-
2547
- def test_parse_top_level_statements_enddoc
2548
- util_parser <<-CONTENT
2549
- # :enddoc:
2550
- CONTENT
2551
-
2552
- assert_throws :eof do
2553
- @parser.parse_top_level_statements @top_level
2554
- end
2555
- end
2556
-
2557
- def test_parse_top_level_statements_stopdoc
2558
- @top_level.stop_doc
2559
- content = "# this is the top-level comment"
2560
-
2561
- util_parser content
2562
-
2563
- @parser.parse_top_level_statements @top_level
2564
-
2565
- assert_empty @top_level.comment
2566
- end
2567
-
2568
- def test_parse_top_level_statements_stopdoc_integration
2569
- content = <<-CONTENT
2570
- # :stopdoc:
2571
-
2572
- class Example
2573
- def method_name
2574
- end
2575
- end
2576
- CONTENT
2577
-
2578
- util_parser content
2579
-
2580
- @parser.parse_top_level_statements @top_level
2581
-
2582
- assert_equal 1, @top_level.classes.length
2583
- assert_empty @top_level.modules
2584
-
2585
- assert @top_level.find_module_named('Example').ignored?
2586
- end
2587
-
2588
- # This tests parse_comment
2589
- def test_parse_top_level_statements_constant_nodoc_integration
2590
- content = <<-CONTENT
2591
- class A
2592
- C = A # :nodoc:
2593
- end
2594
- CONTENT
2595
-
2596
- util_parser content
2597
-
2598
- @parser.parse_top_level_statements @top_level
2599
-
2600
- klass = @top_level.find_module_named('A')
2601
-
2602
- c = klass.constants.first
2603
-
2604
- assert_nil c.document_self, 'C should not be documented'
2605
- end
2606
-
2607
- def test_parse_yield_in_braces_with_parens
2608
- klass = RDoc::NormalClass.new 'Foo'
2609
- klass.parent = @top_level
2610
-
2611
- util_parser "def foo\nn.times { |i| yield nth(i) }\nend"
2612
-
2613
- tk = @parser.get_tk
2614
-
2615
- @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, @comment
2616
-
2617
- foo = klass.method_list.first
2618
- assert_equal 'nth(i)', foo.block_params
2619
- end
2620
-
2621
- def test_read_directive
2622
- parser = util_parser '# :category: test'
2623
-
2624
- directive, value = parser.read_directive %w[category]
2625
-
2626
- assert_equal 'category', directive
2627
- assert_equal 'test', value
2628
-
2629
- assert_kind_of RDoc::RubyToken::TkNL, parser.get_tk
2630
- end
2631
-
2632
- def test_read_directive_allow
2633
- parser = util_parser '# :category: test'
2634
-
2635
- directive = parser.read_directive []
2636
-
2637
- assert_nil directive
2638
-
2639
- assert_kind_of RDoc::RubyToken::TkNL, parser.get_tk
2640
- end
2641
-
2642
- def test_read_directive_empty
2643
- parser = util_parser '# test'
2644
-
2645
- directive = parser.read_directive %w[category]
2646
-
2647
- assert_nil directive
2648
-
2649
- assert_kind_of RDoc::RubyToken::TkNL, parser.get_tk
2650
- end
2651
-
2652
- def test_read_directive_no_comment
2653
- parser = util_parser ''
2654
-
2655
- directive = parser.read_directive %w[category]
2656
-
2657
- assert_nil directive
2658
-
2659
- assert_kind_of RDoc::RubyToken::TkNL, parser.get_tk
2660
- end
2661
-
2662
- def test_read_directive_one_liner
2663
- parser = util_parser '; end # :category: test'
2664
-
2665
- directive, value = parser.read_directive %w[category]
2666
-
2667
- assert_equal 'category', directive
2668
- assert_equal 'test', value
2669
-
2670
- assert_kind_of RDoc::RubyToken::TkSEMICOLON, parser.get_tk
2671
- end
2672
-
2673
- def test_read_documentation_modifiers
2674
- c = RDoc::Context.new
2675
-
2676
- parser = util_parser '# :category: test'
2677
-
2678
- parser.read_documentation_modifiers c, %w[category]
2679
-
2680
- assert_equal 'test', c.current_section.title
2681
- end
2682
-
2683
- def test_read_documentation_modifiers_notnew
2684
- m = RDoc::AnyMethod.new nil, 'initialize'
2685
-
2686
- parser = util_parser '# :notnew: test'
2687
-
2688
- parser.read_documentation_modifiers m, %w[notnew]
2689
-
2690
- assert m.dont_rename_initialize
2691
- end
2692
-
2693
- def test_read_documentation_modifiers_not_dash_new
2694
- m = RDoc::AnyMethod.new nil, 'initialize'
2695
-
2696
- parser = util_parser '# :not-new: test'
2697
-
2698
- parser.read_documentation_modifiers m, %w[not-new]
2699
-
2700
- assert m.dont_rename_initialize
2701
- end
2702
-
2703
- def test_read_documentation_modifiers_not_new
2704
- m = RDoc::AnyMethod.new nil, 'initialize'
2705
-
2706
- parser = util_parser '# :not_new: test'
2707
-
2708
- parser.read_documentation_modifiers m, %w[not_new]
2709
-
2710
- assert m.dont_rename_initialize
2711
- end
2712
-
2713
- def test_sanity_integer
2714
- util_parser '1'
2715
- assert_equal '1', @parser.get_tk.text
2716
-
2717
- util_parser '1.0'
2718
- assert_equal '1.0', @parser.get_tk.text
2719
- end
2720
-
2721
- def test_sanity_interpolation
2722
- last_tk = nil
2723
- util_parser 'class A; B = "#{c}"; end'
2724
-
2725
- while tk = @parser.get_tk do last_tk = tk end
2726
-
2727
- assert_equal "\n", last_tk.text
2728
- end
2729
-
2730
- # If you're writing code like this you're doing it wrong
2731
-
2732
- def test_sanity_interpolation_crazy
2733
- util_parser '"#{"#{"a")}" if b}"'
2734
-
2735
- assert_equal '"#{"#{"a")}" if b}"', @parser.get_tk.text
2736
- assert_equal RDoc::RubyToken::TkNL, @parser.get_tk.class
2737
- end
2738
-
2739
- def test_sanity_interpolation_curly
2740
- util_parser '%{ #{} }'
2741
-
2742
- assert_equal '%Q{ #{} }', @parser.get_tk.text
2743
- assert_equal RDoc::RubyToken::TkNL, @parser.get_tk.class
2744
- end
2745
-
2746
- def test_sanity_interpolation_format
2747
- util_parser '"#{stftime("%m-%d")}"'
2748
-
2749
- while @parser.get_tk do end
2750
- end
2751
-
2752
- def test_sanity_symbol_interpolation
2753
- util_parser ':"#{bar}="'
2754
-
2755
- while @parser.get_tk do end
2756
- end
2757
-
2758
- def test_scan_cr
2759
- content = <<-CONTENT
2760
- class C\r
2761
- def m\r
2762
- a=\\\r
2763
- 123\r
2764
- end\r
2765
- end\r
2766
- CONTENT
2767
-
2768
- util_parser content
2769
-
2770
- @parser.scan
2771
-
2772
- c = @top_level.classes.first
2773
-
2774
- assert_equal 1, c.method_list.length
2775
- end
2776
-
2777
- def test_scan_block_comment
2778
- content = <<-CONTENT
2779
- =begin rdoc
2780
- Foo comment
2781
- =end
2782
-
2783
- class Foo
2784
-
2785
- =begin
2786
- m comment
2787
- =end
2788
-
2789
- def m() end
2790
- end
2791
- CONTENT
2792
-
2793
- util_parser content
2794
-
2795
- @parser.scan
2796
-
2797
- foo = @top_level.classes.first
2798
-
2799
- assert_equal 'Foo comment', foo.comment.text
2800
-
2801
- m = foo.method_list.first
2802
-
2803
- assert_equal 'm comment', m.comment.text
2804
- end
2805
-
2806
- def test_scan_block_comment_nested # Issue #41
2807
- content = <<-CONTENT
2808
- require 'something'
2809
- =begin rdoc
2810
- findmeindoc
2811
- =end
2812
- module Foo
2813
- class Bar
2814
- end
2815
- end
2816
- CONTENT
2817
-
2818
- util_parser content
2819
-
2820
- @parser.scan
2821
-
2822
- foo = @top_level.modules.first
2823
-
2824
- assert_equal 'Foo', foo.full_name
2825
- assert_equal 'findmeindoc', foo.comment.text
2826
-
2827
- bar = foo.classes.first
2828
-
2829
- assert_equal 'Foo::Bar', bar.full_name
2830
- assert_equal '', bar.comment.text
2831
- end
2832
-
2833
- def test_scan_block_comment_notflush
2834
- ##
2835
- #
2836
- # The previous test assumes that between the =begin/=end blocs that there is
2837
- # only one line, or minima formatting directives. This test tests for those
2838
- # who use the =begin bloc with longer / more advanced formatting within.
2839
- #
2840
- ##
2841
- content = <<-CONTENT
2842
- =begin rdoc
2843
-
2844
- = DESCRIPTION
2845
-
2846
- This is a simple test class
2847
-
2848
- = RUMPUS
2849
-
2850
- Is a silly word
2851
-
2852
- =end
2853
- class StevenSimpleClass
2854
- # A band on my iPhone as I wrote this test
2855
- FRUIT_BATS="Make nice music"
2856
-
2857
- =begin rdoc
2858
- A nice girl
2859
- =end
2860
-
2861
- def lauren
2862
- puts "Summoning Lauren!"
2863
- end
2864
- end
2865
- CONTENT
2866
- util_parser content
2867
-
2868
- @parser.scan
2869
-
2870
- foo = @top_level.classes.first
2871
-
2872
- assert_equal "= DESCRIPTION\n\nThis is a simple test class\n\n= RUMPUS\n\nIs a silly word",
2873
- foo.comment.text
2874
-
2875
- m = foo.method_list.first
2876
-
2877
- assert_equal 'A nice girl', m.comment.text
2878
- end
2879
-
2880
- def test_scan_class_nested_nodoc
2881
- content = <<-CONTENT
2882
- class A::B # :nodoc:
2883
- end
2884
- CONTENT
2885
-
2886
- util_parser content
2887
-
2888
- @parser.scan
2889
-
2890
- visible = @store.all_classes_and_modules.select { |mod| mod.display? }
2891
-
2892
- assert_empty visible.map { |mod| mod.full_name }
2893
- end
2894
-
2895
- def test_scan_constant_in_method
2896
- content = <<-CONTENT # newline is after M is important
2897
- module M
2898
- def m
2899
- A
2900
- B::C
2901
- end
2902
- end
2903
- CONTENT
2904
-
2905
- util_parser content
2906
-
2907
- @parser.scan
2908
-
2909
- m = @top_level.modules.first
2910
-
2911
- assert_empty m.constants
2912
-
2913
- assert_empty @store.classes_hash.keys
2914
- assert_equal %w[M], @store.modules_hash.keys
2915
- end
2916
-
2917
- def test_scan_constant_in_rescue
2918
- content = <<-CONTENT # newline is after M is important
2919
- module M
2920
- def m
2921
- rescue A::B
2922
- rescue A::C => e
2923
- rescue A::D, A::E
2924
- rescue A::F,
2925
- A::G
2926
- rescue H
2927
- rescue I => e
2928
- rescue J, K
2929
- rescue L =>
2930
- e
2931
- rescue M;
2932
- rescue N,
2933
- O => e
2934
- end
2935
- end
2936
- CONTENT
2937
-
2938
- util_parser content
2939
-
2940
- @parser.scan
2941
-
2942
- m = @top_level.modules.first
2943
-
2944
- assert_empty m.constants
2945
-
2946
- assert_empty @store.classes_hash.keys
2947
- assert_equal %w[M], @store.modules_hash.keys
2948
- end
2949
-
2950
- def test_scan_constant_nodoc
2951
- content = <<-CONTENT # newline is after M is important
2952
- module M
2953
-
2954
- C = v # :nodoc:
2955
- end
2956
- CONTENT
2957
-
2958
- util_parser content
2959
-
2960
- @parser.scan
2961
-
2962
- c = @top_level.modules.first.constants.first
2963
-
2964
- assert c.documented?
2965
- end
2966
-
2967
- def test_scan_constant_nodoc_block
2968
- content = <<-CONTENT # newline is after M is important
2969
- module M
2970
-
2971
- C = v do # :nodoc:
2972
- end
2973
- end
2974
- CONTENT
2975
-
2976
- util_parser content
2977
-
2978
- @parser.scan
2979
-
2980
- c = @top_level.modules.first.constants.first
2981
-
2982
- assert c.documented?
2983
- end
2984
-
2985
- def test_scan_duplicate_module
2986
- content = <<-CONTENT
2987
- # comment a
2988
- module Foo
2989
- end
2990
-
2991
- # comment b
2992
- module Foo
2993
- end
2994
- CONTENT
2995
-
2996
- util_parser content
2997
-
2998
- @parser.scan
2999
-
3000
- foo = @top_level.modules.first
3001
-
3002
- expected = [
3003
- RDoc::Comment.new('comment b', @top_level)
3004
- ]
3005
-
3006
- assert_equal expected, foo.comment_location.map { |c, l| c }
3007
- end
3008
-
3009
- def test_scan_meta_method_block
3010
- content = <<-CONTENT
3011
- class C
3012
-
3013
- ##
3014
- # my method
3015
-
3016
- inline(:my_method) do |*args|
3017
- "this method used to cause z to disappear"
3018
- end
3019
-
3020
- def z
3021
- end
3022
- CONTENT
3023
-
3024
- util_parser content
3025
-
3026
- @parser.scan
3027
-
3028
- assert_equal 2, @top_level.classes.first.method_list.length
3029
- end
3030
-
3031
- def test_scan_method_semi_method
3032
- content = <<-CONTENT
3033
- class A
3034
- def self.m() end; def self.m=() end
3035
- end
3036
-
3037
- class B
3038
- def self.m() end
3039
- end
3040
- CONTENT
3041
-
3042
- util_parser content
3043
-
3044
- @parser.scan
3045
-
3046
- a = @store.find_class_named 'A'
3047
- assert a, 'missing A'
3048
-
3049
- assert_equal 2, a.method_list.length
3050
-
3051
- b = @store.find_class_named 'B'
3052
- assert b, 'missing B'
3053
-
3054
- assert_equal 1, b.method_list.length
3055
- end
3056
-
3057
- def test_scan_markup_override
3058
- content = <<-CONTENT
3059
- # *awesome*
3060
- class C
3061
- # :markup: rd
3062
- # ((*radical*))
3063
- def m
3064
- end
3065
- end
3066
- CONTENT
3067
-
3068
- util_parser content
3069
-
3070
- @parser.scan
3071
-
3072
- c = @top_level.classes.first
3073
-
3074
- assert_equal 'rdoc', c.comment.format
3075
-
3076
- assert_equal 'rd', c.method_list.first.comment.format
3077
- end
3078
-
3079
- def test_scan_markup_first_comment
3080
- content = <<-CONTENT
3081
- # :markup: rd
3082
-
3083
- # ((*awesome*))
3084
- class C
3085
- # ((*radical*))
3086
- def m
3087
- end
3088
- end
3089
- CONTENT
3090
-
3091
- util_parser content
3092
-
3093
- @parser.scan
3094
-
3095
- c = @top_level.classes.first
3096
-
3097
- assert_equal 'rd', c.comment.format
3098
-
3099
- assert_equal 'rd', c.method_list.first.comment.format
3100
- end
3101
-
3102
- def test_scan_rails_routes
3103
- util_parser <<-ROUTES_RB
3104
- namespace :api do
3105
- scope module: :v1 do
3106
- end
3107
- end
3108
- ROUTES_RB
3109
-
3110
- @parser.scan
3111
-
3112
- assert_empty @top_level.classes
3113
- assert_empty @top_level.modules
3114
- end
3115
-
3116
- def test_scan_tomdoc_meta
3117
- util_parser <<-RUBY
3118
- # :markup: tomdoc
3119
-
3120
- class C
3121
-
3122
- # Signature
3123
- #
3124
- # find_by_<field>[_and_<field>...](args)
3125
- #
3126
- # field - A field name.
3127
-
3128
- end
3129
-
3130
- RUBY
3131
-
3132
- @parser.scan
3133
-
3134
- c = @top_level.classes.first
3135
-
3136
- m = c.method_list.first
3137
-
3138
- assert_equal "find_by_<field>[_and_<field>...]", m.name
3139
- assert_equal "find_by_<field>[_and_<field>...](args)\n", m.call_seq
3140
-
3141
- expected =
3142
- doc(
3143
- head(3, 'Signature'),
3144
- list(:NOTE,
3145
- item(%w[field],
3146
- para('A field name.'))))
3147
- expected.file = @top_level
3148
-
3149
- assert_equal expected, m.comment.parse
3150
- end
3151
-
3152
- def test_scan_stopdoc
3153
- util_parser <<-RUBY
3154
- class C
3155
- # :stopdoc:
3156
- class Hidden
3157
- end
3158
- end
3159
- RUBY
3160
-
3161
- @parser.scan
3162
-
3163
- c = @top_level.classes.first
3164
-
3165
- hidden = c.classes.first
3166
-
3167
- refute hidden.document_self
3168
- assert hidden.ignored?
3169
- end
3170
-
3171
- def test_scan_stopdoc_class_alias
3172
- util_parser <<-RUBY
3173
- # :stopdoc:
3174
- module A
3175
- B = C
3176
- end
3177
- RUBY
3178
-
3179
- @parser.scan
3180
-
3181
- assert_empty @store.all_classes
3182
-
3183
- assert_equal 1, @store.all_modules.length
3184
- m = @store.all_modules.first
3185
-
3186
- assert m.ignored?
3187
- end
3188
-
3189
- def test_scan_stopdoc_nested
3190
- util_parser <<-RUBY
3191
- # :stopdoc:
3192
- class A::B
3193
- end
3194
- RUBY
3195
-
3196
- @parser.scan
3197
-
3198
- a = @store.modules_hash['A']
3199
- a_b = @store.classes_hash['A::B']
3200
-
3201
- refute a.document_self, 'A is inside stopdoc'
3202
- assert a.ignored?, 'A is inside stopdoc'
3203
-
3204
- refute a_b.document_self, 'A::B is inside stopdoc'
3205
- assert a_b.ignored?, 'A::B is inside stopdoc'
3206
- end
3207
-
3208
- def test_scan_struct_self_brackets
3209
- util_parser <<-RUBY
3210
- class C < M.m
3211
- def self.[]
3212
- end
3213
- end
3214
- RUBY
3215
-
3216
- @parser.scan
3217
-
3218
- c = @store.find_class_named 'C'
3219
- assert_equal %w[C::[]], c.method_list.map { |m| m.full_name }
3220
- end
3221
-
3222
- def test_scan_visibility
3223
- util_parser <<-RUBY
3224
- class C
3225
- def a() end
3226
-
3227
- private :a
3228
-
3229
- class << self
3230
- def b() end
3231
- private :b
3232
- end
3233
- end
3234
- RUBY
3235
-
3236
- @parser.scan
3237
-
3238
- c = @store.find_class_named 'C'
3239
-
3240
- c_a = c.find_method_named 'a'
3241
-
3242
- assert_equal :private, c_a.visibility
3243
- refute c_a.singleton
3244
-
3245
- c_b = c.find_method_named 'b'
3246
-
3247
- assert_equal :private, c_b.visibility
3248
- assert c_b.singleton
3249
- end
3250
-
3251
- def test_singleton_method_via_eigenclass
3252
- util_parser <<-RUBY
3253
- class C
3254
- class << self
3255
- def a() end
3256
- end
3257
- end
3258
- RUBY
3259
-
3260
- @parser.scan
3261
-
3262
- c = @store.find_class_named 'C'
3263
- c_a = c.find_method_named 'a'
3264
-
3265
- assert_equal :public, c_a.visibility
3266
- assert c_a.singleton
3267
- end
3268
-
3269
- def test_stopdoc_after_comment
3270
- util_parser <<-EOS
3271
- module Bar
3272
- # hello
3273
- module Foo
3274
- # :stopdoc:
3275
- end
3276
- # there
3277
- class Baz
3278
- # :stopdoc:
3279
- end
3280
- end
3281
- EOS
3282
-
3283
- @parser.parse_statements @top_level
3284
-
3285
- foo = @top_level.modules.first.modules.first
3286
- assert_equal 'Foo', foo.name
3287
- assert_equal 'hello', foo.comment.text
3288
-
3289
- baz = @top_level.modules.first.classes.first
3290
- assert_equal 'Baz', baz.name
3291
- assert_equal 'there', baz.comment.text
3292
- end
3293
-
3294
- def tk klass, scan, line, char, name, text
3295
- klass = RDoc::RubyToken.const_get "Tk#{klass.to_s.upcase}"
3296
-
3297
- token = if klass.instance_method(:initialize).arity == 3 then
3298
- raise ArgumentError, "name not used for #{klass}" if name
3299
- klass.new scan, line, char
3300
- else
3301
- klass.new scan, line, char, name
3302
- end
3303
-
3304
- token.set_text text
3305
-
3306
- token
3307
- end
3308
-
3309
- def util_parser(content)
3310
- @parser = RDoc::Parser::Ruby.new @top_level, @filename, content, @options,
3311
- @stats
3312
- end
3313
-
3314
- def util_two_parsers(first_file_content, second_file_content)
3315
- util_parser first_file_content
3316
-
3317
- @parser2 = RDoc::Parser::Ruby.new @top_level2, @filename,
3318
- second_file_content, @options, @stats
3319
- end
3320
-
3321
- end
3322
-