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,327 +0,0 @@
1
- # -*- coding: us-ascii -*-
2
-
3
- require 'rdoc/test_case'
4
-
5
- class TestRDocParser < RDoc::TestCase
6
-
7
- def setup
8
- super
9
-
10
- @RP = RDoc::Parser
11
- @binary_dat = File.expand_path '../binary.dat', __FILE__
12
-
13
- @fn = 'file.rb'
14
- @top_level = RDoc::TopLevel.new @fn
15
- @options = RDoc::Options.new
16
- end
17
-
18
- def test_class_binary_eh_ISO_2022_JP
19
- iso_2022_jp = File.join Dir.tmpdir, "test_rdoc_parser_#{$$}.rd"
20
-
21
- open iso_2022_jp, 'wb' do |io|
22
- io.write "# coding: ISO-2022-JP\n"
23
- io.write ":\e$B%3%^%s%I\e(B:\n"
24
- end
25
-
26
- refute @RP.binary? iso_2022_jp
27
- ensure
28
- File.unlink iso_2022_jp
29
- end
30
-
31
- def test_class_binary_eh_marshal
32
- marshal = File.join Dir.tmpdir, "test_rdoc_parser_#{$$}.marshal"
33
- open marshal, 'wb' do |io|
34
- io.write Marshal.dump('')
35
- io.write 'lots of text ' * 500
36
- end
37
-
38
- assert @RP.binary?(marshal)
39
- ensure
40
- File.unlink marshal
41
- end
42
-
43
- def test_class_binary_japanese_text
44
- file_name = File.expand_path '../test.ja.txt', __FILE__
45
- refute @RP.binary?(file_name)
46
- end
47
-
48
- def test_class_binary_large_japanese_rdoc
49
- skip "Encoding not implemented" unless Object.const_defined? :Encoding
50
-
51
- capture_io do
52
- begin
53
- extenc, Encoding.default_external =
54
- Encoding.default_external, Encoding::US_ASCII
55
- file_name = File.expand_path '../test.ja.largedoc', __FILE__
56
- assert !@RP.binary?(file_name)
57
- ensure
58
- Encoding.default_external = extenc
59
- end
60
- end
61
- end
62
-
63
- def test_class_binary_japanese_rdoc
64
- skip "Encoding not implemented" unless Object.const_defined? :Encoding
65
-
66
- file_name = File.expand_path '../test.ja.rdoc', __FILE__
67
- refute @RP.binary?(file_name)
68
- end
69
-
70
- def test_class_can_parse
71
- assert_equal @RP.can_parse(__FILE__), @RP::Ruby
72
-
73
- readme_file_name = File.expand_path '../test.txt', __FILE__
74
-
75
- assert_equal @RP::Simple, @RP.can_parse(readme_file_name)
76
-
77
- assert_equal @RP::Simple, @RP.can_parse(@binary_dat)
78
-
79
- jtest_file_name = File.expand_path '../test.ja.txt', __FILE__
80
- assert_equal @RP::Simple, @RP.can_parse(jtest_file_name)
81
-
82
- jtest_rdoc_file_name = File.expand_path '../test.ja.rdoc', __FILE__
83
- assert_equal @RP::Simple, @RP.can_parse(jtest_rdoc_file_name)
84
-
85
- readme_file_name = File.expand_path '../README', __FILE__
86
- assert_equal @RP::Simple, @RP.can_parse(readme_file_name)
87
-
88
- jtest_largerdoc_file_name = File.expand_path '../test.ja.largedoc', __FILE__
89
- assert_equal @RP::Simple, @RP.can_parse(jtest_largerdoc_file_name)
90
-
91
- @RP.alias_extension 'rdoc', 'largedoc'
92
- assert_equal @RP::Simple, @RP.can_parse(jtest_largerdoc_file_name)
93
- end
94
-
95
- def test_class_for_executable
96
- temp_dir do
97
- content = "#!/usr/bin/env ruby -w\n"
98
- open 'app', 'w' do |io| io.write content end
99
- app = @store.add_file 'app'
100
-
101
- parser = @RP.for app, 'app', content, @options, :stats
102
-
103
- assert_kind_of RDoc::Parser::Ruby, parser
104
-
105
- assert_equal 'app', parser.file_name
106
- end
107
- end
108
-
109
- def test_class_for_forbidden
110
- skip 'chmod not supported' if Gem.win_platform?
111
-
112
- tf = Tempfile.open 'forbidden' do |io|
113
- begin
114
- File.chmod 0000, io.path
115
- forbidden = @store.add_file io.path
116
-
117
- parser = @RP.for forbidden, 'forbidden', '', @options, :stats
118
-
119
- assert_nil parser
120
- ensure
121
- File.chmod 0400, io.path
122
- end
123
- io
124
- end
125
- tf.close! if tf.respond_to? :close!
126
- end
127
-
128
- def test_class_for_modeline
129
- temp_dir do
130
- content = "# -*- rdoc -*-\n= NEWS\n"
131
-
132
- open 'NEWS', 'w' do |io| io.write content end
133
- app = @store.add_file 'NEWS'
134
-
135
- parser = @RP.for app, 'NEWS', content, @options, :stats
136
-
137
- assert_kind_of RDoc::Parser::Simple, parser
138
-
139
- assert_equal "= NEWS\n", parser.content
140
- end
141
- end
142
-
143
- def test_can_parse_modeline
144
- readme_ext = File.join Dir.tmpdir, "README.EXT.#{$$}"
145
-
146
- open readme_ext, 'w' do |io|
147
- io.puts "# README.EXT - -*- rdoc -*- created at: Mon Aug 7 16:45:54 JST 1995"
148
- io.puts
149
- io.puts "This document explains how to make extension libraries for Ruby."
150
- end
151
-
152
- assert_equal RDoc::Parser::Simple, @RP.can_parse(readme_ext)
153
- ensure
154
- File.unlink readme_ext
155
- end
156
-
157
- ##
158
- # Selenium hides a .jar file using a .txt extension.
159
-
160
- def test_class_can_parse_zip
161
- hidden_zip = File.expand_path '../hidden.zip.txt', __FILE__
162
- assert_nil @RP.can_parse(hidden_zip)
163
- end
164
-
165
- def test_check_modeline
166
- readme_ext = File.join Dir.tmpdir, "README.EXT.#{$$}"
167
-
168
- open readme_ext, 'w' do |io|
169
- io.puts "# README.EXT - -*- RDoc -*- created at: Mon Aug 7 16:45:54 JST 1995"
170
- io.puts
171
- io.puts "This document explains how to make extension libraries for Ruby."
172
- end
173
-
174
- assert_equal 'rdoc', @RP.check_modeline(readme_ext)
175
- ensure
176
- File.unlink readme_ext
177
- end
178
-
179
- def test_check_modeline_coding
180
- readme_ext = File.join Dir.tmpdir, "README.EXT.#{$$}"
181
-
182
- open readme_ext, 'w' do |io|
183
- io.puts "# -*- coding: utf-8 -*-"
184
- end
185
-
186
- assert_nil @RP.check_modeline readme_ext
187
- ensure
188
- File.unlink readme_ext
189
- end
190
-
191
- def test_check_modeline_with_other
192
- readme_ext = File.join Dir.tmpdir, "README.EXT.#{$$}"
193
-
194
- open readme_ext, 'w' do |io|
195
- io.puts "# README.EXT - -*- mode: RDoc; indent-tabs-mode: nil -*-"
196
- io.puts
197
- io.puts "This document explains how to make extension libraries for Ruby."
198
- end
199
-
200
- assert_equal 'rdoc', @RP.check_modeline(readme_ext)
201
- ensure
202
- File.unlink readme_ext
203
- end
204
-
205
- def test_check_modeline_no_modeline
206
- readme_ext = File.join Dir.tmpdir, "README.EXT.#{$$}"
207
-
208
- open readme_ext, 'w' do |io|
209
- io.puts "This document explains how to make extension libraries for Ruby."
210
- end
211
-
212
- assert_nil @RP.check_modeline(readme_ext)
213
- ensure
214
- File.unlink readme_ext
215
- end
216
-
217
- def test_class_for_binary
218
- rp = @RP.dup
219
-
220
- class << rp
221
- alias old_can_parse can_parse
222
- end
223
-
224
- def rp.can_parse(*args) nil end
225
-
226
- assert_nil @RP.for(nil, @binary_dat, nil, nil, nil)
227
- end
228
-
229
- def test_class_for_markup
230
- content = <<-CONTENT
231
- # coding: utf-8 markup: rd
232
- CONTENT
233
-
234
- parser = @RP.for @top_level, __FILE__, content, @options, nil
235
-
236
- assert_kind_of @RP::RD, parser
237
- end
238
-
239
- def test_class_use_markup
240
- content = <<-CONTENT
241
- # coding: utf-8 markup: rd
242
- CONTENT
243
-
244
- parser = @RP.use_markup content
245
-
246
- assert_equal @RP::RD, parser
247
- end
248
-
249
- def test_class_use_markup_markdown
250
- content = <<-CONTENT
251
- # coding: utf-8 markup: markdown
252
- CONTENT
253
-
254
- parser = @RP.use_markup content
255
-
256
- assert_equal @RP::Ruby, parser
257
- end
258
-
259
- def test_class_use_markup_modeline
260
- content = <<-CONTENT
261
- # -*- coding: utf-8 -*-
262
- # markup: rd
263
- CONTENT
264
-
265
- parser = @RP.use_markup content
266
-
267
- assert_equal @RP::RD, parser
268
- end
269
-
270
- def test_class_use_markup_modeline_shebang
271
- content = <<-CONTENT
272
- #!/bin/sh
273
- /* -*- coding: utf-8 -*-
274
- * markup: rd
275
- */
276
- CONTENT
277
-
278
- parser = @RP.use_markup content
279
-
280
- assert_equal @RP::RD, parser
281
- end
282
-
283
- def test_class_use_markup_shebang
284
- content = <<-CONTENT
285
- #!/usr/bin/env ruby
286
- # coding: utf-8 markup: rd
287
- CONTENT
288
-
289
- parser = @RP.use_markup content
290
-
291
- assert_equal @RP::RD, parser
292
- end
293
-
294
- def test_class_use_markup_tomdoc
295
- content = <<-CONTENT
296
- # coding: utf-8 markup: tomdoc
297
- CONTENT
298
-
299
- parser = @RP.use_markup content
300
-
301
- assert_equal @RP::Ruby, parser
302
- end
303
-
304
- def test_class_use_markup_none
305
- parser = @RP.use_markup ''
306
-
307
- assert_nil parser
308
- end
309
-
310
- def test_class_use_markup_unknown
311
- content = <<-CONTENT
312
- # :markup: RDoc
313
- CONTENT
314
-
315
- parser = @RP.use_markup content
316
-
317
- assert_nil parser
318
- end
319
-
320
- def test_initialize
321
- @RP.new @top_level, @fn, '', @options, nil
322
-
323
- assert_equal @RP, @top_level.parser
324
- end
325
-
326
- end
327
-
@@ -1,1896 +0,0 @@
1
- require 'rdoc/test_case'
2
-
3
- =begin
4
- TODO: test call-seq parsing
5
-
6
- /*
7
- * call-seq:
8
- * ARGF.readlines(sep=$/) -> array
9
- * ARGF.readlines(limit) -> array
10
- * ARGF.readlines(sep, limit) -> array
11
- *
12
- * ARGF.to_a(sep=$/) -> array
13
- * ARGF.to_a(limit) -> array
14
- * ARGF.to_a(sep, limit) -> array
15
- *
16
- * Reads +ARGF+'s current file in its entirety, returning an +Array+ of its
17
- * lines, one line per element. Lines are assumed to be separated by _sep_.
18
- *
19
- * lines = ARGF.readlines
20
- * lines[0] #=> "This is line one\n"
21
- */
22
-
23
- assert call-seq did not stop at first empty line
24
-
25
- /*
26
- * call-seq:
27
- *
28
- * flt ** other -> float
29
- *
30
- * Raises <code>float</code> the <code>other</code> power.
31
- *
32
- * 2.0**3 #=> 8.0
33
- */
34
-
35
- assert call-seq correct (bug: was empty)
36
-
37
- /* call-seq: flt ** other -> float */
38
-
39
- assert call-seq correct
40
-
41
- =end
42
-
43
- class TestRDocParserC < RDoc::TestCase
44
-
45
- def setup
46
- super
47
-
48
- @tempfile = Tempfile.new self.class.name
49
- filename = @tempfile.path
50
-
51
- @top_level = @store.add_file filename
52
- @fn = filename
53
- @options = RDoc::Options.new
54
- @options.verbosity = 2
55
- @stats = RDoc::Stats.new @store, 0
56
- end
57
-
58
- def teardown
59
- super
60
-
61
- @tempfile.close!
62
- end
63
-
64
- def test_class_can_parse
65
- c_parser = RDoc::Parser::C
66
-
67
- temp_dir do
68
- FileUtils.touch 'file.C'
69
- assert_equal c_parser, c_parser.can_parse('file.C')
70
-
71
- FileUtils.touch 'file.CC'
72
- assert_equal c_parser, c_parser.can_parse('file.CC')
73
-
74
- FileUtils.touch 'file.H'
75
- assert_equal c_parser, c_parser.can_parse('file.H')
76
-
77
- FileUtils.touch 'file.HH'
78
- assert_equal c_parser, c_parser.can_parse('file.HH')
79
-
80
- FileUtils.touch 'file.c'
81
- assert_equal c_parser, c_parser.can_parse('file.c')
82
-
83
- FileUtils.touch 'file.cc'
84
- assert_equal c_parser, c_parser.can_parse('file.cc')
85
-
86
- FileUtils.touch 'file.cpp'
87
- assert_equal c_parser, c_parser.can_parse('file.cpp')
88
-
89
- FileUtils.touch 'file.cxx'
90
- assert_equal c_parser, c_parser.can_parse('file.cxx')
91
-
92
- FileUtils.touch 'file.h'
93
- assert_equal c_parser, c_parser.can_parse('file.h')
94
-
95
- FileUtils.touch 'file.hh'
96
- assert_equal c_parser, c_parser.can_parse('file.hh')
97
-
98
- FileUtils.touch 'file.y'
99
- assert_equal c_parser, c_parser.can_parse('file.y')
100
- end
101
- end
102
-
103
- def test_initialize
104
- some_ext = @top_level.add_class RDoc::NormalClass, 'SomeExt'
105
- @top_level.add_class RDoc::SingleClass, 'SomeExtSingle'
106
-
107
- @store.cache[:c_class_variables] = {
108
- @fn => { 'cSomeExt' => 'SomeExt' }
109
- }
110
-
111
- @store.cache[:c_singleton_class_variables] = {
112
- @fn => { 'cSomeExtSingle' => 'SomeExtSingle' }
113
- }
114
-
115
- parser = RDoc::Parser::C.new @top_level, @fn, '', @options, @stats
116
-
117
- expected = { 'cSomeExt' => some_ext }
118
- assert_equal expected, parser.classes
119
-
120
- expected = { 'cSomeExtSingle' => 'SomeExtSingle' }
121
- assert_equal expected, parser.singleton_classes
122
-
123
- expected = {
124
- 'cSomeExt' => 'SomeExt',
125
- 'cSomeExtSingle' => 'SomeExtSingle',
126
- }
127
- known_classes = parser.known_classes.delete_if do |key, _|
128
- RDoc::KNOWN_CLASSES.keys.include? key
129
- end
130
-
131
- assert_equal expected, known_classes
132
- end
133
-
134
- def test_do_attr_rb_attr
135
- content = <<-EOF
136
- void Init_Blah(void) {
137
- cBlah = rb_define_class("Blah", rb_cObject);
138
-
139
- /*
140
- * This is an accessor
141
- */
142
- rb_attr(cBlah, rb_intern("accessor"), 1, 1, Qfalse);
143
-
144
- /*
145
- * This is a reader
146
- */
147
- rb_attr(cBlah, rb_intern("reader"), 1, 0, Qfalse);
148
-
149
- /*
150
- * This is a writer
151
- */
152
- rb_attr(cBlah, rb_intern("writer"), 0, 1, Qfalse);
153
- }
154
- EOF
155
-
156
- klass = util_get_class content, 'cBlah'
157
-
158
- attrs = klass.attributes
159
- assert_equal 3, attrs.length, attrs.inspect
160
-
161
- accessor = attrs.shift
162
- assert_equal 'accessor', accessor.name
163
- assert_equal 'RW', accessor.rw
164
- assert_equal 'This is an accessor', accessor.comment.text
165
- assert_equal @top_level, accessor.file
166
-
167
- reader = attrs.shift
168
- assert_equal 'reader', reader.name
169
- assert_equal 'R', reader.rw
170
- assert_equal 'This is a reader', reader.comment.text
171
-
172
- writer = attrs.shift
173
- assert_equal 'writer', writer.name
174
- assert_equal 'W', writer.rw
175
- assert_equal 'This is a writer', writer.comment.text
176
- end
177
-
178
- def test_do_attr_rb_define_attr
179
- content = <<-EOF
180
- void Init_Blah(void) {
181
- cBlah = rb_define_class("Blah", rb_cObject);
182
-
183
- /*
184
- * This is an accessor
185
- */
186
- rb_define_attr(cBlah, "accessor", 1, 1);
187
- }
188
- EOF
189
-
190
- klass = util_get_class content, 'cBlah'
191
-
192
- attrs = klass.attributes
193
- assert_equal 1, attrs.length, attrs.inspect
194
-
195
- accessor = attrs.shift
196
- assert_equal 'accessor', accessor.name
197
- assert_equal 'RW', accessor.rw
198
- assert_equal 'This is an accessor', accessor.comment.text
199
- assert_equal @top_level, accessor.file
200
- end
201
-
202
- def test_do_aliases
203
- content = <<-EOF
204
- /*
205
- * This should show up as an alias with documentation
206
- */
207
- VALUE blah(VALUE klass, VALUE year) {
208
- }
209
-
210
- void Init_Blah(void) {
211
- cDate = rb_define_class("Date", rb_cObject);
212
-
213
- rb_define_method(cDate, "blah", blah, 1);
214
-
215
- rb_define_alias(cDate, "bleh", "blah");
216
- }
217
- EOF
218
-
219
- klass = util_get_class content, 'cDate'
220
-
221
- methods = klass.method_list
222
- assert_equal 2, methods.length
223
- assert_equal 'bleh', methods.last.name
224
- assert_equal 'blah', methods.last.is_alias_for.name
225
-
226
- assert_equal @top_level, methods.last.is_alias_for.file
227
- assert_equal @top_level, methods.last.file
228
- end
229
-
230
- def test_do_aliases_singleton
231
- content = <<-EOF
232
- /*
233
- * This should show up as a method with documentation
234
- */
235
- VALUE blah(VALUE klass, VALUE year) {
236
- }
237
-
238
- void Init_Blah(void) {
239
- cDate = rb_define_class("Date", rb_cObject);
240
- sDate = rb_singleton_class(cDate);
241
-
242
- rb_define_method(sDate, "blah", blah, 1);
243
-
244
- /*
245
- * This should show up as an alias
246
- */
247
- rb_define_alias(sDate, "bleh", "blah");
248
- }
249
- EOF
250
-
251
- klass = util_get_class content, 'cDate'
252
-
253
- methods = klass.method_list
254
-
255
- assert_equal 2, methods.length
256
- assert_equal 'bleh', methods.last.name
257
- assert methods.last.singleton
258
- assert_equal 'blah', methods.last.is_alias_for.name
259
- assert_equal 'This should show up as an alias', methods.last.comment.text
260
- end
261
-
262
- def test_do_classes_boot_class
263
- content = <<-EOF
264
- /* Document-class: Foo
265
- * this is the Foo boot class
266
- */
267
- VALUE cFoo = boot_defclass("Foo", rb_cObject);
268
- EOF
269
-
270
- klass = util_get_class content, 'cFoo'
271
- assert_equal "this is the Foo boot class", klass.comment.text
272
- assert_equal 'Object', klass.superclass
273
- end
274
-
275
- def test_do_classes_boot_class_nil
276
- content = <<-EOF
277
- /* Document-class: Foo
278
- * this is the Foo boot class
279
- */
280
- VALUE cFoo = boot_defclass("Foo", 0);
281
- EOF
282
-
283
- klass = util_get_class content, 'cFoo'
284
- assert_equal "this is the Foo boot class", klass.comment.text
285
- assert_equal nil, klass.superclass
286
- end
287
-
288
- def test_do_aliases_missing_class
289
- content = <<-EOF
290
- void Init_Blah(void) {
291
- rb_define_alias(cDate, "b", "a");
292
- }
293
- EOF
294
-
295
- _, err = verbose_capture_io do
296
- refute util_get_class(content, 'cDate')
297
- end
298
-
299
- assert_equal "Enclosing class or module \"cDate\" for alias b a is not known\n",
300
- err
301
- end
302
-
303
- def test_do_classes_class
304
- content = <<-EOF
305
- /* Document-class: Foo
306
- * this is the Foo class
307
- */
308
- VALUE cFoo = rb_define_class("Foo", rb_cObject);
309
- EOF
310
-
311
- klass = util_get_class content, 'cFoo'
312
- assert_equal "this is the Foo class", klass.comment.text
313
- end
314
-
315
- def test_do_classes_struct
316
- content = <<-EOF
317
- /* Document-class: Foo
318
- * this is the Foo class
319
- */
320
- VALUE cFoo = rb_struct_define_without_accessor(
321
- "Foo", rb_cObject, foo_alloc,
322
- "some", "various", "fields", NULL);
323
- EOF
324
-
325
- klass = util_get_class content, 'cFoo'
326
- assert_equal "this is the Foo class", klass.comment.text
327
- end
328
-
329
- def test_do_classes_class_under
330
- content = <<-EOF
331
- /* Document-class: Kernel::Foo
332
- * this is the Foo class under Kernel
333
- */
334
- VALUE cFoo = rb_define_class_under(rb_mKernel, "Foo", rb_cObject);
335
- EOF
336
-
337
- klass = util_get_class content, 'cFoo'
338
- assert_equal 'Kernel::Foo', klass.full_name
339
- assert_equal "this is the Foo class under Kernel", klass.comment.text
340
- end
341
-
342
- def test_do_classes_class_under_rb_path2class
343
- content = <<-EOF
344
- /* Document-class: Kernel::Foo
345
- * this is Kernel::Foo < A::B
346
- */
347
- VALUE cFoo = rb_define_class_under(rb_mKernel, "Foo", rb_path2class("A::B"));
348
- EOF
349
-
350
- klass = util_get_class content, 'cFoo'
351
-
352
- assert_equal 'Kernel::Foo', klass.full_name
353
- assert_equal 'A::B', klass.superclass
354
- assert_equal 'this is Kernel::Foo < A::B', klass.comment.text
355
- end
356
-
357
- def test_do_classes_singleton
358
- content = <<-EOF
359
- VALUE cFoo = rb_define_class("Foo", rb_cObject);
360
- VALUE cFooS = rb_singleton_class(cFoo);
361
- EOF
362
-
363
- util_get_class content, 'cFooS'
364
-
365
- assert_equal 'Foo', @parser.singleton_classes['cFooS']
366
- end
367
-
368
- def test_do_classes_module
369
- content = <<-EOF
370
- /* Document-module: Foo
371
- * this is the Foo module
372
- */
373
- VALUE mFoo = rb_define_module("Foo");
374
- EOF
375
-
376
- klass = util_get_class content, 'mFoo'
377
- assert_equal "this is the Foo module", klass.comment.text
378
- end
379
-
380
- def test_do_classes_module_under
381
- content = <<-EOF
382
- /* Document-module: Kernel::Foo
383
- * this is the Foo module under Kernel
384
- */
385
- VALUE mFoo = rb_define_module_under(rb_mKernel, "Foo");
386
- EOF
387
-
388
- klass = util_get_class content, 'mFoo'
389
- assert_equal "this is the Foo module under Kernel", klass.comment.text
390
- end
391
-
392
- def test_do_constants
393
- content = <<-EOF
394
- #include <ruby.h>
395
-
396
- void Init_foo(){
397
- VALUE cFoo = rb_define_class("Foo", rb_cObject);
398
-
399
- /* 300: The highest possible score in bowling */
400
- rb_define_const(cFoo, "PERFECT", INT2FIX(300));
401
-
402
- /* Huzzah!: What you cheer when you roll a perfect game */
403
- rb_define_const(cFoo, "CHEER", rb_str_new2("Huzzah!"));
404
-
405
- /* TEST\:TEST: Checking to see if escaped colon works */
406
- rb_define_const(cFoo, "TEST", rb_str_new2("TEST:TEST"));
407
-
408
- /* \\: The file separator on MS Windows */
409
- rb_define_const(cFoo, "MSEPARATOR", rb_str_new2("\\"));
410
-
411
- /* /: The file separator on Unix */
412
- rb_define_const(cFoo, "SEPARATOR", rb_str_new2("/"));
413
-
414
- /* C:\\Program Files\\Stuff: A directory on MS Windows */
415
- rb_define_const(cFoo, "STUFF", rb_str_new2("C:\\Program Files\\Stuff"));
416
-
417
- /* Default definition */
418
- rb_define_const(cFoo, "NOSEMI", INT2FIX(99));
419
-
420
- rb_define_const(cFoo, "NOCOMMENT", rb_str_new2("No comment"));
421
-
422
- /*
423
- * Multiline comment goes here because this comment spans multiple lines.
424
- * Multiline comment goes here because this comment spans multiple lines.
425
- */
426
- rb_define_const(cFoo, "MULTILINE", INT2FIX(1));
427
-
428
- /*
429
- * 1: Multiline comment goes here because this comment spans multiple lines.
430
- * Multiline comment goes here because this comment spans multiple lines.
431
- */
432
- rb_define_const(cFoo, "MULTILINE_VALUE", INT2FIX(1));
433
-
434
- /* Multiline comment goes here because this comment spans multiple lines.
435
- * Multiline comment goes here because this comment spans multiple lines.
436
- */
437
- rb_define_const(cFoo, "MULTILINE_NOT_EMPTY", INT2FIX(1));
438
-
439
- /*
440
- * Multiline comment goes here because this comment spans multiple lines.
441
- * 1: However, the value extraction should only happen for the first line
442
- */
443
- rb_define_const(cFoo, "MULTILINE_COLON_ON_SECOND_LINE", INT2FIX(1));
444
-
445
- }
446
- EOF
447
-
448
- @parser = util_parser content
449
-
450
- @parser.do_classes
451
- @parser.do_constants
452
-
453
- klass = @parser.classes['cFoo']
454
- assert klass
455
-
456
- constants = klass.constants
457
- assert !klass.constants.empty?
458
-
459
- assert_equal @top_level, constants.first.file
460
-
461
- constants = constants.map { |c| [c.name, c.value, c.comment.text] }
462
-
463
- assert_equal ['PERFECT', '300', 'The highest possible score in bowling '],
464
- constants.shift
465
- assert_equal ['CHEER', 'Huzzah!',
466
- 'What you cheer when you roll a perfect game '],
467
- constants.shift
468
- assert_equal ['TEST', 'TEST:TEST',
469
- 'Checking to see if escaped colon works '],
470
- constants.shift
471
- assert_equal ['MSEPARATOR', '\\',
472
- 'The file separator on MS Windows '],
473
- constants.shift
474
- assert_equal ['SEPARATOR', '/',
475
- 'The file separator on Unix '],
476
- constants.shift
477
- assert_equal ['STUFF', 'C:\\Program Files\\Stuff',
478
- 'A directory on MS Windows '],
479
- constants.shift
480
- assert_equal ['NOSEMI', 'INT2FIX(99)',
481
- 'Default definition '],
482
- constants.shift
483
- assert_equal ['NOCOMMENT', 'rb_str_new2("No comment")', ''],
484
- constants.shift
485
-
486
- comment = <<-EOF.chomp
487
- Multiline comment goes here because this comment spans multiple lines.
488
- Multiline comment goes here because this comment spans multiple lines.
489
- EOF
490
- assert_equal ['MULTILINE', 'INT2FIX(1)', comment], constants.shift
491
- assert_equal ['MULTILINE_VALUE', '1', comment], constants.shift
492
- assert_equal ['MULTILINE_NOT_EMPTY', 'INT2FIX(1)', comment], constants.shift
493
-
494
- comment = <<-EOF.chomp
495
- Multiline comment goes here because this comment spans multiple lines.
496
- 1: However, the value extraction should only happen for the first line
497
- EOF
498
- assert_equal ['MULTILINE_COLON_ON_SECOND_LINE', 'INT2FIX(1)', comment],
499
- constants.shift
500
-
501
- assert constants.empty?, constants.inspect
502
- end
503
-
504
- def test_do_constants_curses
505
- content = <<-EOF
506
- void Init_curses(){
507
- mCurses = rb_define_module("Curses");
508
-
509
- /*
510
- * Document-const: Curses::COLOR_BLACK
511
- *
512
- * Value of the color black
513
- */
514
- rb_curses_define_const(COLOR_BLACK);
515
- }
516
- EOF
517
-
518
- @parser = util_parser content
519
-
520
- @parser.do_modules
521
- @parser.do_classes
522
- @parser.do_constants
523
-
524
- klass = @parser.classes['mCurses']
525
-
526
- constants = klass.constants
527
- refute_empty klass.constants
528
-
529
- assert_equal 'COLOR_BLACK', constants.first.name
530
- assert_equal 'UINT2NUM(COLOR_BLACK)', constants.first.value
531
- assert_equal 'Value of the color black', constants.first.comment.text
532
- end
533
-
534
- def test_do_constants_file
535
- content = <<-EOF
536
- void Init_File(void) {
537
- /* Document-const: LOCK_SH
538
- *
539
- * Shared lock
540
- */
541
- rb_file_const("LOCK_SH", INT2FIX(LOCK_SH));
542
- }
543
- EOF
544
-
545
- @parser = util_parser content
546
-
547
- @parser.do_modules
548
- @parser.do_classes
549
- @parser.do_constants
550
-
551
- klass = @parser.classes['rb_mFConst']
552
-
553
- constants = klass.constants
554
- refute_empty klass.constants
555
-
556
- constant = constants.first
557
-
558
- assert_equal 'LOCK_SH', constant.name
559
- assert_equal 'INT2FIX(LOCK_SH)', constant.value
560
- assert_equal 'Shared lock', constant.comment.text
561
- end
562
-
563
- def test_do_includes
564
- content = <<-EOF
565
- Init_foo() {
566
- VALUE cFoo = rb_define_class("Foo", rb_cObject);
567
- VALUE mInc = rb_define_module("Inc");
568
-
569
- rb_include_module(cFoo, mInc);
570
- }
571
- EOF
572
-
573
- klass = util_get_class content, 'cFoo'
574
-
575
- incl = klass.includes.first
576
- assert_equal 'Inc', incl.name
577
- assert_equal '', incl.comment.text
578
- assert_equal @top_level, incl.file
579
- end
580
-
581
- # HACK parsing warning instead of setting up in file
582
- def test_do_methods_in_c
583
- content = <<-EOF
584
- VALUE blah(VALUE klass, VALUE year) {
585
- }
586
-
587
- void Init_Blah(void) {
588
- cDate = rb_define_class("Date", rb_cObject);
589
-
590
- rb_define_method(cDate, "blah", blah, 1); /* in blah.c */
591
- }
592
- EOF
593
-
594
- klass = nil
595
-
596
- _, err = verbose_capture_io do
597
- klass = util_get_class content, 'cDate'
598
- end
599
-
600
- assert_match ' blah.c ', err
601
- end
602
-
603
- # HACK parsing warning instead of setting up in file
604
- def test_do_methods_in_cpp
605
- content = <<-EOF
606
- VALUE blah(VALUE klass, VALUE year) {
607
- }
608
-
609
- void Init_Blah(void) {
610
- cDate = rb_define_class("Date", rb_cObject);
611
-
612
- rb_define_method(cDate, "blah", blah, 1); /* in blah.cpp */
613
- }
614
- EOF
615
-
616
- klass = nil
617
-
618
- _, err = verbose_capture_io do
619
- klass = util_get_class content, 'cDate'
620
- end
621
-
622
- assert_match ' blah.cpp ', err
623
- end
624
-
625
- # HACK parsing warning instead of setting up in file
626
- def test_do_methods_in_y
627
- content = <<-EOF
628
- VALUE blah(VALUE klass, VALUE year) {
629
- }
630
-
631
- void Init_Blah(void) {
632
- cDate = rb_define_class("Date", rb_cObject);
633
-
634
- rb_define_method(cDate, "blah", blah, 1); /* in blah.y */
635
- }
636
- EOF
637
-
638
- klass = nil
639
-
640
- _, err = verbose_capture_io do
641
- klass = util_get_class content, 'cDate'
642
- end
643
-
644
- assert_match ' blah.y ', err
645
- end
646
-
647
- def test_do_methods_singleton_class
648
- content = <<-EOF
649
- VALUE blah(VALUE klass, VALUE year) {
650
- }
651
-
652
- void Init_Blah(void) {
653
- cDate = rb_define_class("Date", rb_cObject);
654
- sDate = rb_singleton_class(cDate);
655
-
656
- rb_define_method(sDate, "blah", blah, 1);
657
- }
658
- EOF
659
-
660
- klass = util_get_class content, 'cDate'
661
-
662
- methods = klass.method_list
663
- assert_equal 1, methods.length
664
- assert_equal 'blah', methods.first.name
665
- assert methods.first.singleton
666
- end
667
-
668
- def test_do_missing
669
- parser = util_parser
670
-
671
- klass_a = @top_level.add_class RDoc::ClassModule, 'A'
672
- parser.classes['a'] = klass_a
673
-
674
- parser.enclosure_dependencies['c'] << 'b'
675
- parser.enclosure_dependencies['b'] << 'a'
676
- parser.enclosure_dependencies['d'] << 'a'
677
-
678
- parser.missing_dependencies['d'] = ['d', :class, 'D', 'Object', 'a']
679
- parser.missing_dependencies['c'] = ['c', :class, 'C', 'Object', 'b']
680
- parser.missing_dependencies['b'] = ['b', :class, 'B', 'Object', 'a']
681
-
682
- parser.do_missing
683
-
684
- assert_equal %w[A A::B A::B::C A::D],
685
- @store.all_classes_and_modules.map { |m| m.full_name }.sort
686
- end
687
-
688
- def test_do_missing_cycle
689
- parser = util_parser
690
-
691
- klass_a = @top_level.add_class RDoc::ClassModule, 'A'
692
- parser.classes['a'] = klass_a
693
-
694
- parser.enclosure_dependencies['c'] << 'b'
695
- parser.enclosure_dependencies['b'] << 'a'
696
-
697
- parser.missing_dependencies['c'] = ['c', :class, 'C', 'Object', 'b']
698
- parser.missing_dependencies['b'] = ['b', :class, 'B', 'Object', 'a']
699
-
700
- parser.enclosure_dependencies['y'] << 'z'
701
- parser.enclosure_dependencies['z'] << 'y'
702
-
703
- parser.missing_dependencies['y'] = ['y', :class, 'Y', 'Object', 'z']
704
- parser.missing_dependencies['z'] = ['z', :class, 'Z', 'Object', 'y']
705
-
706
- _, err = verbose_capture_io do
707
- parser.do_missing
708
- end
709
-
710
- expected = 'Unable to create class Y (y), class Z (z) ' +
711
- 'due to a cyclic class or module creation'
712
-
713
- assert_equal expected, err.chomp
714
-
715
- assert_equal %w[A A::B A::B::C],
716
- @store.all_classes_and_modules.map { |m| m.full_name }.sort
717
- end
718
-
719
- def test_find_alias_comment
720
- parser = util_parser
721
-
722
- comment = parser.find_alias_comment 'C', '[]', 'index'
723
-
724
- assert_equal '', comment.text
725
-
726
- parser = util_parser <<-C
727
- /*
728
- * comment
729
- */
730
-
731
- rb_define_alias(C, "[]", "index");
732
- C
733
-
734
- comment = parser.find_alias_comment 'C', '[]', 'index'
735
-
736
- assert_equal "/*\n * comment\n */\n\n", comment.text
737
- end
738
-
739
- def test_find_attr_comment_document_attr
740
- parser= util_parser <<-C
741
- /*
742
- * Document-attr: y
743
- * comment
744
- */
745
- C
746
-
747
- comment = parser.find_attr_comment nil, 'y'
748
-
749
- assert_equal "/*\n * \n * comment\n */", comment.text
750
- end
751
-
752
- def test_find_attr_comment_document_attr_oneline
753
- parser= util_parser <<-C
754
- /* Document-attr: y
755
- * comment
756
- */
757
- C
758
-
759
- comment = parser.find_attr_comment nil, 'y'
760
-
761
- assert_equal "/* \n * comment\n */", comment.text
762
- end
763
-
764
- def test_find_attr_comment_document_attr_overlap
765
- parser= util_parser <<-C
766
- /* Document-attr: x
767
- * comment
768
- */
769
-
770
- /* Document-attr: y
771
- * comment
772
- */
773
- C
774
-
775
- comment = parser.find_attr_comment nil, 'y'
776
-
777
- assert_equal "/* \n * comment\n */", comment.text
778
- end
779
-
780
- def test_find_class_comment
781
- @options.rdoc_include << File.dirname(__FILE__)
782
-
783
- content = <<-EOF
784
- /*
785
- * Comment 1
786
- */
787
- foo = rb_define_class("MyClassName1", rb_cObject);
788
-
789
- /*
790
- * Comment 2
791
- */
792
- bar = rb_define_class("MyClassName2", rb_cObject);
793
- EOF
794
-
795
- util_get_class content
796
-
797
- assert_equal "Comment 1", @parser.classes['foo'].comment.text
798
- assert_equal "Comment 2", @parser.classes['bar'].comment.text
799
- end
800
-
801
- def test_find_class_comment_init
802
- content = <<-EOF
803
- /*
804
- * a comment for class Foo
805
- */
806
- void
807
- Init_Foo(void) {
808
- VALUE foo = rb_define_class("Foo", rb_cObject);
809
- }
810
- EOF
811
-
812
- klass = util_get_class content, 'foo'
813
-
814
- assert_equal "a comment for class Foo", klass.comment.text
815
- end
816
-
817
- def test_find_class_comment_define_class
818
- content = <<-EOF
819
- /*
820
- * a comment for class Foo
821
- */
822
- VALUE foo = rb_define_class("Foo", rb_cObject);
823
- EOF
824
-
825
- klass = util_get_class content, 'foo'
826
-
827
- assert_equal "a comment for class Foo", klass.comment.text
828
- end
829
-
830
- def test_find_class_comment_define_class_Init_Foo
831
- content = <<-EOF
832
- /*
833
- * a comment for class Foo on Init
834
- */
835
- void
836
- Init_Foo(void) {
837
- /*
838
- * a comment for class Foo on rb_define_class
839
- */
840
- VALUE foo = rb_define_class("Foo", rb_cObject);
841
- }
842
- EOF
843
-
844
- klass = util_get_class content, 'foo'
845
-
846
- assert_equal "a comment for class Foo on Init", klass.comment.text
847
- end
848
-
849
- def test_find_class_comment_define_class_Init_Foo_no_void
850
- content = <<-EOF
851
- /*
852
- * a comment for class Foo on Init
853
- */
854
- void
855
- Init_Foo() {
856
- /*
857
- * a comment for class Foo on rb_define_class
858
- */
859
- VALUE foo = rb_define_class("Foo", rb_cObject);
860
- }
861
- EOF
862
-
863
- klass = util_get_class content, 'foo'
864
-
865
- assert_equal "a comment for class Foo on Init", klass.comment.text
866
- end
867
-
868
- def test_find_class_comment_define_class_bogus_comment
869
- content = <<-EOF
870
- /*
871
- * a comment for other_function
872
- */
873
- void
874
- other_function() {
875
- }
876
-
877
- void
878
- Init_Foo(void) {
879
- VALUE foo = rb_define_class("Foo", rb_cObject);
880
- }
881
- EOF
882
-
883
- klass = util_get_class content, 'foo'
884
-
885
- assert_equal '', klass.comment.text
886
- end
887
-
888
- def test_find_class_comment_define_class_under
889
- content = <<-EOF
890
- /*
891
- * a comment for class Foo
892
- */
893
- VALUE foo = rb_define_class_under(rb_cObject, "Foo", rb_cObject);
894
- EOF
895
-
896
- klass = util_get_class content, 'foo'
897
-
898
- assert_equal "a comment for class Foo", klass.comment.text
899
- end
900
-
901
- def test_find_class_comment_define_class_under_Init
902
- content = <<-EOF
903
- /*
904
- * a comment for class Foo on Init
905
- */
906
- void
907
- Init_Foo(void) {
908
- /*
909
- * a comment for class Foo on rb_define_class
910
- */
911
- VALUE foo = rb_define_class_under(rb_cObject, "Foo", rb_cObject);
912
- }
913
- EOF
914
-
915
- klass = util_get_class content, 'foo'
916
-
917
- # the inner comment is used since Object::Foo is not necessarily the same
918
- # thing as "Foo" for Init_
919
- assert_equal "a comment for class Foo on rb_define_class",
920
- klass.comment.text
921
- end
922
-
923
- def test_find_const_comment_rb_define
924
- content = <<-EOF
925
- /*
926
- * A comment
927
- */
928
- rb_define_const(cFoo, "CONST", value);
929
- EOF
930
-
931
- parser = util_parser content
932
-
933
- comment = parser.find_const_comment 'const', 'CONST'
934
-
935
- assert_equal "/*\n * A comment\n */\n", comment.text
936
- end
937
-
938
- def test_find_const_comment_document_const
939
- content = <<-EOF
940
- /*
941
- * Document-const: CONST
942
- *
943
- * A comment
944
- */
945
- EOF
946
-
947
- parser = util_parser content
948
-
949
- comment = parser.find_const_comment nil, 'CONST'
950
-
951
- assert_equal "/*\n *\n * A comment\n */", comment.text
952
- end
953
-
954
- def test_find_const_comment_document_const_full_name
955
- content = <<-EOF
956
- /*
957
- * Document-const: Foo::CONST
958
- *
959
- * A comment
960
- */
961
- EOF
962
-
963
- parser = util_parser content
964
-
965
- comment = parser.find_const_comment nil, 'CONST', 'Foo'
966
-
967
- assert_equal "/*\n *\n * A comment\n */", comment.text
968
- end
969
-
970
- def test_find_body
971
- content = <<-EOF
972
- /*
973
- * a comment for other_function
974
- */
975
- VALUE
976
- other_function() {
977
- }
978
-
979
- void
980
- Init_Foo(void) {
981
- VALUE foo = rb_define_class("Foo", rb_cObject);
982
-
983
- rb_define_method(foo, "my_method", other_function, 0);
984
- }
985
- EOF
986
-
987
- klass = util_get_class content, 'foo'
988
- other_function = klass.method_list.first
989
-
990
- assert_equal 'my_method', other_function.name
991
- assert_equal "a comment for other_function",
992
- other_function.comment.text
993
- assert_equal '()', other_function.params
994
-
995
- code = other_function.token_stream.first.text
996
-
997
- assert_equal "VALUE\nother_function() {\n}", code
998
- end
999
-
1000
- def test_find_body_2
1001
- content = <<-CONTENT
1002
- /* Copyright (C) 2010 Sven Herzberg
1003
- *
1004
- * This file is free software; the author(s) gives unlimited
1005
- * permission to copy and/or distribute it, with or without
1006
- * modifications, as long as this notice is preserved.
1007
- */
1008
-
1009
- #include <ruby.h>
1010
-
1011
- static VALUE
1012
- wrap_initialize (VALUE self)
1013
- {
1014
- return self;
1015
- }
1016
-
1017
- /* */
1018
- static VALUE
1019
- wrap_shift (VALUE self,
1020
- VALUE arg)
1021
- {
1022
- return self;
1023
- }
1024
-
1025
- void
1026
- init_gi_repository (void)
1027
- {
1028
- VALUE mTest = rb_define_module ("Test");
1029
- VALUE cTest = rb_define_class_under (mTest, "Test", rb_cObject);
1030
-
1031
- rb_define_method (cTest, "initialize", wrap_initialize, 0);
1032
- rb_define_method (cTest, "shift", wrap_shift, 0);
1033
- }
1034
- CONTENT
1035
-
1036
- klass = util_get_class content, 'cTest'
1037
- assert_equal 2, klass.method_list.length
1038
- end
1039
-
1040
- def test_find_body_cast
1041
- content = <<-EOF
1042
- /*
1043
- * a comment for other_function
1044
- */
1045
- VALUE
1046
- other_function() {
1047
- }
1048
-
1049
- void
1050
- Init_Foo(void) {
1051
- VALUE foo = rb_define_class("Foo", rb_cObject);
1052
-
1053
- rb_define_method(foo, "my_method", (METHOD)other_function, 0);
1054
- }
1055
- EOF
1056
-
1057
- klass = util_get_class content, 'foo'
1058
- other_function = klass.method_list.first
1059
-
1060
- assert_equal 'my_method', other_function.name
1061
- assert_equal "a comment for other_function",
1062
- other_function.comment.text
1063
- assert_equal '()', other_function.params
1064
-
1065
- code = other_function.token_stream.first.text
1066
-
1067
- assert_equal "VALUE\nother_function() {\n}", code
1068
- end
1069
-
1070
- def test_find_body_define
1071
- content = <<-EOF
1072
- #define something something_else
1073
-
1074
- #define other_function rb_other_function
1075
-
1076
- /*
1077
- * a comment for rb_other_function
1078
- */
1079
- VALUE
1080
- rb_other_function() {
1081
- }
1082
-
1083
- void
1084
- Init_Foo(void) {
1085
- VALUE foo = rb_define_class("Foo", rb_cObject);
1086
-
1087
- rb_define_method(foo, "my_method", other_function, 0);
1088
- }
1089
- EOF
1090
-
1091
- klass = util_get_class content, 'foo'
1092
- other_function = klass.method_list.first
1093
-
1094
- assert_equal 'my_method', other_function.name
1095
- assert_equal 'a comment for rb_other_function', other_function.comment.text
1096
- assert_equal '()', other_function.params
1097
- assert_equal 118, other_function.offset
1098
- assert_equal 8, other_function.line
1099
-
1100
- code = other_function.token_stream.first.text
1101
-
1102
- assert_equal "VALUE\nrb_other_function() {\n}", code
1103
- end
1104
-
1105
- def test_find_body_define_comment
1106
- content = <<-EOF
1107
- /*
1108
- * a comment for other_function
1109
- */
1110
- #define other_function rb_other_function
1111
-
1112
- /* */
1113
- VALUE
1114
- rb_other_function() {
1115
- }
1116
-
1117
- void
1118
- Init_Foo(void) {
1119
- VALUE foo = rb_define_class("Foo", rb_cObject);
1120
-
1121
- rb_define_method(foo, "my_method", other_function, 0);
1122
- }
1123
- EOF
1124
-
1125
- klass = util_get_class content, 'foo'
1126
- other_function = klass.method_list.first
1127
-
1128
- assert_equal 'my_method', other_function.name
1129
- assert_equal 'a comment for other_function', other_function.comment.text
1130
- assert_equal '()', other_function.params
1131
- assert_equal 39, other_function.offset
1132
- assert_equal 4, other_function.line
1133
-
1134
- code = other_function.token_stream.first.text
1135
-
1136
- assert_equal "#define other_function rb_other_function", code
1137
- end
1138
-
1139
- def test_find_body_document_method
1140
- content = <<-EOF
1141
- /*
1142
- * Document-method: bar
1143
- * Document-method: baz
1144
- *
1145
- * a comment for bar
1146
- */
1147
- VALUE
1148
- bar() {
1149
- }
1150
-
1151
- void
1152
- Init_Foo(void) {
1153
- VALUE foo = rb_define_class("Foo", rb_cObject);
1154
-
1155
- rb_define_method(foo, "bar", bar, 0);
1156
- rb_define_method(foo, "baz", bar, 0);
1157
- }
1158
- EOF
1159
-
1160
- klass = util_get_class content, 'foo'
1161
- assert_equal 2, klass.method_list.length
1162
-
1163
- methods = klass.method_list.sort
1164
-
1165
- bar = methods.first
1166
- assert_equal 'Foo#bar', bar.full_name
1167
- assert_equal "a comment for bar", bar.comment.text
1168
-
1169
- baz = methods.last
1170
- assert_equal 'Foo#baz', baz.full_name
1171
- assert_equal "a comment for bar", baz.comment.text
1172
- end
1173
-
1174
- def test_find_body_document_method_equals
1175
- content = <<-EOF
1176
- /*
1177
- * Document-method: Zlib::GzipFile#mtime=
1178
- *
1179
- * A comment
1180
- */
1181
- static VALUE
1182
- rb_gzfile_set_mtime(VALUE obj, VALUE mtime)
1183
- {
1184
-
1185
- void
1186
- Init_zlib() {
1187
- mZlib = rb_define_module("Zlib");
1188
- cGzipFile = rb_define_class_under(mZlib, "GzipFile", rb_cObject);
1189
- cGzipWriter = rb_define_class_under(mZlib, "GzipWriter", cGzipFile);
1190
- rb_define_method(cGzipWriter, "mtime=", rb_gzfile_set_mtime, 1);
1191
- }
1192
- EOF
1193
-
1194
- klass = util_get_class content, 'cGzipWriter'
1195
- assert_equal 1, klass.method_list.length
1196
-
1197
- methods = klass.method_list.sort
1198
-
1199
- bar = methods.first
1200
- assert_equal 'Zlib::GzipWriter#mtime=', bar.full_name
1201
- assert_equal 'A comment', bar.comment.text
1202
- end
1203
-
1204
- def test_find_body_document_method_same
1205
- content = <<-EOF
1206
- VALUE
1207
- s_bar() {
1208
- }
1209
-
1210
- VALUE
1211
- bar() {
1212
- }
1213
-
1214
- /*
1215
- * Document-method: Foo::bar
1216
- *
1217
- * a comment for Foo::bar
1218
- */
1219
-
1220
- /*
1221
- * Document-method: Foo#bar
1222
- *
1223
- * a comment for Foo#bar
1224
- */
1225
-
1226
- void
1227
- Init_Foo(void) {
1228
- VALUE foo = rb_define_class("Foo", rb_cObject);
1229
-
1230
- rb_define_singleton_method(foo, "bar", s_bar, 0);
1231
- rb_define_method(foo, "bar", bar, 0);
1232
- }
1233
- EOF
1234
-
1235
- klass = util_get_class content, 'foo'
1236
- assert_equal 2, klass.method_list.length
1237
-
1238
- methods = klass.method_list.sort
1239
-
1240
- s_bar = methods.first
1241
- assert_equal 'Foo::bar', s_bar.full_name
1242
- assert_equal "a comment for Foo::bar", s_bar.comment.text
1243
-
1244
- bar = methods.last
1245
- assert_equal 'Foo#bar', bar.full_name
1246
- assert_equal "a comment for Foo#bar", bar.comment.text
1247
- end
1248
-
1249
- def test_find_body_macro
1250
- content = <<-EOF
1251
- /*
1252
- * a comment for other_function
1253
- */
1254
- DLL_LOCAL VALUE
1255
- other_function() {
1256
- }
1257
-
1258
- void
1259
- Init_Foo(void) {
1260
- VALUE foo = rb_define_class("Foo", rb_cObject);
1261
-
1262
- rb_define_method(foo, "my_method", other_function, 0);
1263
- }
1264
- EOF
1265
-
1266
- klass = util_get_class content, 'foo'
1267
- other_function = klass.method_list.first
1268
-
1269
- assert_equal 'my_method', other_function.name
1270
- assert_equal "a comment for other_function",
1271
- other_function.comment.text
1272
- assert_equal '()', other_function.params
1273
-
1274
- code = other_function.token_stream.first.text
1275
-
1276
- assert_equal "DLL_LOCAL VALUE\nother_function() {\n}", code
1277
- end
1278
-
1279
- def test_find_modifiers_call_seq
1280
- comment = RDoc::Comment.new <<-COMMENT
1281
- call-seq:
1282
- commercial() -> Date <br />
1283
-
1284
- If no arguments are given:
1285
-
1286
- COMMENT
1287
-
1288
- parser = util_parser
1289
- method_obj = RDoc::AnyMethod.new nil, 'blah'
1290
-
1291
- parser.find_modifiers comment, method_obj
1292
-
1293
- expected = <<-CALL_SEQ.chomp
1294
- commercial() -> Date <br />
1295
-
1296
- CALL_SEQ
1297
-
1298
- assert_equal expected, method_obj.call_seq
1299
- end
1300
-
1301
- def test_find_modifiers_nodoc
1302
- comment = RDoc::Comment.new <<-COMMENT
1303
- /* :nodoc:
1304
- *
1305
- * Blah
1306
- */
1307
-
1308
- COMMENT
1309
-
1310
- parser = util_parser
1311
- method_obj = RDoc::AnyMethod.new nil, 'blah'
1312
-
1313
- parser.find_modifiers comment, method_obj
1314
-
1315
- assert_equal nil, method_obj.document_self
1316
- end
1317
-
1318
- def test_find_modifiers_yields
1319
- comment = RDoc::Comment.new <<-COMMENT
1320
- /* :yields: a, b
1321
- *
1322
- * Blah
1323
- */
1324
-
1325
- COMMENT
1326
-
1327
- parser = util_parser
1328
- method_obj = RDoc::AnyMethod.new nil, 'blah'
1329
-
1330
- parser.find_modifiers comment, method_obj
1331
-
1332
- assert_equal 'a, b', method_obj.block_params
1333
-
1334
- assert_equal "\n\nBlah", comment.text
1335
- end
1336
-
1337
- def test_handle_method_args_minus_1
1338
- parser = util_parser "Document-method: Object#m\n blah */"
1339
-
1340
- parser.content = <<-BODY
1341
- VALUE
1342
- rb_other(VALUE obj) {
1343
- rb_funcall(obj, rb_intern("other"), 0);
1344
- return rb_str_new2("blah, blah, blah");
1345
- }
1346
-
1347
- VALUE
1348
- rb_m(int argc, VALUE *argv, VALUE obj) {
1349
- VALUE o1, o2;
1350
- rb_scan_args(argc, argv, "1", &o1, &o2);
1351
- }
1352
- BODY
1353
-
1354
- parser.handle_method 'method', 'rb_cObject', 'm', 'rb_m', -1
1355
-
1356
- m = @top_level.find_module_named('Object').method_list.first
1357
-
1358
- assert_equal 'm', m.name
1359
- assert_equal @top_level, m.file
1360
- assert_equal 115, m.offset
1361
- assert_equal 7, m.line
1362
-
1363
- assert_equal '(p1)', m.params
1364
- end
1365
-
1366
- def test_handle_method_args_0
1367
- parser = util_parser "Document-method: BasicObject#==\n blah */"
1368
-
1369
- parser.handle_method 'method', 'rb_cBasicObject', '==', 'rb_obj_equal', 0
1370
-
1371
- bo = @top_level.find_module_named 'BasicObject'
1372
-
1373
- assert_equal 1, bo.method_list.length
1374
-
1375
- equals2 = bo.method_list.first
1376
-
1377
- assert_equal '()', equals2.params
1378
- end
1379
-
1380
- def test_handle_method_args_1
1381
- parser = util_parser "Document-method: BasicObject#==\n blah */"
1382
-
1383
- parser.handle_method 'method', 'rb_cBasicObject', '==', 'rb_obj_equal', 1
1384
-
1385
- bo = @top_level.find_module_named 'BasicObject'
1386
-
1387
- assert_equal 1, bo.method_list.length
1388
-
1389
- equals2 = bo.method_list.first
1390
-
1391
- assert_equal '(p1)', equals2.params
1392
- end
1393
-
1394
- def test_handle_method_args_2
1395
- parser = util_parser "Document-method: BasicObject#==\n blah */"
1396
-
1397
- parser.handle_method 'method', 'rb_cBasicObject', '==', 'rb_obj_equal', 2
1398
-
1399
- bo = @top_level.find_module_named 'BasicObject'
1400
-
1401
- assert_equal 1, bo.method_list.length
1402
-
1403
- equals2 = bo.method_list.first
1404
-
1405
- assert_equal '(p1, p2)', equals2.params
1406
- end
1407
-
1408
- # test_handle_args_minus_1 handled by test_handle_method
1409
-
1410
- def test_handle_method_args_minus_2
1411
- parser = util_parser "Document-method: BasicObject#==\n blah */"
1412
-
1413
- parser.handle_method 'method', 'rb_cBasicObject', '==', 'rb_obj_equal', -2
1414
-
1415
- bo = @top_level.find_module_named 'BasicObject'
1416
-
1417
- assert_equal 1, bo.method_list.length
1418
-
1419
- equals2 = bo.method_list.first
1420
-
1421
- assert_equal '(*args)', equals2.params
1422
- end
1423
-
1424
- def test_handle_method_initialize
1425
- parser = util_parser "Document-method: BasicObject::new\n blah */"
1426
-
1427
- parser.handle_method('private_method', 'rb_cBasicObject',
1428
- 'initialize', 'rb_obj_dummy', -1)
1429
-
1430
- bo = @top_level.find_module_named 'BasicObject'
1431
-
1432
- assert_equal 1, bo.method_list.length
1433
-
1434
- new = bo.method_list.first
1435
-
1436
- assert_equal 'new', new.name
1437
- assert_equal :public, new.visibility
1438
- end
1439
-
1440
- def test_handle_singleton
1441
- parser = util_parser <<-SINGLE
1442
- void Init_Blah(void) {
1443
- cDate = rb_define_class("Date", rb_cObject);
1444
- sDate = rb_singleton_class(cDate);
1445
- }
1446
- SINGLE
1447
-
1448
- parser.scan
1449
-
1450
- assert_equal 'Date', parser.known_classes['sDate']
1451
- assert_equal 'Date', parser.singleton_classes['sDate']
1452
- end
1453
-
1454
- def test_look_for_directives_in
1455
- parser = util_parser
1456
-
1457
- comment = RDoc::Comment.new "# :other: not_handled\n"
1458
-
1459
- parser.look_for_directives_in @top_level, comment
1460
-
1461
- assert_equal "# :other: not_handled\n", comment.text
1462
- assert_equal 'not_handled', @top_level.metadata['other']
1463
- end
1464
-
1465
- def test_load_variable_map
1466
- some_ext = @top_level.add_class RDoc::NormalClass, 'SomeExt'
1467
- @top_level.add_class RDoc::NormalClass, 'OtherExt'
1468
-
1469
- @store.cache[:c_class_variables][@fn] = { 'cSomeExt' => 'SomeExt' }
1470
- @store.cache[:c_class_variables]['other.c'] = { 'cOtherExt' => 'OtherExt' }
1471
-
1472
- parser = util_parser
1473
-
1474
- map = parser.load_variable_map :c_class_variables
1475
-
1476
- expected = { 'cSomeExt' => some_ext }
1477
-
1478
- assert_equal expected, map
1479
-
1480
- assert_equal 'SomeExt', parser.known_classes['cSomeExt']
1481
- assert_nil parser.known_classes['cOtherExt']
1482
- end
1483
-
1484
- def test_load_variable_map_empty
1485
- parser = util_parser
1486
-
1487
- map = parser.load_variable_map :c_class_variables
1488
-
1489
- assert_empty map
1490
- end
1491
-
1492
- def test_load_variable_map_legacy
1493
- @store.cache[:c_class_variables] = nil
1494
-
1495
- parser = util_parser
1496
-
1497
- map = parser.load_variable_map :c_class_variables
1498
-
1499
- assert_empty map
1500
- end
1501
-
1502
- def test_load_variable_map_singleton
1503
- @top_level.add_class RDoc::NormalClass, 'SomeExt'
1504
- @top_level.add_class RDoc::NormalClass, 'OtherExt'
1505
-
1506
- @store.cache[:c_singleton_class_variables][@fn] =
1507
- { 'cSomeExt' => 'SomeExt' }
1508
- @store.cache[:c_singleton_class_variables]['other.c'] =
1509
- { 'cOtherExt' => 'OtherExt' }
1510
-
1511
- parser = util_parser
1512
-
1513
- map = parser.load_variable_map :c_singleton_class_variables
1514
-
1515
- expected = { 'cSomeExt' => 'SomeExt' }
1516
-
1517
- assert_equal expected, map
1518
-
1519
- assert_equal 'SomeExt', parser.known_classes['cSomeExt']
1520
- assert_nil parser.known_classes['cOtherExt']
1521
- end
1522
-
1523
- def test_load_variable_map_trim
1524
- a = @top_level.add_class RDoc::NormalClass, 'A'
1525
-
1526
- @store.cache[:c_class_variables][@fn] = {
1527
- 'cA' => 'A',
1528
- 'cB' => 'B',
1529
- }
1530
-
1531
- parser = util_parser
1532
-
1533
- map = parser.load_variable_map :c_class_variables
1534
-
1535
- expected = { 'cA' => a }
1536
-
1537
- assert_equal expected, map
1538
- end
1539
-
1540
- def test_define_method
1541
- content = <<-EOF
1542
- /*Method Comment! */
1543
- static VALUE
1544
- rb_io_s_read(argc, argv, io)
1545
- int argc;
1546
- VALUE *argv;
1547
- VALUE io;
1548
- {
1549
- }
1550
-
1551
- void
1552
- Init_IO(void) {
1553
- /*
1554
- * a comment for class Foo on rb_define_class
1555
- */
1556
- VALUE rb_cIO = rb_define_class("IO", rb_cObject);
1557
- rb_define_singleton_method(rb_cIO, "read", rb_io_s_read, -1);
1558
- }
1559
- EOF
1560
-
1561
- klass = util_get_class content, 'rb_cIO'
1562
- read_method = klass.method_list.first
1563
- assert_equal "read", read_method.name
1564
- assert_equal "Method Comment! ", read_method.comment.text
1565
- assert_equal "rb_io_s_read", read_method.c_function
1566
- assert read_method.singleton
1567
- end
1568
-
1569
- def test_define_method_with_prototype
1570
- content = <<-EOF
1571
- static VALUE rb_io_s_read(int, VALUE*, VALUE);
1572
-
1573
- /* Method Comment! */
1574
- static VALUE
1575
- rb_io_s_read(argc, argv, io)
1576
- int argc;
1577
- VALUE *argv;
1578
- VALUE io;
1579
- {
1580
- }
1581
-
1582
- void
1583
- Init_IO(void) {
1584
- /*
1585
- * a comment for class Foo on rb_define_class
1586
- */
1587
- VALUE rb_cIO = rb_define_class("IO", rb_cObject);
1588
- rb_define_singleton_method(rb_cIO, "read", rb_io_s_read, -1);
1589
- }
1590
- EOF
1591
-
1592
- klass = util_get_class content, 'rb_cIO'
1593
- read_method = klass.method_list.first
1594
- assert_equal "read", read_method.name
1595
- assert_equal "Method Comment! ", read_method.comment.text
1596
- assert_equal "rb_io_s_read", read_method.c_function
1597
- assert read_method.singleton
1598
- end
1599
-
1600
- def test_define_method_private
1601
- content = <<-EOF
1602
- /*Method Comment! */
1603
- static VALUE
1604
- rb_io_s_read(argc, argv, io)
1605
- int argc;
1606
- VALUE *argv;
1607
- VALUE io;
1608
- {
1609
- }
1610
-
1611
- void
1612
- Init_IO(void) {
1613
- /*
1614
- * a comment for class Foo on rb_define_class
1615
- */
1616
- VALUE rb_cIO = rb_define_class("IO", rb_cObject);
1617
- rb_define_private_method(rb_cIO, "read", rb_io_s_read, -1);
1618
- }
1619
- EOF
1620
-
1621
- klass = util_get_class content, 'rb_cIO'
1622
- read_method = klass.method_list.first
1623
- assert_equal 'IO#read', read_method.full_name
1624
- assert_equal :private, read_method.visibility
1625
- assert_equal "Method Comment! ", read_method.comment.text
1626
- end
1627
-
1628
- def test_define_method_private_singleton
1629
- content = <<-EOF
1630
- /*Method Comment! */
1631
- static VALUE
1632
- rb_io_s_read(argc, argv, io)
1633
- int argc;
1634
- VALUE *argv;
1635
- VALUE io;
1636
- {
1637
- }
1638
-
1639
- void
1640
- Init_IO(void) {
1641
- /*
1642
- * a comment for class Foo on rb_define_class
1643
- */
1644
- VALUE rb_cIO = rb_define_class("IO", rb_cObject);
1645
- VALUE rb_cIO_s = rb_singleton_class(rb_cIO);
1646
- rb_define_private_method(rb_cIO_s, "read", rb_io_s_read, -1);
1647
- }
1648
- EOF
1649
-
1650
- klass = util_get_class content, 'rb_cIO'
1651
- read_method = klass.method_list.first
1652
- assert_equal "read", read_method.name
1653
- assert_equal "Method Comment! ", read_method.comment.text
1654
- assert_equal :private, read_method.visibility
1655
- assert read_method.singleton
1656
- end
1657
-
1658
- def test_define_method_singleton
1659
- content = <<-EOF
1660
- /*Method Comment! */
1661
- static VALUE
1662
- rb_io_s_read(argc, argv, io)
1663
- int argc;
1664
- VALUE *argv;
1665
- VALUE io;
1666
- {
1667
- }
1668
-
1669
- void
1670
- Init_IO(void) {
1671
- /*
1672
- * a comment for class Foo on rb_define_class
1673
- */
1674
- VALUE rb_cIO = rb_define_class("IO", rb_cObject);
1675
- VALUE rb_cIO_s = rb_singleton_class(rb_cIO);
1676
- rb_define_method(rb_cIO_s, "read", rb_io_s_read, -1);
1677
- }
1678
- EOF
1679
-
1680
- klass = util_get_class content, 'rb_cIO'
1681
- read_method = klass.method_list.first
1682
- assert_equal "read", read_method.name
1683
- assert_equal "Method Comment! ", read_method.comment.text
1684
- assert read_method.singleton
1685
- end
1686
-
1687
- def test_rb_scan_args
1688
- parser = util_parser
1689
-
1690
- assert_equal '(p1)',
1691
- parser.rb_scan_args('rb_scan_args(a, b, "1",)')
1692
- assert_equal '(p1, p2)',
1693
- parser.rb_scan_args('rb_scan_args(a, b, "2",)')
1694
-
1695
- assert_equal '(p1 = v1)',
1696
- parser.rb_scan_args('rb_scan_args(a, b, "01",)')
1697
- assert_equal '(p1 = v1, p2 = v2)',
1698
- parser.rb_scan_args('rb_scan_args(a, b, "02",)')
1699
-
1700
- assert_equal '(p1, p2 = v2)',
1701
- parser.rb_scan_args('rb_scan_args(a, b, "11",)')
1702
-
1703
- assert_equal '(p1, *args)',
1704
- parser.rb_scan_args('rb_scan_args(a, b, "1*",)')
1705
- assert_equal '(p1, p2 = {})',
1706
- parser.rb_scan_args('rb_scan_args(a, b, "1:",)')
1707
- assert_equal '(p1, &block)',
1708
- parser.rb_scan_args('rb_scan_args(a, b, "1&",)')
1709
-
1710
- assert_equal '(p1, p2)',
1711
- parser.rb_scan_args('rb_scan_args(a, b, "101",)')
1712
-
1713
- assert_equal '(p1, p2 = v2, p3)',
1714
- parser.rb_scan_args('rb_scan_args(a, b, "111",)')
1715
-
1716
- assert_equal '(p1, *args, p3)',
1717
- parser.rb_scan_args('rb_scan_args(a, b, "1*1",)')
1718
-
1719
- assert_equal '(p1, p2 = v2, *args)',
1720
- parser.rb_scan_args('rb_scan_args(a, b, "11*",)')
1721
- assert_equal '(p1, p2 = v2, p3 = {})',
1722
- parser.rb_scan_args('rb_scan_args(a, b, "11:",)')
1723
- assert_equal '(p1, p2 = v2, &block)',
1724
- parser.rb_scan_args('rb_scan_args(a, b, "11&",)')
1725
-
1726
- assert_equal '(p1, p2 = v2, *args, p4, p5 = {}, &block)',
1727
- parser.rb_scan_args('rb_scan_args(a, b, "11*1:&",)')
1728
-
1729
- # The following aren't valid according to spec but are according to the
1730
- # implementation.
1731
- assert_equal '(*args)',
1732
- parser.rb_scan_args('rb_scan_args(a, b, "*",)')
1733
- assert_equal '(p1 = {})',
1734
- parser.rb_scan_args('rb_scan_args(a, b, ":",)')
1735
- assert_equal '(&block)',
1736
- parser.rb_scan_args('rb_scan_args(a, b, "&",)')
1737
-
1738
- assert_equal '(*args, p2 = {})',
1739
- parser.rb_scan_args('rb_scan_args(a, b, "*:",)')
1740
- assert_equal '(p1 = {}, &block)',
1741
- parser.rb_scan_args('rb_scan_args(a, b, ":&",)')
1742
- assert_equal '(*args, p2 = {}, &block)',
1743
- parser.rb_scan_args('rb_scan_args(a, b, "*:&",)')
1744
- end
1745
-
1746
- def test_scan
1747
- parser = util_parser <<-C
1748
- void Init(void) {
1749
- mM = rb_define_module("M");
1750
- cC = rb_define_class("C", rb_cObject);
1751
- sC = rb_singleton_class(cC);
1752
- }
1753
- C
1754
-
1755
- parser.scan
1756
-
1757
- expected = {
1758
- @fn => {
1759
- 'mM' => 'M',
1760
- 'cC' => 'C', }}
1761
- assert_equal expected, @store.c_class_variables
1762
-
1763
- expected = {
1764
- @fn => {
1765
- 'sC' => 'C' } }
1766
- assert_equal expected, @store.c_singleton_class_variables
1767
- end
1768
-
1769
- def test_scan_method_copy
1770
- parser = util_parser <<-C
1771
- /*
1772
- * call-seq:
1773
- * pathname.to_s -> string
1774
- * pathname.to_path -> string
1775
- *
1776
- * Return the path as a String.
1777
- *
1778
- * to_path is implemented so Pathname objects are usable with File.open, etc.
1779
- */
1780
- static VALUE
1781
- path_to_s(VALUE self) { }
1782
-
1783
- /*
1784
- * call-seq:
1785
- * str[index] -> new_str or nil
1786
- * str[start, length] -> new_str or nil
1787
- * str.slice(index) -> new_str or nil
1788
- * str.slice(start, length) -> new_str or nil
1789
- */
1790
- static VALUE
1791
- path_aref_m(int argc, VALUE *argv, VALUE str) { }
1792
-
1793
- /*
1794
- * call-seq:
1795
- * string <=> other_string -> -1, 0, +1 or nil
1796
- */
1797
- static VALUE
1798
- path_cmp_m(VALUE str1, VALUE str2) { }
1799
-
1800
- /*
1801
- * call-seq:
1802
- * str == obj -> true or false
1803
- * str === obj -> true or false
1804
- */
1805
- VALUE
1806
- rb_str_equal(VALUE str1, VALUE str2) { }
1807
-
1808
- Init_pathname()
1809
- {
1810
- rb_cPathname = rb_define_class("Pathname", rb_cObject);
1811
-
1812
- rb_define_method(rb_cPathname, "to_s", path_to_s, 0);
1813
- rb_define_method(rb_cPathname, "to_path", path_to_s, 0);
1814
- rb_define_method(rb_cPathname, "[]", path_aref_m, -1);
1815
- rb_define_method(rb_cPathname, "slice", path_aref_m, -1);
1816
- rb_define_method(rb_cPathname, "<=>", path_cmp_m, 1);
1817
- rb_define_method(rb_cPathname, "==", rb_str_equal), 2);
1818
- rb_define_method(rb_cPathname, "===", rb_str_equal), 2);
1819
- }
1820
- C
1821
-
1822
- parser.scan
1823
-
1824
- pathname = @store.classes_hash['Pathname']
1825
-
1826
- to_path = pathname.method_list.find { |m| m.name == 'to_path' }
1827
- assert_equal "pathname.to_path -> string", to_path.call_seq
1828
-
1829
- to_s = pathname.method_list.find { |m| m.name == 'to_s' }
1830
- assert_equal "pathname.to_s -> string", to_s.call_seq
1831
-
1832
- index_expected = <<-EXPECTED.chomp
1833
- str[index] -> new_str or nil
1834
- str[start, length] -> new_str or nil
1835
- EXPECTED
1836
-
1837
- index = pathname.method_list.find { |m| m.name == '[]' }
1838
- assert_equal index_expected, index.call_seq, '[]'
1839
-
1840
- slice_expected = <<-EXPECTED.chomp
1841
- str.slice(index) -> new_str or nil
1842
- str.slice(start, length) -> new_str or nil
1843
- EXPECTED
1844
-
1845
- slice = pathname.method_list.find { |m| m.name == 'slice' }
1846
- assert_equal slice_expected, slice.call_seq
1847
-
1848
- spaceship = pathname.method_list.find { |m| m.name == '<=>' }
1849
- assert_equal "string <=> other_string -> -1, 0, +1 or nil",
1850
- spaceship.call_seq
1851
-
1852
- equals2 = pathname.method_list.find { |m| m.name == '==' }
1853
- assert_match 'str == obj', equals2.call_seq
1854
-
1855
- equals3 = pathname.method_list.find { |m| m.name == '===' }
1856
- assert_match 'str === obj', equals3.call_seq
1857
- end
1858
-
1859
- def test_scan_order_dependent
1860
- parser = util_parser <<-C
1861
- void a(void) {
1862
- mA = rb_define_module("A");
1863
- }
1864
-
1865
- void b(void) {
1866
- cB = rb_define_class_under(mA, "B", rb_cObject);
1867
- }
1868
-
1869
- void c(void) {
1870
- mC = rb_define_module_under(cB, "C");
1871
- }
1872
-
1873
- void d(void) {
1874
- mD = rb_define_class_under(mC, "D");
1875
- }
1876
- C
1877
-
1878
- parser.scan
1879
-
1880
- assert_equal %w[A A::B A::B::C],
1881
- @store.all_classes_and_modules.map { |m| m.full_name }.sort
1882
- end
1883
-
1884
- def util_get_class content, name = nil
1885
- @parser = util_parser content
1886
- @parser.scan
1887
-
1888
- @parser.classes[name] if name
1889
- end
1890
-
1891
- def util_parser content = ''
1892
- RDoc::Parser::C.new @top_level, @fn, content, @options, @stats
1893
- end
1894
-
1895
- end
1896
-