rdoc 3.1 → 6.3.3
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.
- checksums.yaml +7 -0
- data/CONTRIBUTING.rdoc +220 -0
- data/CVE-2013-0256.rdoc +49 -0
- data/ExampleMarkdown.md +37 -0
- data/ExampleRDoc.rdoc +208 -0
- data/Gemfile +12 -0
- data/History.rdoc +1666 -0
- data/LEGAL.rdoc +50 -0
- data/LICENSE.rdoc +57 -0
- data/README.rdoc +129 -0
- data/RI.rdoc +57 -0
- data/Rakefile +84 -81
- data/TODO.rdoc +59 -0
- data/bin/console +7 -0
- data/bin/setup +6 -0
- data/{bin → exe}/rdoc +11 -2
- data/exe/ri +12 -0
- data/lib/rdoc/alias.rb +1 -2
- data/lib/rdoc/anon_class.rb +3 -2
- data/lib/rdoc/any_method.rb +234 -40
- data/lib/rdoc/attr.rb +79 -11
- data/lib/rdoc/class_module.rb +443 -71
- data/lib/rdoc/code_object.rb +216 -20
- data/lib/rdoc/code_objects.rb +4 -21
- data/lib/rdoc/comment.rb +250 -0
- data/lib/rdoc/constant.rb +110 -9
- data/lib/rdoc/context/section.rb +232 -0
- data/lib/rdoc/context.rb +392 -172
- data/lib/rdoc/cross_reference.rb +202 -0
- data/lib/rdoc/encoding.rb +83 -28
- data/lib/rdoc/erb_partial.rb +19 -0
- data/lib/rdoc/erbio.rb +8 -3
- data/lib/rdoc/extend.rb +10 -0
- data/lib/rdoc/generator/darkfish.rb +507 -84
- data/lib/rdoc/generator/json_index.rb +300 -0
- data/lib/rdoc/generator/markup.rb +27 -74
- data/lib/rdoc/generator/pot/message_extractor.rb +68 -0
- data/lib/rdoc/generator/pot/po.rb +84 -0
- data/lib/rdoc/generator/pot/po_entry.rb +141 -0
- data/lib/rdoc/generator/pot.rb +98 -0
- data/lib/rdoc/generator/ri.rb +8 -62
- data/lib/rdoc/generator/template/darkfish/_footer.rhtml +5 -0
- data/lib/rdoc/generator/template/darkfish/_head.rhtml +22 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_VCS_info.rhtml +19 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_classes.rhtml +9 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +15 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +9 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +15 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +15 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +12 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_navigation.rhtml +11 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +12 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml +11 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml +14 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +11 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +18 -0
- data/lib/rdoc/generator/template/darkfish/class.rhtml +172 -0
- data/lib/rdoc/generator/template/darkfish/css/fonts.css +167 -0
- data/lib/rdoc/generator/template/darkfish/css/rdoc.css +639 -0
- data/lib/rdoc/generator/template/darkfish/fonts/Lato-Light.ttf +0 -0
- data/lib/rdoc/generator/template/darkfish/fonts/Lato-LightItalic.ttf +0 -0
- data/lib/rdoc/generator/template/darkfish/fonts/Lato-Regular.ttf +0 -0
- data/lib/rdoc/generator/template/darkfish/fonts/Lato-RegularItalic.ttf +0 -0
- data/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Bold.ttf +0 -0
- data/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Regular.ttf +0 -0
- data/lib/rdoc/generator/template/darkfish/images/add.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/arrow_up.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/delete.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/tag_blue.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/transparent.png +0 -0
- data/lib/rdoc/generator/template/darkfish/index.rhtml +18 -60
- data/lib/rdoc/generator/template/darkfish/js/darkfish.js +51 -83
- data/lib/rdoc/generator/template/darkfish/js/search.js +110 -0
- data/lib/rdoc/generator/template/darkfish/page.rhtml +18 -0
- data/lib/rdoc/generator/template/darkfish/servlet_not_found.rhtml +18 -0
- data/lib/rdoc/generator/template/darkfish/servlet_root.rhtml +62 -0
- data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +58 -0
- data/lib/rdoc/generator/template/json_index/.document +1 -0
- data/lib/rdoc/generator/template/json_index/js/navigation.js +105 -0
- data/lib/rdoc/generator/template/json_index/js/searcher.js +229 -0
- data/lib/rdoc/generator.rb +24 -13
- data/lib/rdoc/ghost_method.rb +1 -2
- data/lib/rdoc/i18n/locale.rb +102 -0
- data/lib/rdoc/i18n/text.rb +126 -0
- data/lib/rdoc/i18n.rb +10 -0
- data/lib/rdoc/include.rb +5 -95
- data/lib/rdoc/known_classes.rb +5 -2
- data/lib/rdoc/markdown/entities.rb +2132 -0
- data/lib/rdoc/markdown/literals.kpeg +23 -0
- data/lib/rdoc/markdown/literals.rb +416 -0
- data/lib/rdoc/markdown.kpeg +1237 -0
- data/lib/rdoc/markdown.rb +16684 -0
- data/lib/rdoc/markup/attr_changer.rb +23 -0
- data/lib/rdoc/markup/attr_span.rb +36 -0
- data/lib/rdoc/markup/attribute_manager.rb +135 -62
- data/lib/rdoc/markup/attributes.rb +71 -0
- data/lib/rdoc/markup/blank_line.rb +1 -0
- data/lib/rdoc/markup/block_quote.rb +15 -0
- data/lib/rdoc/markup/document.rb +96 -9
- data/lib/rdoc/markup/formatter.rb +138 -25
- data/lib/rdoc/markup/hard_break.rb +32 -0
- data/lib/rdoc/markup/heading.rb +61 -2
- data/lib/rdoc/markup/include.rb +43 -0
- data/lib/rdoc/markup/indented_paragraph.rb +48 -0
- data/lib/rdoc/markup/list.rb +25 -4
- data/lib/rdoc/markup/list_item.rb +18 -4
- data/lib/rdoc/markup/paragraph.rb +15 -0
- data/lib/rdoc/markup/parser.rb +180 -88
- data/lib/rdoc/markup/pre_process.rb +183 -38
- data/lib/rdoc/markup/raw.rb +6 -5
- data/lib/rdoc/markup/regexp_handling.rb +41 -0
- data/lib/rdoc/markup/rule.rb +1 -0
- data/lib/rdoc/markup/table.rb +47 -0
- data/lib/rdoc/markup/to_ansi.rb +17 -7
- data/lib/rdoc/markup/to_bs.rb +5 -8
- data/lib/rdoc/markup/to_html.rb +238 -137
- data/lib/rdoc/markup/to_html_crossref.rb +125 -152
- data/lib/rdoc/markup/to_html_snippet.rb +285 -0
- data/lib/rdoc/markup/to_joined_paragraph.rb +47 -0
- data/lib/rdoc/markup/to_label.rb +75 -0
- data/lib/rdoc/markup/to_markdown.rb +192 -0
- data/lib/rdoc/markup/to_rdoc.rb +85 -15
- data/lib/rdoc/markup/to_table_of_contents.rb +89 -0
- data/lib/rdoc/markup/to_test.rb +2 -4
- data/lib/rdoc/markup/to_tt_only.rb +121 -0
- data/lib/rdoc/markup/verbatim.rb +39 -0
- data/lib/rdoc/markup.rb +388 -110
- data/lib/rdoc/meta_method.rb +1 -2
- data/lib/rdoc/method_attr.rb +87 -21
- data/lib/rdoc/mixin.rb +121 -0
- data/lib/rdoc/normal_class.rb +39 -10
- data/lib/rdoc/normal_module.rb +22 -7
- data/lib/rdoc/options.rb +613 -73
- data/lib/rdoc/parser/c.rb +621 -287
- data/lib/rdoc/parser/changelog.rb +335 -0
- data/lib/rdoc/parser/markdown.rb +24 -0
- data/lib/rdoc/parser/rd.rb +23 -0
- data/lib/rdoc/parser/ripper_state_lex.rb +590 -0
- data/lib/rdoc/parser/ruby.rb +1368 -762
- data/lib/rdoc/parser/ruby_tools.rb +42 -35
- data/lib/rdoc/parser/simple.rb +23 -11
- data/lib/rdoc/parser/text.rb +12 -0
- data/lib/rdoc/parser.rb +162 -89
- data/lib/rdoc/rd/block_parser.rb +1056 -0
- data/lib/rdoc/rd/block_parser.ry +639 -0
- data/lib/rdoc/rd/inline.rb +72 -0
- data/lib/rdoc/rd/inline_parser.rb +1208 -0
- data/lib/rdoc/rd/inline_parser.ry +593 -0
- data/lib/rdoc/rd.rb +100 -0
- data/lib/rdoc/rdoc.rb +208 -115
- data/lib/rdoc/require.rb +1 -2
- data/lib/rdoc/ri/driver.rb +734 -239
- data/lib/rdoc/ri/formatter.rb +1 -0
- data/lib/rdoc/ri/paths.rb +91 -48
- data/lib/rdoc/ri/store.rb +3 -261
- data/lib/rdoc/ri/task.rb +71 -0
- data/lib/rdoc/ri.rb +5 -2
- data/lib/rdoc/rubygems_hook.rb +246 -0
- data/lib/rdoc/servlet.rb +451 -0
- data/lib/rdoc/single_class.rb +14 -2
- data/lib/rdoc/stats/normal.rb +19 -12
- data/lib/rdoc/stats/quiet.rb +1 -0
- data/lib/rdoc/stats/verbose.rb +1 -0
- data/lib/rdoc/stats.rb +262 -104
- data/lib/rdoc/store.rb +979 -0
- data/lib/rdoc/task.rb +84 -44
- data/lib/rdoc/text.rb +117 -72
- data/lib/rdoc/token_stream.rb +73 -4
- data/lib/rdoc/tom_doc.rb +263 -0
- data/lib/rdoc/top_level.rb +111 -261
- data/lib/rdoc/version.rb +8 -0
- data/lib/rdoc.rb +127 -64
- data/man/ri.1 +247 -0
- data/rdoc.gemspec +249 -0
- metadata +171 -291
- data/.autotest +0 -16
- data/.document +0 -5
- data/History.txt +0 -594
- data/LICENSE.txt +0 -57
- data/Manifest.txt +0 -158
- data/README.txt +0 -45
- data/RI.txt +0 -58
- data/bin/ri +0 -5
- data/lib/rdoc/gauntlet.rb +0 -52
- data/lib/rdoc/generator/template/darkfish/classpage.rhtml +0 -296
- data/lib/rdoc/generator/template/darkfish/filepage.rhtml +0 -124
- data/lib/rdoc/generator/template/darkfish/js/jquery.js +0 -32
- data/lib/rdoc/generator/template/darkfish/js/quicksearch.js +0 -114
- data/lib/rdoc/generator/template/darkfish/js/thickbox-compressed.js +0 -10
- data/lib/rdoc/generator/template/darkfish/rdoc.css +0 -706
- data/lib/rdoc/markup/formatter_test_case.rb +0 -689
- data/lib/rdoc/markup/inline.rb +0 -137
- data/lib/rdoc/markup/text_formatter_test_case.rb +0 -116
- data/lib/rdoc/ruby_lex.rb +0 -1291
- data/lib/rdoc/ruby_token.rb +0 -416
- data/test/README +0 -1
- data/test/binary.dat +0 -0
- data/test/hidden.zip.txt +0 -1
- data/test/test.ja.rdoc +0 -10
- data/test/test.ja.txt +0 -8
- data/test/test.txt +0 -1
- data/test/test_attribute_manager.rb +0 -120
- data/test/test_rdoc_alias.rb +0 -13
- data/test/test_rdoc_any_method.rb +0 -126
- data/test/test_rdoc_attr.rb +0 -61
- data/test/test_rdoc_class_module.rb +0 -233
- data/test/test_rdoc_code_object.rb +0 -165
- data/test/test_rdoc_constant.rb +0 -15
- data/test/test_rdoc_context.rb +0 -370
- data/test/test_rdoc_encoding.rb +0 -166
- data/test/test_rdoc_generator_darkfish.rb +0 -119
- data/test/test_rdoc_generator_ri.rb +0 -76
- data/test/test_rdoc_include.rb +0 -96
- data/test/test_rdoc_markup.rb +0 -37
- data/test/test_rdoc_markup_attribute_manager.rb +0 -240
- data/test/test_rdoc_markup_document.rb +0 -51
- data/test/test_rdoc_markup_paragraph.rb +0 -9
- data/test/test_rdoc_markup_parser.rb +0 -1395
- data/test/test_rdoc_markup_pre_process.rb +0 -185
- data/test/test_rdoc_markup_raw.rb +0 -27
- data/test/test_rdoc_markup_to_ansi.rb +0 -328
- data/test/test_rdoc_markup_to_bs.rb +0 -341
- data/test/test_rdoc_markup_to_html.rb +0 -335
- data/test/test_rdoc_markup_to_html_crossref.rb +0 -169
- data/test/test_rdoc_markup_to_rdoc.rb +0 -327
- data/test/test_rdoc_method_attr.rb +0 -122
- data/test/test_rdoc_normal_class.rb +0 -17
- data/test/test_rdoc_normal_module.rb +0 -31
- data/test/test_rdoc_options.rb +0 -342
- data/test/test_rdoc_parser.rb +0 -83
- data/test/test_rdoc_parser_c.rb +0 -912
- data/test/test_rdoc_parser_ruby.rb +0 -1754
- data/test/test_rdoc_parser_simple.rb +0 -99
- data/test/test_rdoc_rdoc.rb +0 -164
- data/test/test_rdoc_require.rb +0 -25
- data/test/test_rdoc_ri_driver.rb +0 -846
- data/test/test_rdoc_ri_paths.rb +0 -43
- data/test/test_rdoc_ri_store.rb +0 -352
- data/test/test_rdoc_ruby_lex.rb +0 -23
- data/test/test_rdoc_stats.rb +0 -38
- data/test/test_rdoc_task.rb +0 -92
- data/test/test_rdoc_text.rb +0 -251
- data/test/test_rdoc_top_level.rb +0 -120
- data/test/xref_data.rb +0 -62
- data/test/xref_test_case.rb +0 -61
- data.tar.gz.sig +0 -3
- metadata.gz.sig +0 -0
@@ -1,1754 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
require 'stringio'
|
4
|
-
require 'tempfile'
|
5
|
-
require 'rubygems'
|
6
|
-
require 'minitest/autorun'
|
7
|
-
|
8
|
-
require 'rdoc/options'
|
9
|
-
require 'rdoc/parser/ruby'
|
10
|
-
require 'rdoc/stats'
|
11
|
-
|
12
|
-
class TestRDocParserRuby < MiniTest::Unit::TestCase
|
13
|
-
|
14
|
-
def setup
|
15
|
-
@tempfile = Tempfile.new self.class.name
|
16
|
-
@filename = @tempfile.path
|
17
|
-
|
18
|
-
# Some tests need two paths.
|
19
|
-
@tempfile2 = Tempfile.new self.class.name
|
20
|
-
@filename2 = @tempfile2.path
|
21
|
-
|
22
|
-
util_top_level
|
23
|
-
@options = RDoc::Options.new
|
24
|
-
@options.quiet = true
|
25
|
-
@options.option_parser = OptionParser.new
|
26
|
-
|
27
|
-
@stats = RDoc::Stats.new 0
|
28
|
-
end
|
29
|
-
|
30
|
-
def teardown
|
31
|
-
@tempfile.close
|
32
|
-
@tempfile2.close
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_extract_call_seq
|
36
|
-
m = RDoc::AnyMethod.new nil, 'm'
|
37
|
-
p = util_parser ''
|
38
|
-
|
39
|
-
comment = <<-COMMENT
|
40
|
-
# call-seq:
|
41
|
-
# bla => true or false
|
42
|
-
#
|
43
|
-
# moar comment
|
44
|
-
COMMENT
|
45
|
-
|
46
|
-
p.extract_call_seq comment, m
|
47
|
-
|
48
|
-
assert_equal "bla => true or false\n", m.call_seq
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_extract_call_seq_blank
|
52
|
-
m = RDoc::AnyMethod.new nil, 'm'
|
53
|
-
p = util_parser ''
|
54
|
-
|
55
|
-
comment = <<-COMMENT
|
56
|
-
# call-seq:
|
57
|
-
# bla => true or false
|
58
|
-
#
|
59
|
-
COMMENT
|
60
|
-
|
61
|
-
p.extract_call_seq comment, m
|
62
|
-
|
63
|
-
assert_equal "bla => true or false\n", m.call_seq
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_extract_call_seq_no_blank
|
67
|
-
m = RDoc::AnyMethod.new nil, 'm'
|
68
|
-
p = util_parser ''
|
69
|
-
|
70
|
-
comment = <<-COMMENT
|
71
|
-
# call-seq:
|
72
|
-
# bla => true or false
|
73
|
-
COMMENT
|
74
|
-
|
75
|
-
p.extract_call_seq comment, m
|
76
|
-
|
77
|
-
assert_equal "bla => true or false\n", m.call_seq
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_extract_call_seq_undent
|
81
|
-
m = RDoc::AnyMethod.new nil, 'm'
|
82
|
-
p = util_parser ''
|
83
|
-
|
84
|
-
comment = <<-COMMENT
|
85
|
-
# call-seq:
|
86
|
-
# bla => true or false
|
87
|
-
# moar comment
|
88
|
-
COMMENT
|
89
|
-
|
90
|
-
p.extract_call_seq comment, m
|
91
|
-
|
92
|
-
assert_equal "bla => true or false\nmoar comment\n", m.call_seq
|
93
|
-
end
|
94
|
-
|
95
|
-
def test_get_symbol_or_name
|
96
|
-
util_parser "* & | + 5 / 4"
|
97
|
-
|
98
|
-
assert_equal '*', @parser.get_symbol_or_name
|
99
|
-
|
100
|
-
@parser.skip_tkspace
|
101
|
-
|
102
|
-
assert_equal '&', @parser.get_symbol_or_name
|
103
|
-
|
104
|
-
@parser.skip_tkspace
|
105
|
-
|
106
|
-
assert_equal '|', @parser.get_symbol_or_name
|
107
|
-
|
108
|
-
@parser.skip_tkspace
|
109
|
-
|
110
|
-
assert_equal '+', @parser.get_symbol_or_name
|
111
|
-
|
112
|
-
@parser.skip_tkspace
|
113
|
-
@parser.get_tk
|
114
|
-
@parser.skip_tkspace
|
115
|
-
|
116
|
-
assert_equal '/', @parser.get_symbol_or_name
|
117
|
-
end
|
118
|
-
|
119
|
-
def test_look_for_directives_in_attr
|
120
|
-
util_parser ""
|
121
|
-
|
122
|
-
comment = "# :attr: my_attr\n"
|
123
|
-
|
124
|
-
@parser.look_for_directives_in @top_level, comment
|
125
|
-
|
126
|
-
assert_equal "# :attr: my_attr\n", comment
|
127
|
-
|
128
|
-
comment = "# :attr_reader: my_method\n"
|
129
|
-
|
130
|
-
@parser.look_for_directives_in @top_level, comment
|
131
|
-
|
132
|
-
assert_equal "# :attr_reader: my_method\n", comment
|
133
|
-
|
134
|
-
comment = "# :attr_writer: my_method\n"
|
135
|
-
|
136
|
-
@parser.look_for_directives_in @top_level, comment
|
137
|
-
|
138
|
-
assert_equal "# :attr_writer: my_method\n", comment
|
139
|
-
end
|
140
|
-
|
141
|
-
def test_remove_private_comments
|
142
|
-
util_parser ''
|
143
|
-
|
144
|
-
comment = <<-EOS
|
145
|
-
# This is text
|
146
|
-
#--
|
147
|
-
# this is private
|
148
|
-
EOS
|
149
|
-
|
150
|
-
expected = <<-EOS
|
151
|
-
# This is text
|
152
|
-
EOS
|
153
|
-
|
154
|
-
@parser.remove_private_comments(comment)
|
155
|
-
|
156
|
-
assert_equal expected, comment
|
157
|
-
end
|
158
|
-
|
159
|
-
def test_remove_private_comments_rule
|
160
|
-
util_parser ''
|
161
|
-
|
162
|
-
comment = <<-EOS
|
163
|
-
# This is text with a rule:
|
164
|
-
# ---
|
165
|
-
# this is also text
|
166
|
-
EOS
|
167
|
-
|
168
|
-
expected = comment.dup
|
169
|
-
|
170
|
-
@parser.remove_private_comments(comment)
|
171
|
-
|
172
|
-
assert_equal expected, comment
|
173
|
-
end
|
174
|
-
|
175
|
-
def test_remove_private_comments_toggle
|
176
|
-
util_parser ''
|
177
|
-
|
178
|
-
comment = <<-EOS
|
179
|
-
# This is text
|
180
|
-
#--
|
181
|
-
# this is private
|
182
|
-
#++
|
183
|
-
# This is text again.
|
184
|
-
EOS
|
185
|
-
|
186
|
-
expected = <<-EOS
|
187
|
-
# This is text
|
188
|
-
# This is text again.
|
189
|
-
EOS
|
190
|
-
|
191
|
-
@parser.remove_private_comments(comment)
|
192
|
-
|
193
|
-
assert_equal expected, comment
|
194
|
-
end
|
195
|
-
|
196
|
-
def test_look_for_directives_in_commented
|
197
|
-
util_parser ""
|
198
|
-
|
199
|
-
comment = "# how to make a section:\n# # :section: new section\n"
|
200
|
-
|
201
|
-
@parser.look_for_directives_in @top_level, comment
|
202
|
-
|
203
|
-
section = @top_level.current_section
|
204
|
-
assert_equal nil, section.title
|
205
|
-
assert_equal nil, section.comment
|
206
|
-
|
207
|
-
assert_equal "# how to make a section:\n# # :section: new section\n",
|
208
|
-
comment
|
209
|
-
end
|
210
|
-
|
211
|
-
def test_look_for_directives_in_enddoc
|
212
|
-
util_parser ""
|
213
|
-
|
214
|
-
@parser.look_for_directives_in @top_level, "# :enddoc:\n"
|
215
|
-
|
216
|
-
assert @top_level.done_documenting
|
217
|
-
end
|
218
|
-
|
219
|
-
def test_look_for_directives_in_main
|
220
|
-
util_parser ""
|
221
|
-
|
222
|
-
@parser.look_for_directives_in @top_level, "# :main: new main page\n"
|
223
|
-
|
224
|
-
assert_equal 'new main page', @options.main_page
|
225
|
-
end
|
226
|
-
|
227
|
-
def test_look_for_directives_in_method
|
228
|
-
util_parser ""
|
229
|
-
|
230
|
-
comment = "# :method: my_method\n"
|
231
|
-
|
232
|
-
@parser.look_for_directives_in @top_level, comment
|
233
|
-
|
234
|
-
assert_equal "# :method: my_method\n", comment
|
235
|
-
|
236
|
-
comment = "# :singleton-method: my_method\n"
|
237
|
-
|
238
|
-
@parser.look_for_directives_in @top_level, comment
|
239
|
-
|
240
|
-
assert_equal "# :singleton-method: my_method\n", comment
|
241
|
-
end
|
242
|
-
|
243
|
-
def test_look_for_directives_in_startdoc
|
244
|
-
util_parser ""
|
245
|
-
|
246
|
-
@top_level.stop_doc
|
247
|
-
assert !@top_level.document_self
|
248
|
-
assert !@top_level.document_children
|
249
|
-
|
250
|
-
@parser.look_for_directives_in @top_level, "# :startdoc:\n"
|
251
|
-
|
252
|
-
assert @top_level.document_self
|
253
|
-
assert @top_level.document_children
|
254
|
-
end
|
255
|
-
|
256
|
-
def test_look_for_directives_in_stopdoc
|
257
|
-
util_parser ""
|
258
|
-
|
259
|
-
assert @top_level.document_self
|
260
|
-
assert @top_level.document_children
|
261
|
-
|
262
|
-
@parser.look_for_directives_in @top_level, "# :stopdoc:\n"
|
263
|
-
|
264
|
-
assert !@top_level.document_self
|
265
|
-
assert !@top_level.document_children
|
266
|
-
end
|
267
|
-
|
268
|
-
def test_look_for_directives_in_section
|
269
|
-
util_parser ""
|
270
|
-
|
271
|
-
comment = "# :section: new section\n# woo stuff\n"
|
272
|
-
|
273
|
-
@parser.look_for_directives_in @top_level, comment
|
274
|
-
|
275
|
-
section = @top_level.current_section
|
276
|
-
assert_equal 'new section', section.title
|
277
|
-
assert_equal "# woo stuff\n", section.comment
|
278
|
-
|
279
|
-
assert_equal '', comment
|
280
|
-
end
|
281
|
-
|
282
|
-
def test_look_for_directives_in_title
|
283
|
-
util_parser ""
|
284
|
-
|
285
|
-
@parser.look_for_directives_in @top_level, "# :title: new title\n"
|
286
|
-
|
287
|
-
assert_equal 'new title', @options.title
|
288
|
-
end
|
289
|
-
|
290
|
-
def test_look_for_directives_in_unhandled
|
291
|
-
util_parser ""
|
292
|
-
|
293
|
-
@parser.look_for_directives_in @top_level, "# :unhandled: blah\n"
|
294
|
-
|
295
|
-
assert_equal 'blah', @top_level.metadata['unhandled']
|
296
|
-
end
|
297
|
-
|
298
|
-
def test_parse_alias
|
299
|
-
klass = RDoc::NormalClass.new 'Foo'
|
300
|
-
klass.parent = @top_level
|
301
|
-
|
302
|
-
util_parser "alias :next= :bar"
|
303
|
-
|
304
|
-
tk = @parser.get_tk
|
305
|
-
|
306
|
-
alas = @parser.parse_alias klass, RDoc::Parser::Ruby::NORMAL, tk, 'comment'
|
307
|
-
|
308
|
-
assert_equal 'bar', alas.old_name
|
309
|
-
assert_equal 'next=', alas.new_name
|
310
|
-
assert_equal klass, alas.parent
|
311
|
-
assert_equal 'comment', alas.comment
|
312
|
-
assert_equal @top_level, alas.file
|
313
|
-
end
|
314
|
-
|
315
|
-
def test_parse_alias_singleton
|
316
|
-
klass = RDoc::NormalClass.new 'Foo'
|
317
|
-
klass.parent = @top_level
|
318
|
-
|
319
|
-
util_parser "alias :next= :bar"
|
320
|
-
|
321
|
-
tk = @parser.get_tk
|
322
|
-
|
323
|
-
alas = @parser.parse_alias klass, RDoc::Parser::Ruby::SINGLE, tk, 'comment'
|
324
|
-
|
325
|
-
assert_equal 'bar', alas.old_name
|
326
|
-
assert_equal 'next=', alas.new_name
|
327
|
-
assert_equal klass, alas.parent
|
328
|
-
assert_equal 'comment', alas.comment
|
329
|
-
assert_equal @top_level, alas.file
|
330
|
-
assert alas.singleton
|
331
|
-
end
|
332
|
-
|
333
|
-
def test_parse_alias_meta
|
334
|
-
klass = RDoc::NormalClass.new 'Foo'
|
335
|
-
klass.parent = @top_level
|
336
|
-
|
337
|
-
util_parser "alias m.chop m"
|
338
|
-
|
339
|
-
tk = @parser.get_tk
|
340
|
-
|
341
|
-
alas = @parser.parse_alias klass, RDoc::Parser::Ruby::NORMAL, tk, 'comment'
|
342
|
-
|
343
|
-
assert_nil alas
|
344
|
-
end
|
345
|
-
|
346
|
-
def test_parse_attr
|
347
|
-
klass = RDoc::NormalClass.new 'Foo'
|
348
|
-
klass.parent = @top_level
|
349
|
-
|
350
|
-
comment = "##\n# my attr\n"
|
351
|
-
|
352
|
-
util_parser "attr :foo, :bar"
|
353
|
-
|
354
|
-
tk = @parser.get_tk
|
355
|
-
|
356
|
-
@parser.parse_attr klass, RDoc::Parser::Ruby::NORMAL, tk, comment
|
357
|
-
|
358
|
-
assert_equal 1, klass.attributes.length
|
359
|
-
|
360
|
-
foo = klass.attributes.first
|
361
|
-
assert_equal 'foo', foo.name
|
362
|
-
assert_equal 'my attr', foo.comment
|
363
|
-
assert_equal @top_level, foo.file
|
364
|
-
end
|
365
|
-
|
366
|
-
def test_parse_attr_accessor
|
367
|
-
klass = RDoc::NormalClass.new 'Foo'
|
368
|
-
klass.parent = @top_level
|
369
|
-
|
370
|
-
comment = "##\n# my attr\n"
|
371
|
-
|
372
|
-
util_parser "attr_accessor :foo, :bar"
|
373
|
-
|
374
|
-
tk = @parser.get_tk
|
375
|
-
|
376
|
-
@parser.parse_attr_accessor klass, RDoc::Parser::Ruby::NORMAL, tk, comment
|
377
|
-
|
378
|
-
assert_equal 2, klass.attributes.length
|
379
|
-
|
380
|
-
foo = klass.attributes.first
|
381
|
-
assert_equal 'foo', foo.name
|
382
|
-
assert_equal 'RW', foo.rw
|
383
|
-
assert_equal 'my attr', foo.comment
|
384
|
-
assert_equal @top_level, foo.file
|
385
|
-
|
386
|
-
bar = klass.attributes.last
|
387
|
-
assert_equal 'bar', bar.name
|
388
|
-
assert_equal 'RW', bar.rw
|
389
|
-
assert_equal 'my attr', bar.comment
|
390
|
-
end
|
391
|
-
|
392
|
-
def test_parse_attr_accessor_nodoc
|
393
|
-
klass = RDoc::NormalClass.new 'Foo'
|
394
|
-
klass.parent = @top_level
|
395
|
-
|
396
|
-
comment = "##\n# my attr\n"
|
397
|
-
|
398
|
-
util_parser "attr_accessor :foo, :bar # :nodoc:"
|
399
|
-
|
400
|
-
tk = @parser.get_tk
|
401
|
-
|
402
|
-
@parser.parse_attr_accessor klass, RDoc::Parser::Ruby::NORMAL, tk, comment
|
403
|
-
|
404
|
-
assert_equal 0, klass.attributes.length
|
405
|
-
end
|
406
|
-
|
407
|
-
def test_parse_attr_accessor_writer
|
408
|
-
klass = RDoc::NormalClass.new 'Foo'
|
409
|
-
klass.parent = @top_level
|
410
|
-
|
411
|
-
comment = "##\n# my attr\n"
|
412
|
-
|
413
|
-
util_parser "attr_writer :foo, :bar"
|
414
|
-
|
415
|
-
tk = @parser.get_tk
|
416
|
-
|
417
|
-
@parser.parse_attr_accessor klass, RDoc::Parser::Ruby::NORMAL, tk, comment
|
418
|
-
|
419
|
-
assert_equal 2, klass.attributes.length
|
420
|
-
|
421
|
-
foo = klass.attributes.first
|
422
|
-
assert_equal 'foo', foo.name
|
423
|
-
assert_equal 'W', foo.rw
|
424
|
-
assert_equal "my attr", foo.comment
|
425
|
-
assert_equal @top_level, foo.file
|
426
|
-
|
427
|
-
bar = klass.attributes.last
|
428
|
-
assert_equal 'bar', bar.name
|
429
|
-
assert_equal 'W', bar.rw
|
430
|
-
assert_equal "my attr", bar.comment
|
431
|
-
end
|
432
|
-
|
433
|
-
def test_parse_meta_attr
|
434
|
-
klass = RDoc::NormalClass.new 'Foo'
|
435
|
-
klass.parent = @top_level
|
436
|
-
|
437
|
-
comment = "##\n# :attr: \n# my method\n"
|
438
|
-
|
439
|
-
util_parser "add_my_method :foo, :bar"
|
440
|
-
|
441
|
-
tk = @parser.get_tk
|
442
|
-
|
443
|
-
@parser.parse_meta_attr klass, RDoc::Parser::Ruby::NORMAL, tk, comment
|
444
|
-
|
445
|
-
assert_equal 2, klass.attributes.length
|
446
|
-
foo = klass.attributes.first
|
447
|
-
assert_equal 'foo', foo.name
|
448
|
-
assert_equal 'RW', foo.rw
|
449
|
-
assert_equal "my method", foo.comment
|
450
|
-
assert_equal @top_level, foo.file
|
451
|
-
end
|
452
|
-
|
453
|
-
def test_parse_meta_attr_accessor
|
454
|
-
klass = RDoc::NormalClass.new 'Foo'
|
455
|
-
klass.parent = @top_level
|
456
|
-
|
457
|
-
comment = "##\n# :attr_accessor: \n# my method\n"
|
458
|
-
|
459
|
-
util_parser "add_my_method :foo, :bar"
|
460
|
-
|
461
|
-
tk = @parser.get_tk
|
462
|
-
|
463
|
-
@parser.parse_meta_attr klass, RDoc::Parser::Ruby::NORMAL, tk, comment
|
464
|
-
|
465
|
-
assert_equal 2, klass.attributes.length
|
466
|
-
foo = klass.attributes.first
|
467
|
-
assert_equal 'foo', foo.name
|
468
|
-
assert_equal 'RW', foo.rw
|
469
|
-
assert_equal 'my method', foo.comment
|
470
|
-
assert_equal @top_level, foo.file
|
471
|
-
end
|
472
|
-
|
473
|
-
def test_parse_meta_attr_named
|
474
|
-
klass = RDoc::NormalClass.new 'Foo'
|
475
|
-
klass.parent = @top_level
|
476
|
-
|
477
|
-
comment = "##\n# :attr: foo\n# my method\n"
|
478
|
-
|
479
|
-
util_parser "add_my_method :foo, :bar"
|
480
|
-
|
481
|
-
tk = @parser.get_tk
|
482
|
-
|
483
|
-
@parser.parse_meta_attr klass, RDoc::Parser::Ruby::NORMAL, tk, comment
|
484
|
-
|
485
|
-
assert_equal 1, klass.attributes.length
|
486
|
-
foo = klass.attributes.first
|
487
|
-
assert_equal 'foo', foo.name
|
488
|
-
assert_equal 'RW', foo.rw
|
489
|
-
assert_equal 'my method', foo.comment
|
490
|
-
assert_equal @top_level, foo.file
|
491
|
-
end
|
492
|
-
|
493
|
-
def test_parse_meta_attr_reader
|
494
|
-
klass = RDoc::NormalClass.new 'Foo'
|
495
|
-
klass.parent = @top_level
|
496
|
-
|
497
|
-
comment = "##\n# :attr_reader: \n# my method\n"
|
498
|
-
|
499
|
-
util_parser "add_my_method :foo, :bar"
|
500
|
-
|
501
|
-
tk = @parser.get_tk
|
502
|
-
|
503
|
-
@parser.parse_meta_attr klass, RDoc::Parser::Ruby::NORMAL, tk, comment
|
504
|
-
|
505
|
-
foo = klass.attributes.first
|
506
|
-
assert_equal 'foo', foo.name
|
507
|
-
assert_equal 'R', foo.rw
|
508
|
-
assert_equal 'my method', foo.comment
|
509
|
-
assert_equal @top_level, foo.file
|
510
|
-
end
|
511
|
-
|
512
|
-
def test_parse_meta_attr_writer
|
513
|
-
klass = RDoc::NormalClass.new 'Foo'
|
514
|
-
klass.parent = @top_level
|
515
|
-
|
516
|
-
comment = "##\n# :attr_writer: \n# my method\n"
|
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
|
-
foo = klass.attributes.first
|
525
|
-
assert_equal 'foo', foo.name
|
526
|
-
assert_equal 'W', foo.rw
|
527
|
-
assert_equal "my method", foo.comment
|
528
|
-
assert_equal @top_level, foo.file
|
529
|
-
end
|
530
|
-
|
531
|
-
def test_parse_class
|
532
|
-
comment = "##\n# my method\n"
|
533
|
-
|
534
|
-
util_parser "class Foo\nend"
|
535
|
-
|
536
|
-
tk = @parser.get_tk
|
537
|
-
|
538
|
-
@parser.parse_class @top_level, RDoc::Parser::Ruby::NORMAL, tk, comment
|
539
|
-
|
540
|
-
foo = @top_level.classes.first
|
541
|
-
assert_equal 'Foo', foo.full_name
|
542
|
-
assert_equal 'my method', foo.comment
|
543
|
-
end
|
544
|
-
|
545
|
-
def test_parse_class_ghost_method
|
546
|
-
util_parser <<-CLASS
|
547
|
-
class Foo
|
548
|
-
##
|
549
|
-
# :method: blah
|
550
|
-
# my method
|
551
|
-
end
|
552
|
-
CLASS
|
553
|
-
|
554
|
-
tk = @parser.get_tk
|
555
|
-
|
556
|
-
@parser.parse_class @top_level, RDoc::Parser::Ruby::NORMAL, tk, ''
|
557
|
-
|
558
|
-
foo = @top_level.classes.first
|
559
|
-
assert_equal 'Foo', foo.full_name
|
560
|
-
|
561
|
-
blah = foo.method_list.first
|
562
|
-
assert_equal 'Foo#blah', blah.full_name
|
563
|
-
assert_equal @top_level, blah.file
|
564
|
-
end
|
565
|
-
|
566
|
-
def test_parse_class_multi_ghost_methods
|
567
|
-
util_parser <<-'CLASS'
|
568
|
-
class Foo
|
569
|
-
##
|
570
|
-
# :method: one
|
571
|
-
#
|
572
|
-
# my method
|
573
|
-
|
574
|
-
##
|
575
|
-
# :method: two
|
576
|
-
#
|
577
|
-
# my method
|
578
|
-
|
579
|
-
[:one, :two].each do |t|
|
580
|
-
eval("def #{t}; \"#{t}\"; end")
|
581
|
-
end
|
582
|
-
end
|
583
|
-
CLASS
|
584
|
-
|
585
|
-
tk = @parser.get_tk
|
586
|
-
|
587
|
-
@parser.parse_class @top_level, RDoc::Parser::Ruby::NORMAL, tk, ''
|
588
|
-
|
589
|
-
foo = @top_level.classes.first
|
590
|
-
assert_equal 'Foo', foo.full_name
|
591
|
-
|
592
|
-
assert_equal 2, foo.method_list.length
|
593
|
-
end
|
594
|
-
|
595
|
-
def test_parse_class_nested_superclass
|
596
|
-
util_top_level
|
597
|
-
foo = @top_level.add_module RDoc::NormalModule, 'Foo'
|
598
|
-
|
599
|
-
util_parser "class Bar < Super\nend"
|
600
|
-
|
601
|
-
tk = @parser.get_tk
|
602
|
-
|
603
|
-
@parser.parse_class foo, RDoc::Parser::Ruby::NORMAL, tk, ''
|
604
|
-
|
605
|
-
bar = foo.classes.first
|
606
|
-
assert_equal 'Super', bar.superclass
|
607
|
-
end
|
608
|
-
|
609
|
-
def test_parse_module
|
610
|
-
comment = "##\n# my module\n"
|
611
|
-
|
612
|
-
util_parser "module Foo\nend"
|
613
|
-
|
614
|
-
tk = @parser.get_tk
|
615
|
-
|
616
|
-
@parser.parse_module @top_level, RDoc::Parser::Ruby::NORMAL, tk, comment
|
617
|
-
|
618
|
-
foo = @top_level.modules.first
|
619
|
-
assert_equal 'Foo', foo.full_name
|
620
|
-
assert_equal 'my module', foo.comment
|
621
|
-
end
|
622
|
-
|
623
|
-
def test_parse_class_colon3
|
624
|
-
code = <<-CODE
|
625
|
-
class A
|
626
|
-
class ::B
|
627
|
-
end
|
628
|
-
end
|
629
|
-
CODE
|
630
|
-
|
631
|
-
util_parser code
|
632
|
-
|
633
|
-
@parser.parse_class @top_level, false, @parser.get_tk, ''
|
634
|
-
|
635
|
-
assert_equal %w[A B], RDoc::TopLevel.classes.map { |c| c.full_name }
|
636
|
-
end
|
637
|
-
|
638
|
-
def test_parse_class_single
|
639
|
-
code = <<-CODE
|
640
|
-
class A
|
641
|
-
class << B
|
642
|
-
end
|
643
|
-
class << d = Object.new
|
644
|
-
def foo; end
|
645
|
-
alias bar foo
|
646
|
-
end
|
647
|
-
end
|
648
|
-
CODE
|
649
|
-
|
650
|
-
util_parser code
|
651
|
-
|
652
|
-
@parser.parse_class @top_level, false, @parser.get_tk, ''
|
653
|
-
|
654
|
-
assert_equal %w[A], RDoc::TopLevel.classes.map { |c| c.full_name }
|
655
|
-
assert_equal %w[A::B A::d], RDoc::TopLevel.modules.map { |c| c.full_name }
|
656
|
-
|
657
|
-
# make sure method/alias was not added to enclosing class/module
|
658
|
-
a = RDoc::TopLevel.all_classes_hash['A']
|
659
|
-
assert_empty a.method_list
|
660
|
-
|
661
|
-
# make sure non-constant-named module will be removed from documentation
|
662
|
-
d = RDoc::TopLevel.all_modules_hash['A::d']
|
663
|
-
assert d.remove_from_documentation?
|
664
|
-
|
665
|
-
end
|
666
|
-
|
667
|
-
# TODO this is really a Context#add_class test
|
668
|
-
def test_parse_class_object
|
669
|
-
code = <<-CODE
|
670
|
-
module A
|
671
|
-
class B
|
672
|
-
end
|
673
|
-
class Object
|
674
|
-
end
|
675
|
-
class C < Object
|
676
|
-
end
|
677
|
-
end
|
678
|
-
CODE
|
679
|
-
|
680
|
-
util_parser code
|
681
|
-
|
682
|
-
@parser.parse_module @top_level, false, @parser.get_tk, ''
|
683
|
-
|
684
|
-
assert_equal %w[A], RDoc::TopLevel.modules.map { |c| c.full_name }
|
685
|
-
assert_equal %w[A::B A::C A::Object], RDoc::TopLevel.classes.map { |c| c.full_name }.sort
|
686
|
-
assert_equal 'Object', RDoc::TopLevel.classes_hash['A::B'].superclass
|
687
|
-
assert_equal 'Object', RDoc::TopLevel.classes_hash['A::Object'].superclass
|
688
|
-
assert_equal 'A::Object', RDoc::TopLevel.classes_hash['A::C'].superclass.full_name
|
689
|
-
end
|
690
|
-
|
691
|
-
def test_parse_class_mistaken_for_module
|
692
|
-
# The code below is not strictly legal Ruby (Foo must have been defined
|
693
|
-
# before Foo::Bar is encountered), but RDoc might encounter Foo::Bar
|
694
|
-
# before Foo if they live in different files.
|
695
|
-
|
696
|
-
code = <<-RUBY
|
697
|
-
class Foo::Bar
|
698
|
-
end
|
699
|
-
|
700
|
-
module Foo::Baz
|
701
|
-
end
|
702
|
-
|
703
|
-
class Foo
|
704
|
-
end
|
705
|
-
RUBY
|
706
|
-
|
707
|
-
util_parser code
|
708
|
-
|
709
|
-
@parser.scan
|
710
|
-
|
711
|
-
assert_equal %w[Foo::Baz], RDoc::TopLevel.modules_hash.keys
|
712
|
-
assert_empty @top_level.modules
|
713
|
-
|
714
|
-
foo = @top_level.classes.first
|
715
|
-
assert_equal 'Foo', foo.full_name
|
716
|
-
|
717
|
-
bar = foo.classes.first
|
718
|
-
assert_equal 'Foo::Bar', bar.full_name
|
719
|
-
|
720
|
-
baz = foo.modules.first
|
721
|
-
assert_equal 'Foo::Baz', baz.full_name
|
722
|
-
end
|
723
|
-
|
724
|
-
def test_parse_class_definition_encountered_after_class_reference
|
725
|
-
# The code below is not strictly legal Ruby (Foo must have been defined
|
726
|
-
# before Foo.bar is encountered), but RDoc might encounter Foo.bar before
|
727
|
-
# Foo if they live in different files.
|
728
|
-
|
729
|
-
code = <<-EOF
|
730
|
-
def Foo.bar
|
731
|
-
end
|
732
|
-
|
733
|
-
class Foo < IO
|
734
|
-
end
|
735
|
-
EOF
|
736
|
-
|
737
|
-
util_parser code
|
738
|
-
|
739
|
-
@parser.scan
|
740
|
-
|
741
|
-
assert_empty RDoc::TopLevel.modules_hash
|
742
|
-
# HACK why does it fail?
|
743
|
-
#assert_empty @top_level.modules
|
744
|
-
|
745
|
-
foo = @top_level.classes.first
|
746
|
-
assert_equal 'Foo', foo.full_name
|
747
|
-
assert_equal 'IO', foo.superclass
|
748
|
-
|
749
|
-
bar = foo.method_list.first
|
750
|
-
assert_equal 'bar', bar.name
|
751
|
-
end
|
752
|
-
|
753
|
-
def test_parse_module_relative_to_top_level_namespace
|
754
|
-
comment = <<-EOF
|
755
|
-
#
|
756
|
-
# Weirdly named module
|
757
|
-
#
|
758
|
-
EOF
|
759
|
-
|
760
|
-
code = comment + <<-EOF
|
761
|
-
module ::Foo
|
762
|
-
class Helper
|
763
|
-
end
|
764
|
-
end
|
765
|
-
EOF
|
766
|
-
|
767
|
-
util_parser code
|
768
|
-
@parser.scan()
|
769
|
-
|
770
|
-
foo = @top_level.modules.first
|
771
|
-
assert_equal 'Foo', foo.full_name
|
772
|
-
assert_equal 'Weirdly named module', foo.comment
|
773
|
-
|
774
|
-
helper = foo.classes.first
|
775
|
-
assert_equal 'Foo::Helper', helper.full_name
|
776
|
-
end
|
777
|
-
|
778
|
-
def test_parse_comment_attr
|
779
|
-
klass = RDoc::NormalClass.new 'Foo'
|
780
|
-
klass.parent = @top_level
|
781
|
-
|
782
|
-
comment = "##\n# :attr: foo\n# my attr\n"
|
783
|
-
|
784
|
-
util_parser "\n"
|
785
|
-
|
786
|
-
tk = @parser.get_tk
|
787
|
-
|
788
|
-
@parser.parse_comment klass, tk, comment
|
789
|
-
|
790
|
-
foo = klass.attributes.first
|
791
|
-
assert_equal 'foo', foo.name
|
792
|
-
assert_equal 'RW', foo.rw
|
793
|
-
assert_equal 'my attr', foo.comment
|
794
|
-
assert_equal @top_level, foo.file
|
795
|
-
|
796
|
-
assert_equal nil, foo.viewer
|
797
|
-
assert_equal true, foo.document_children
|
798
|
-
assert_equal true, foo.document_self
|
799
|
-
assert_equal false, foo.done_documenting
|
800
|
-
assert_equal false, foo.force_documentation
|
801
|
-
assert_equal klass, foo.parent
|
802
|
-
assert_equal :public, foo.visibility
|
803
|
-
assert_equal "\n", foo.text
|
804
|
-
|
805
|
-
assert_equal klass.current_section, foo.section
|
806
|
-
end
|
807
|
-
|
808
|
-
def test_parse_comment_method
|
809
|
-
klass = RDoc::NormalClass.new 'Foo'
|
810
|
-
klass.parent = @top_level
|
811
|
-
|
812
|
-
comment = "##\n# :method: foo\n# my method\n"
|
813
|
-
|
814
|
-
util_parser "\n"
|
815
|
-
|
816
|
-
tk = @parser.get_tk
|
817
|
-
|
818
|
-
@parser.parse_comment klass, tk, comment
|
819
|
-
|
820
|
-
foo = klass.method_list.first
|
821
|
-
assert_equal 'foo', foo.name
|
822
|
-
assert_equal 'my method', foo.comment
|
823
|
-
assert_equal @top_level, foo.file
|
824
|
-
|
825
|
-
assert_equal [], foo.aliases
|
826
|
-
assert_equal nil, foo.block_params
|
827
|
-
assert_equal nil, foo.call_seq
|
828
|
-
assert_equal nil, foo.is_alias_for
|
829
|
-
assert_equal nil, foo.viewer
|
830
|
-
assert_equal true, foo.document_children
|
831
|
-
assert_equal true, foo.document_self
|
832
|
-
assert_equal '', foo.params
|
833
|
-
assert_equal false, foo.done_documenting
|
834
|
-
assert_equal false, foo.dont_rename_initialize
|
835
|
-
assert_equal false, foo.force_documentation
|
836
|
-
assert_equal klass, foo.parent
|
837
|
-
assert_equal false, foo.singleton
|
838
|
-
assert_equal :public, foo.visibility
|
839
|
-
assert_equal "\n", foo.text
|
840
|
-
assert_equal klass.current_section, foo.section
|
841
|
-
|
842
|
-
stream = [
|
843
|
-
tk(:COMMENT, 1, 1, nil, "# File #{@top_level.absolute_name}, line 1"),
|
844
|
-
RDoc::Parser::Ruby::NEWLINE_TOKEN,
|
845
|
-
tk(:SPACE, 1, 1, nil, ''),
|
846
|
-
]
|
847
|
-
|
848
|
-
assert_equal stream, foo.token_stream
|
849
|
-
end
|
850
|
-
|
851
|
-
def test_parse_constant_attrasgn
|
852
|
-
util_top_level
|
853
|
-
|
854
|
-
klass = @top_level.add_class RDoc::NormalClass, 'Foo'
|
855
|
-
|
856
|
-
util_parser "A[k] = v"
|
857
|
-
|
858
|
-
tk = @parser.get_tk
|
859
|
-
|
860
|
-
@parser.parse_constant klass, tk, ''
|
861
|
-
|
862
|
-
assert klass.constants.empty?
|
863
|
-
end
|
864
|
-
|
865
|
-
def test_parse_constant_alias
|
866
|
-
util_top_level
|
867
|
-
klass = @top_level.add_class RDoc::NormalClass, 'Foo'
|
868
|
-
cB = klass.add_class RDoc::NormalClass, 'B'
|
869
|
-
|
870
|
-
util_parser "A = B"
|
871
|
-
|
872
|
-
tk = @parser.get_tk
|
873
|
-
|
874
|
-
@parser.parse_constant klass, tk, ''
|
875
|
-
|
876
|
-
assert_equal cB, klass.find_module_named('A')
|
877
|
-
end
|
878
|
-
|
879
|
-
def test_parse_constant_alias_same_name
|
880
|
-
foo = @top_level.add_class RDoc::NormalClass, 'Foo'
|
881
|
-
top_bar = @top_level.add_class RDoc::NormalClass, 'Bar'
|
882
|
-
bar = foo.add_class RDoc::NormalClass, 'Bar'
|
883
|
-
|
884
|
-
assert RDoc::TopLevel.find_class_or_module('::Bar')
|
885
|
-
|
886
|
-
util_parser "A = ::Bar"
|
887
|
-
|
888
|
-
tk = @parser.get_tk
|
889
|
-
|
890
|
-
@parser.parse_constant foo, tk, ''
|
891
|
-
|
892
|
-
assert_equal top_bar, bar.find_module_named('A')
|
893
|
-
end
|
894
|
-
|
895
|
-
def test_parse_meta_method
|
896
|
-
klass = RDoc::NormalClass.new 'Foo'
|
897
|
-
klass.parent = @top_level
|
898
|
-
|
899
|
-
comment = "##\n# my method\n"
|
900
|
-
|
901
|
-
util_parser "add_my_method :foo, :bar\nadd_my_method :baz"
|
902
|
-
|
903
|
-
tk = @parser.get_tk
|
904
|
-
|
905
|
-
@parser.parse_meta_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment
|
906
|
-
|
907
|
-
foo = klass.method_list.first
|
908
|
-
assert_equal 'foo', foo.name
|
909
|
-
assert_equal 'my method', foo.comment
|
910
|
-
assert_equal @top_level, foo.file
|
911
|
-
|
912
|
-
assert_equal [], foo.aliases
|
913
|
-
assert_equal nil, foo.block_params
|
914
|
-
assert_equal nil, foo.call_seq
|
915
|
-
assert_equal true, foo.document_children
|
916
|
-
assert_equal true, foo.document_self
|
917
|
-
assert_equal false, foo.done_documenting
|
918
|
-
assert_equal false, foo.dont_rename_initialize
|
919
|
-
assert_equal false, foo.force_documentation
|
920
|
-
assert_equal nil, foo.is_alias_for
|
921
|
-
assert_equal '', foo.params
|
922
|
-
assert_equal klass, foo.parent
|
923
|
-
assert_equal false, foo.singleton
|
924
|
-
assert_equal 'add_my_method :foo', foo.text
|
925
|
-
assert_equal nil, foo.viewer
|
926
|
-
assert_equal :public, foo.visibility
|
927
|
-
assert_equal klass.current_section, foo.section
|
928
|
-
|
929
|
-
stream = [
|
930
|
-
tk(:COMMENT, 1, 1, nil, "# File #{@top_level.absolute_name}, line 1"),
|
931
|
-
RDoc::Parser::Ruby::NEWLINE_TOKEN,
|
932
|
-
tk(:SPACE, 1, 1, nil, ''),
|
933
|
-
tk(:IDENTIFIER, 1, 0, 'add_my_method', 'add_my_method'),
|
934
|
-
tk(:SPACE, 1, 13, nil, ' '),
|
935
|
-
tk(:SYMBOL, 1, 14, nil, ':foo'),
|
936
|
-
tk(:COMMA, 1, 18, nil, ','),
|
937
|
-
tk(:SPACE, 1, 19, nil, ' '),
|
938
|
-
tk(:SYMBOL, 1, 20, nil, ':bar'),
|
939
|
-
tk(:NL, 1, 24, nil, "\n"),
|
940
|
-
]
|
941
|
-
|
942
|
-
assert_equal stream, foo.token_stream
|
943
|
-
end
|
944
|
-
|
945
|
-
def test_parse_meta_method_name
|
946
|
-
klass = RDoc::NormalClass.new 'Foo'
|
947
|
-
klass.parent = @top_level
|
948
|
-
|
949
|
-
comment = "##\n# :method: woo_hoo!\n# my method\n"
|
950
|
-
|
951
|
-
util_parser "add_my_method :foo, :bar\nadd_my_method :baz"
|
952
|
-
|
953
|
-
tk = @parser.get_tk
|
954
|
-
|
955
|
-
@parser.parse_meta_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment
|
956
|
-
|
957
|
-
foo = klass.method_list.first
|
958
|
-
assert_equal 'woo_hoo!', foo.name
|
959
|
-
assert_equal 'my method', foo.comment
|
960
|
-
assert_equal @top_level, foo.file
|
961
|
-
end
|
962
|
-
|
963
|
-
def test_parse_meta_method_singleton
|
964
|
-
klass = RDoc::NormalClass.new 'Foo'
|
965
|
-
klass.parent = @top_level
|
966
|
-
|
967
|
-
comment = "##\n# :singleton-method:\n# my method\n"
|
968
|
-
|
969
|
-
util_parser "add_my_method :foo, :bar\nadd_my_method :baz"
|
970
|
-
|
971
|
-
tk = @parser.get_tk
|
972
|
-
|
973
|
-
@parser.parse_meta_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment
|
974
|
-
|
975
|
-
foo = klass.method_list.first
|
976
|
-
assert_equal 'foo', foo.name
|
977
|
-
assert_equal true, foo.singleton, 'singleton method'
|
978
|
-
assert_equal 'my method', foo.comment
|
979
|
-
assert_equal @top_level, foo.file
|
980
|
-
end
|
981
|
-
|
982
|
-
def test_parse_meta_method_singleton_name
|
983
|
-
klass = RDoc::NormalClass.new 'Foo'
|
984
|
-
klass.parent = @top_level
|
985
|
-
|
986
|
-
comment = "##\n# :singleton-method: woo_hoo!\n# my method\n"
|
987
|
-
|
988
|
-
util_parser "add_my_method :foo, :bar\nadd_my_method :baz"
|
989
|
-
|
990
|
-
tk = @parser.get_tk
|
991
|
-
|
992
|
-
@parser.parse_meta_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment
|
993
|
-
|
994
|
-
foo = klass.method_list.first
|
995
|
-
assert_equal 'woo_hoo!', foo.name
|
996
|
-
assert_equal true, foo.singleton, 'singleton method'
|
997
|
-
assert_equal 'my method', foo.comment
|
998
|
-
assert_equal @top_level, foo.file
|
999
|
-
end
|
1000
|
-
|
1001
|
-
def test_parse_meta_method_string_name
|
1002
|
-
klass = RDoc::NormalClass.new 'Foo'
|
1003
|
-
comment = "##\n# my method\n"
|
1004
|
-
|
1005
|
-
util_parser "add_my_method 'foo'"
|
1006
|
-
|
1007
|
-
tk = @parser.get_tk
|
1008
|
-
|
1009
|
-
@parser.parse_meta_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment
|
1010
|
-
|
1011
|
-
foo = klass.method_list.first
|
1012
|
-
assert_equal 'foo', foo.name
|
1013
|
-
assert_equal 'my method', foo.comment
|
1014
|
-
assert_equal @top_level, foo.file
|
1015
|
-
end
|
1016
|
-
|
1017
|
-
def test_parse_meta_method_unknown
|
1018
|
-
klass = RDoc::NormalClass.new 'Foo'
|
1019
|
-
comment = "##\n# my method\n"
|
1020
|
-
|
1021
|
-
util_parser "add_my_method ('foo')"
|
1022
|
-
|
1023
|
-
tk = @parser.get_tk
|
1024
|
-
|
1025
|
-
@parser.parse_meta_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment
|
1026
|
-
|
1027
|
-
foo = klass.method_list.first
|
1028
|
-
assert_equal 'unknown', foo.name
|
1029
|
-
assert_equal 'my method', foo.comment
|
1030
|
-
assert_equal @top_level, foo.file
|
1031
|
-
end
|
1032
|
-
|
1033
|
-
def test_parse_method
|
1034
|
-
klass = RDoc::NormalClass.new 'Foo'
|
1035
|
-
klass.parent = @top_level
|
1036
|
-
|
1037
|
-
comment = "##\n# my method\n"
|
1038
|
-
|
1039
|
-
util_parser "def foo() :bar end"
|
1040
|
-
|
1041
|
-
tk = @parser.get_tk
|
1042
|
-
|
1043
|
-
@parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment
|
1044
|
-
|
1045
|
-
foo = klass.method_list.first
|
1046
|
-
assert_equal 'foo', foo.name
|
1047
|
-
assert_equal 'my method', foo.comment
|
1048
|
-
assert_equal @top_level, foo.file
|
1049
|
-
|
1050
|
-
assert_equal [], foo.aliases
|
1051
|
-
assert_equal nil, foo.block_params
|
1052
|
-
assert_equal nil, foo.call_seq
|
1053
|
-
assert_equal nil, foo.is_alias_for
|
1054
|
-
assert_equal nil, foo.viewer
|
1055
|
-
assert_equal true, foo.document_children
|
1056
|
-
assert_equal true, foo.document_self
|
1057
|
-
assert_equal '()', foo.params
|
1058
|
-
assert_equal false, foo.done_documenting
|
1059
|
-
assert_equal false, foo.dont_rename_initialize
|
1060
|
-
assert_equal false, foo.force_documentation
|
1061
|
-
assert_equal klass, foo.parent
|
1062
|
-
assert_equal false, foo.singleton
|
1063
|
-
assert_equal :public, foo.visibility
|
1064
|
-
assert_equal 'def foo', foo.text
|
1065
|
-
assert_equal klass.current_section, foo.section
|
1066
|
-
|
1067
|
-
stream = [
|
1068
|
-
tk(:COMMENT, 1, 1, nil, "# File #{@top_level.absolute_name}, line 1"),
|
1069
|
-
RDoc::Parser::Ruby::NEWLINE_TOKEN,
|
1070
|
-
tk(:SPACE, 1, 1, nil, ''),
|
1071
|
-
tk(:DEF, 1, 0, 'def', 'def'),
|
1072
|
-
tk(:SPACE, 1, 3, nil, ' '),
|
1073
|
-
tk(:IDENTIFIER, 1, 4, 'foo', 'foo'),
|
1074
|
-
tk(:LPAREN, 1, 7, nil, '('),
|
1075
|
-
tk(:RPAREN, 1, 8, nil, ')'),
|
1076
|
-
tk(:SPACE, 1, 9, nil, ' '),
|
1077
|
-
tk(:COLON, 1, 10, nil, ':'),
|
1078
|
-
tk(:IDENTIFIER, 1, 11, 'bar', 'bar'),
|
1079
|
-
tk(:SPACE, 1, 14, nil, ' '),
|
1080
|
-
tk(:END, 1, 15, 'end', 'end'),
|
1081
|
-
]
|
1082
|
-
|
1083
|
-
assert_equal stream, foo.token_stream
|
1084
|
-
end
|
1085
|
-
|
1086
|
-
def test_parse_method_alias
|
1087
|
-
klass = RDoc::NormalClass.new 'Foo'
|
1088
|
-
klass.parent = @top_level
|
1089
|
-
|
1090
|
-
util_parser "def m() alias a b; end"
|
1091
|
-
|
1092
|
-
tk = @parser.get_tk
|
1093
|
-
|
1094
|
-
@parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, ''
|
1095
|
-
|
1096
|
-
assert klass.aliases.empty?
|
1097
|
-
end
|
1098
|
-
|
1099
|
-
def test_parse_method_false
|
1100
|
-
util_parser "def false.foo() :bar end"
|
1101
|
-
|
1102
|
-
tk = @parser.get_tk
|
1103
|
-
|
1104
|
-
@parser.parse_method @top_level, RDoc::Parser::Ruby::NORMAL, tk, ''
|
1105
|
-
|
1106
|
-
klass = RDoc::TopLevel.find_class_named 'FalseClass'
|
1107
|
-
|
1108
|
-
foo = klass.method_list.first
|
1109
|
-
assert_equal 'foo', foo.name
|
1110
|
-
end
|
1111
|
-
|
1112
|
-
def test_parse_method_funky
|
1113
|
-
klass = RDoc::NormalClass.new 'Foo'
|
1114
|
-
klass.parent = @top_level
|
1115
|
-
|
1116
|
-
util_parser "def (blah).foo() :bar end"
|
1117
|
-
|
1118
|
-
tk = @parser.get_tk
|
1119
|
-
|
1120
|
-
@parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, ''
|
1121
|
-
|
1122
|
-
assert klass.method_list.empty?
|
1123
|
-
end
|
1124
|
-
|
1125
|
-
def test_parse_method_gvar
|
1126
|
-
util_parser "def $stdout.foo() :bar end"
|
1127
|
-
|
1128
|
-
tk = @parser.get_tk
|
1129
|
-
|
1130
|
-
@parser.parse_method @top_level, RDoc::Parser::Ruby::NORMAL, tk, ''
|
1131
|
-
|
1132
|
-
assert @top_level.method_list.empty?
|
1133
|
-
end
|
1134
|
-
|
1135
|
-
def test_parse_method_internal_gvar
|
1136
|
-
klass = RDoc::NormalClass.new 'Foo'
|
1137
|
-
klass.parent = @top_level
|
1138
|
-
|
1139
|
-
util_parser "def foo() def $blah.bar() end end"
|
1140
|
-
|
1141
|
-
tk = @parser.get_tk
|
1142
|
-
|
1143
|
-
@parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, ''
|
1144
|
-
|
1145
|
-
assert_equal 1, klass.method_list.length
|
1146
|
-
end
|
1147
|
-
|
1148
|
-
def test_parse_method_internal_ivar
|
1149
|
-
klass = RDoc::NormalClass.new 'Foo'
|
1150
|
-
klass.parent = @top_level
|
1151
|
-
|
1152
|
-
util_parser "def foo() def @blah.bar() end end"
|
1153
|
-
|
1154
|
-
tk = @parser.get_tk
|
1155
|
-
|
1156
|
-
@parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, ''
|
1157
|
-
|
1158
|
-
assert_equal 1, klass.method_list.length
|
1159
|
-
end
|
1160
|
-
|
1161
|
-
def test_parse_method_internal_lvar
|
1162
|
-
klass = RDoc::NormalClass.new 'Foo'
|
1163
|
-
klass.parent = @top_level
|
1164
|
-
|
1165
|
-
util_parser "def foo() def blah.bar() end end"
|
1166
|
-
|
1167
|
-
tk = @parser.get_tk
|
1168
|
-
|
1169
|
-
@parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, ''
|
1170
|
-
|
1171
|
-
assert_equal 1, klass.method_list.length
|
1172
|
-
end
|
1173
|
-
|
1174
|
-
def test_parse_method_nil
|
1175
|
-
util_parser "def nil.foo() :bar end"
|
1176
|
-
|
1177
|
-
tk = @parser.get_tk
|
1178
|
-
|
1179
|
-
@parser.parse_method @top_level, RDoc::Parser::Ruby::NORMAL, tk, ''
|
1180
|
-
|
1181
|
-
klass = RDoc::TopLevel.find_class_named 'NilClass'
|
1182
|
-
|
1183
|
-
foo = klass.method_list.first
|
1184
|
-
assert_equal 'foo', foo.name
|
1185
|
-
end
|
1186
|
-
|
1187
|
-
def test_parse_method_no_parens
|
1188
|
-
klass = RDoc::NormalClass.new 'Foo'
|
1189
|
-
klass.parent = @top_level
|
1190
|
-
|
1191
|
-
util_parser "def foo arg1, arg2 = {}\nend"
|
1192
|
-
|
1193
|
-
tk = @parser.get_tk
|
1194
|
-
|
1195
|
-
@parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, ''
|
1196
|
-
|
1197
|
-
foo = klass.method_list.first
|
1198
|
-
assert_equal '(arg1, arg2 = {})', foo.params
|
1199
|
-
assert_equal @top_level, foo.file
|
1200
|
-
end
|
1201
|
-
|
1202
|
-
def test_parse_method_parameters_comment
|
1203
|
-
klass = RDoc::NormalClass.new 'Foo'
|
1204
|
-
klass.parent = @top_level
|
1205
|
-
|
1206
|
-
util_parser "def foo arg1, arg2 # some useful comment\nend"
|
1207
|
-
|
1208
|
-
tk = @parser.get_tk
|
1209
|
-
|
1210
|
-
@parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, ''
|
1211
|
-
|
1212
|
-
foo = klass.method_list.first
|
1213
|
-
assert_equal '(arg1, arg2)', foo.params
|
1214
|
-
end
|
1215
|
-
|
1216
|
-
def test_parse_method_parameters_comment_continue
|
1217
|
-
klass = RDoc::NormalClass.new 'Foo'
|
1218
|
-
klass.parent = @top_level
|
1219
|
-
|
1220
|
-
util_parser "def foo arg1, arg2, # some useful comment\narg3\nend"
|
1221
|
-
|
1222
|
-
tk = @parser.get_tk
|
1223
|
-
|
1224
|
-
@parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, ''
|
1225
|
-
|
1226
|
-
foo = klass.method_list.first
|
1227
|
-
assert_equal '(arg1, arg2, arg3)', foo.params
|
1228
|
-
end
|
1229
|
-
|
1230
|
-
def test_parse_method_toplevel
|
1231
|
-
klass = @top_level
|
1232
|
-
|
1233
|
-
util_parser "def foo arg1, arg2\nend"
|
1234
|
-
|
1235
|
-
tk = @parser.get_tk
|
1236
|
-
|
1237
|
-
@parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, ''
|
1238
|
-
|
1239
|
-
object = RDoc::TopLevel.find_class_named 'Object'
|
1240
|
-
|
1241
|
-
foo = object.method_list.first
|
1242
|
-
assert_equal 'Object#foo', foo.full_name
|
1243
|
-
assert_equal @top_level, foo.file
|
1244
|
-
end
|
1245
|
-
|
1246
|
-
def test_parse_method_toplevel_class
|
1247
|
-
klass = @top_level
|
1248
|
-
|
1249
|
-
util_parser "def Object.foo arg1, arg2\nend"
|
1250
|
-
|
1251
|
-
tk = @parser.get_tk
|
1252
|
-
|
1253
|
-
@parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, ''
|
1254
|
-
|
1255
|
-
object = RDoc::TopLevel.find_class_named 'Object'
|
1256
|
-
|
1257
|
-
foo = object.method_list.first
|
1258
|
-
assert_equal 'Object::foo', foo.full_name
|
1259
|
-
end
|
1260
|
-
|
1261
|
-
def test_parse_method_true
|
1262
|
-
util_parser "def true.foo() :bar end"
|
1263
|
-
|
1264
|
-
tk = @parser.get_tk
|
1265
|
-
|
1266
|
-
@parser.parse_method @top_level, RDoc::Parser::Ruby::NORMAL, tk, ''
|
1267
|
-
|
1268
|
-
klass = RDoc::TopLevel.find_class_named 'TrueClass'
|
1269
|
-
|
1270
|
-
foo = klass.method_list.first
|
1271
|
-
assert_equal 'foo', foo.name
|
1272
|
-
end
|
1273
|
-
|
1274
|
-
def test_parse_method_utf8
|
1275
|
-
klass = RDoc::NormalClass.new 'Foo'
|
1276
|
-
klass.parent = @top_level
|
1277
|
-
|
1278
|
-
method = "def ω() end"
|
1279
|
-
|
1280
|
-
assert_equal Encoding::UTF_8, method.encoding if
|
1281
|
-
Object.const_defined? :Encoding
|
1282
|
-
|
1283
|
-
util_parser method
|
1284
|
-
|
1285
|
-
tk = @parser.get_tk
|
1286
|
-
|
1287
|
-
@parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, ''
|
1288
|
-
|
1289
|
-
omega = klass.method_list.first
|
1290
|
-
assert_equal "def \317\211", omega.text
|
1291
|
-
end
|
1292
|
-
|
1293
|
-
def test_parse_statements_class_if
|
1294
|
-
util_parser <<-CODE
|
1295
|
-
module Foo
|
1296
|
-
X = if TRUE then
|
1297
|
-
''
|
1298
|
-
end
|
1299
|
-
|
1300
|
-
def blah
|
1301
|
-
end
|
1302
|
-
end
|
1303
|
-
CODE
|
1304
|
-
|
1305
|
-
@parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil, ''
|
1306
|
-
|
1307
|
-
foo = @top_level.modules.first
|
1308
|
-
assert_equal 'Foo', foo.full_name, 'module Foo'
|
1309
|
-
|
1310
|
-
methods = foo.method_list
|
1311
|
-
assert_equal 1, methods.length
|
1312
|
-
assert_equal 'Foo#blah', methods.first.full_name
|
1313
|
-
end
|
1314
|
-
|
1315
|
-
def test_parse_statements_class_nested
|
1316
|
-
comment = "##\n# my method\n"
|
1317
|
-
|
1318
|
-
util_parser "module Foo\n#{comment}class Bar\nend\nend"
|
1319
|
-
|
1320
|
-
@parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil, ''
|
1321
|
-
|
1322
|
-
foo = @top_level.modules.first
|
1323
|
-
assert_equal 'Foo', foo.full_name, 'module Foo'
|
1324
|
-
|
1325
|
-
bar = foo.classes.first
|
1326
|
-
assert_equal 'Foo::Bar', bar.full_name, 'class Foo::Bar'
|
1327
|
-
assert_equal 'my method', bar.comment
|
1328
|
-
end
|
1329
|
-
|
1330
|
-
def test_parse_statements_identifier_meta_method
|
1331
|
-
content = <<-EOF
|
1332
|
-
class Foo
|
1333
|
-
##
|
1334
|
-
# this is my method
|
1335
|
-
add_my_method :foo
|
1336
|
-
end
|
1337
|
-
EOF
|
1338
|
-
|
1339
|
-
util_parser content
|
1340
|
-
|
1341
|
-
@parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil, ''
|
1342
|
-
|
1343
|
-
foo = @top_level.classes.first.method_list.first
|
1344
|
-
assert_equal 'foo', foo.name
|
1345
|
-
end
|
1346
|
-
|
1347
|
-
def test_parse_statements_identifier_alias_method
|
1348
|
-
content = <<-RUBY
|
1349
|
-
class Foo
|
1350
|
-
def foo() end
|
1351
|
-
alias_method :foo2, :foo
|
1352
|
-
end
|
1353
|
-
RUBY
|
1354
|
-
|
1355
|
-
util_parser content
|
1356
|
-
|
1357
|
-
@parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil, ''
|
1358
|
-
|
1359
|
-
foo = @top_level.classes.first.method_list[0]
|
1360
|
-
assert_equal 'foo', foo.name
|
1361
|
-
|
1362
|
-
foo2 = @top_level.classes.first.method_list.last
|
1363
|
-
assert_equal 'foo2', foo2.name
|
1364
|
-
assert_equal 'foo', foo2.is_alias_for.name
|
1365
|
-
assert @top_level.classes.first.aliases.empty?
|
1366
|
-
end
|
1367
|
-
|
1368
|
-
def test_parse_statements_identifier_alias_method_before_original_method
|
1369
|
-
# This is not strictly legal Ruby code, but it simulates finding an alias
|
1370
|
-
# for a method before finding the original method, which might happen
|
1371
|
-
# to rdoc if the alias is in a different file than the original method
|
1372
|
-
# and rdoc processes the alias' file first.
|
1373
|
-
content = <<-EOF
|
1374
|
-
class Foo
|
1375
|
-
alias_method :foo2, :foo
|
1376
|
-
|
1377
|
-
alias_method :foo3, :foo
|
1378
|
-
|
1379
|
-
def foo()
|
1380
|
-
end
|
1381
|
-
|
1382
|
-
alias_method :foo4, :foo
|
1383
|
-
|
1384
|
-
alias_method :foo5, :unknown
|
1385
|
-
end
|
1386
|
-
EOF
|
1387
|
-
|
1388
|
-
util_parser content
|
1389
|
-
|
1390
|
-
@parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil, ''
|
1391
|
-
|
1392
|
-
foo = @top_level.classes.first.method_list[0]
|
1393
|
-
assert_equal 'foo', foo.name
|
1394
|
-
|
1395
|
-
foo2 = @top_level.classes.first.method_list[1]
|
1396
|
-
assert_equal 'foo2', foo2.name
|
1397
|
-
assert_equal 'foo', foo2.is_alias_for.name
|
1398
|
-
|
1399
|
-
foo3 = @top_level.classes.first.method_list[2]
|
1400
|
-
assert_equal 'foo3', foo3.name
|
1401
|
-
assert_equal 'foo', foo3.is_alias_for.name
|
1402
|
-
|
1403
|
-
foo4 = @top_level.classes.first.method_list.last
|
1404
|
-
assert_equal 'foo4', foo4.name
|
1405
|
-
assert_equal 'foo', foo4.is_alias_for.name
|
1406
|
-
|
1407
|
-
assert_equal 'unknown', @top_level.classes.first.external_aliases[0].old_name
|
1408
|
-
end
|
1409
|
-
|
1410
|
-
def test_parse_statements_identifier_constant
|
1411
|
-
|
1412
|
-
sixth_constant = <<-EOF
|
1413
|
-
Class.new do
|
1414
|
-
rule :file do
|
1415
|
-
all(x, y, z) {
|
1416
|
-
def value
|
1417
|
-
find(:require).each {|r| require r.value }
|
1418
|
-
find(:grammar).map {|g| g.value }
|
1419
|
-
end
|
1420
|
-
def min; end
|
1421
|
-
}
|
1422
|
-
end
|
1423
|
-
end
|
1424
|
-
EOF
|
1425
|
-
|
1426
|
-
content = <<-EOF
|
1427
|
-
class Foo
|
1428
|
-
FIRST_CONSTANT = 5
|
1429
|
-
|
1430
|
-
SECOND_CONSTANT = [
|
1431
|
-
1,
|
1432
|
-
2,
|
1433
|
-
3
|
1434
|
-
]
|
1435
|
-
|
1436
|
-
THIRD_CONSTANT = {
|
1437
|
-
:foo => 'bar',
|
1438
|
-
:x => 'y'
|
1439
|
-
}
|
1440
|
-
|
1441
|
-
FOURTH_CONSTANT = SECOND_CONSTANT.map do |element|
|
1442
|
-
element + 1
|
1443
|
-
element + 2
|
1444
|
-
end
|
1445
|
-
|
1446
|
-
FIFTH_CONSTANT = SECOND_CONSTANT.map { |element| element + 1 }
|
1447
|
-
|
1448
|
-
SIXTH_CONSTANT = #{sixth_constant}
|
1449
|
-
|
1450
|
-
SEVENTH_CONSTANT = proc { |i| begin i end }
|
1451
|
-
end
|
1452
|
-
EOF
|
1453
|
-
|
1454
|
-
util_parser content
|
1455
|
-
|
1456
|
-
@parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil, ''
|
1457
|
-
|
1458
|
-
constants = @top_level.classes.first.constants
|
1459
|
-
|
1460
|
-
constant = constants[0]
|
1461
|
-
assert_equal 'FIRST_CONSTANT', constant.name
|
1462
|
-
assert_equal '5', constant.value
|
1463
|
-
assert_equal @top_level, constant.file
|
1464
|
-
|
1465
|
-
constant = constants[1]
|
1466
|
-
assert_equal 'SECOND_CONSTANT', constant.name
|
1467
|
-
assert_equal "[\n1,\n2,\n3\n]", constant.value
|
1468
|
-
assert_equal @top_level, constant.file
|
1469
|
-
|
1470
|
-
constant = constants[2]
|
1471
|
-
assert_equal 'THIRD_CONSTANT', constant.name
|
1472
|
-
assert_equal "{\n:foo => 'bar',\n:x => 'y'\n}", constant.value
|
1473
|
-
assert_equal @top_level, constant.file
|
1474
|
-
|
1475
|
-
constant = constants[3]
|
1476
|
-
assert_equal 'FOURTH_CONSTANT', constant.name
|
1477
|
-
assert_equal "SECOND_CONSTANT.map do |element|\nelement + 1\nelement + 2\nend", constant.value
|
1478
|
-
assert_equal @top_level, constant.file
|
1479
|
-
|
1480
|
-
constant = constants[4]
|
1481
|
-
assert_equal 'FIFTH_CONSTANT', constant.name
|
1482
|
-
assert_equal 'SECOND_CONSTANT.map { |element| element + 1 }', constant.value
|
1483
|
-
assert_equal @top_level, constant.file
|
1484
|
-
|
1485
|
-
# TODO: parse as class
|
1486
|
-
constant = constants[5]
|
1487
|
-
assert_equal 'SIXTH_CONSTANT', constant.name
|
1488
|
-
assert_equal sixth_constant.lines.map(&:strip).join("\n"), constant.value
|
1489
|
-
assert_equal @top_level, constant.file
|
1490
|
-
|
1491
|
-
# TODO: parse as method
|
1492
|
-
constant = constants[6]
|
1493
|
-
assert_equal 'SEVENTH_CONSTANT', constant.name
|
1494
|
-
assert_equal "proc { |i| begin i end }", constant.value
|
1495
|
-
assert_equal @top_level, constant.file
|
1496
|
-
end
|
1497
|
-
|
1498
|
-
def test_parse_statements_identifier_attr
|
1499
|
-
content = "class Foo\nattr :foo\nend"
|
1500
|
-
|
1501
|
-
util_parser content
|
1502
|
-
|
1503
|
-
@parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil, ''
|
1504
|
-
|
1505
|
-
foo = @top_level.classes.first.attributes.first
|
1506
|
-
assert_equal 'foo', foo.name
|
1507
|
-
assert_equal 'R', foo.rw
|
1508
|
-
end
|
1509
|
-
|
1510
|
-
def test_parse_statements_identifier_attr_accessor
|
1511
|
-
content = "class Foo\nattr_accessor :foo\nend"
|
1512
|
-
|
1513
|
-
util_parser content
|
1514
|
-
|
1515
|
-
@parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil, ''
|
1516
|
-
|
1517
|
-
foo = @top_level.classes.first.attributes.first
|
1518
|
-
assert_equal 'foo', foo.name
|
1519
|
-
assert_equal 'RW', foo.rw
|
1520
|
-
end
|
1521
|
-
|
1522
|
-
def test_parse_statements_identifier_include
|
1523
|
-
content = "class Foo\ninclude Bar\nend"
|
1524
|
-
|
1525
|
-
util_parser content
|
1526
|
-
|
1527
|
-
@parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil, ''
|
1528
|
-
|
1529
|
-
foo = @top_level.classes.first
|
1530
|
-
assert_equal 'Foo', foo.name
|
1531
|
-
assert_equal 1, foo.includes.length
|
1532
|
-
end
|
1533
|
-
|
1534
|
-
def test_parse_statements_identifier_module_function
|
1535
|
-
content = "module Foo\ndef foo() end\nmodule_function :foo\nend"
|
1536
|
-
|
1537
|
-
util_parser content
|
1538
|
-
|
1539
|
-
@parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil, ''
|
1540
|
-
|
1541
|
-
foo, s_foo = @top_level.modules.first.method_list
|
1542
|
-
assert_equal 'foo', foo.name, 'instance method name'
|
1543
|
-
assert_equal :private, foo.visibility, 'instance method visibility'
|
1544
|
-
assert_equal false, foo.singleton, 'instance method singleton'
|
1545
|
-
|
1546
|
-
assert_equal 'foo', s_foo.name, 'module function name'
|
1547
|
-
assert_equal :public, s_foo.visibility, 'module function visibility'
|
1548
|
-
assert_equal true, s_foo.singleton, 'module function singleton'
|
1549
|
-
end
|
1550
|
-
|
1551
|
-
def test_parse_statements_identifier_private
|
1552
|
-
content = "class Foo\nprivate\ndef foo() end\nend"
|
1553
|
-
|
1554
|
-
util_parser content
|
1555
|
-
|
1556
|
-
@parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil, ''
|
1557
|
-
|
1558
|
-
foo = @top_level.classes.first.method_list.first
|
1559
|
-
assert_equal 'foo', foo.name
|
1560
|
-
assert_equal :private, foo.visibility
|
1561
|
-
end
|
1562
|
-
|
1563
|
-
def test_parse_statements_identifier_require
|
1564
|
-
content = "require 'bar'"
|
1565
|
-
|
1566
|
-
util_parser content
|
1567
|
-
|
1568
|
-
@parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil, ''
|
1569
|
-
|
1570
|
-
assert_equal 1, @top_level.requires.length
|
1571
|
-
end
|
1572
|
-
|
1573
|
-
def test_parse_statements_while_begin
|
1574
|
-
util_parser <<-RUBY
|
1575
|
-
class A
|
1576
|
-
def a
|
1577
|
-
while begin a; b end
|
1578
|
-
end
|
1579
|
-
end
|
1580
|
-
|
1581
|
-
def b
|
1582
|
-
end
|
1583
|
-
end
|
1584
|
-
RUBY
|
1585
|
-
|
1586
|
-
@parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil, ''
|
1587
|
-
|
1588
|
-
c_a = @top_level.classes.first
|
1589
|
-
assert_equal 'A', c_a.full_name
|
1590
|
-
|
1591
|
-
assert_equal 1, @top_level.classes.length
|
1592
|
-
|
1593
|
-
m_a = c_a.method_list.first
|
1594
|
-
m_b = c_a.method_list.last
|
1595
|
-
|
1596
|
-
assert_equal 'A#a', m_a.full_name
|
1597
|
-
assert_equal 'A#b', m_b.full_name
|
1598
|
-
end
|
1599
|
-
|
1600
|
-
def test_parse_symbol_in_arg
|
1601
|
-
util_parser ':blah "blah" "#{blah}" blah'
|
1602
|
-
|
1603
|
-
assert_equal 'blah', @parser.parse_symbol_in_arg
|
1604
|
-
|
1605
|
-
@parser.skip_tkspace
|
1606
|
-
|
1607
|
-
assert_equal 'blah', @parser.parse_symbol_in_arg
|
1608
|
-
|
1609
|
-
@parser.skip_tkspace
|
1610
|
-
|
1611
|
-
assert_equal nil, @parser.parse_symbol_in_arg
|
1612
|
-
|
1613
|
-
@parser.skip_tkspace
|
1614
|
-
|
1615
|
-
assert_equal nil, @parser.parse_symbol_in_arg
|
1616
|
-
end
|
1617
|
-
|
1618
|
-
def test_parse_top_level_statements_alias_method
|
1619
|
-
content = <<-CONTENT
|
1620
|
-
class A
|
1621
|
-
alias_method :a, :[] unless c
|
1622
|
-
end
|
1623
|
-
|
1624
|
-
B = A
|
1625
|
-
|
1626
|
-
class C
|
1627
|
-
end
|
1628
|
-
CONTENT
|
1629
|
-
|
1630
|
-
util_parser content
|
1631
|
-
|
1632
|
-
@parser.parse_statements @top_level
|
1633
|
-
end
|
1634
|
-
|
1635
|
-
def test_parse_yield_in_braces_with_parens
|
1636
|
-
klass = RDoc::NormalClass.new 'Foo'
|
1637
|
-
klass.parent = @top_level
|
1638
|
-
|
1639
|
-
util_parser "def foo\nn.times { |i| yield nth(i) }\nend"
|
1640
|
-
|
1641
|
-
tk = @parser.get_tk
|
1642
|
-
|
1643
|
-
@parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, ''
|
1644
|
-
|
1645
|
-
foo = klass.method_list.first
|
1646
|
-
assert_equal 'nth(i)', foo.block_params
|
1647
|
-
end
|
1648
|
-
|
1649
|
-
def test_sanity_integer
|
1650
|
-
util_parser '1'
|
1651
|
-
assert_equal '1', @parser.get_tk.text
|
1652
|
-
|
1653
|
-
util_parser '1.0'
|
1654
|
-
assert_equal '1.0', @parser.get_tk.text
|
1655
|
-
end
|
1656
|
-
|
1657
|
-
def test_sanity_interpolation
|
1658
|
-
last_tk = nil
|
1659
|
-
util_parser 'class A; B = "#{c}"; end'
|
1660
|
-
|
1661
|
-
while tk = @parser.get_tk do last_tk = tk end
|
1662
|
-
|
1663
|
-
assert_equal "\n", last_tk.text
|
1664
|
-
end
|
1665
|
-
|
1666
|
-
# If you're writing code like this you're doing it wrong
|
1667
|
-
|
1668
|
-
def test_sanity_interpolation_crazy
|
1669
|
-
util_parser '"#{"#{"a")}" if b}"'
|
1670
|
-
|
1671
|
-
assert_equal '"#{"#{"a")}" if b}"', @parser.get_tk.text
|
1672
|
-
assert_equal RDoc::RubyToken::TkNL, @parser.get_tk.class
|
1673
|
-
end
|
1674
|
-
|
1675
|
-
def test_sanity_interpolation_curly
|
1676
|
-
util_parser '%{ #{} }'
|
1677
|
-
|
1678
|
-
assert_equal '%{ #{} }', @parser.get_tk.text
|
1679
|
-
assert_equal RDoc::RubyToken::TkNL, @parser.get_tk.class
|
1680
|
-
end
|
1681
|
-
|
1682
|
-
def test_sanity_interpolation_format
|
1683
|
-
util_parser '"#{stftime("%m-%d")}"'
|
1684
|
-
|
1685
|
-
while @parser.get_tk do end
|
1686
|
-
end
|
1687
|
-
|
1688
|
-
def test_sanity_symbol_interpolation
|
1689
|
-
util_parser ':"#{bar}="'
|
1690
|
-
|
1691
|
-
while @parser.get_tk do end
|
1692
|
-
end
|
1693
|
-
|
1694
|
-
def test_stopdoc_after_comment
|
1695
|
-
|
1696
|
-
util_parser <<-EOS
|
1697
|
-
module Bar
|
1698
|
-
# hello
|
1699
|
-
module Foo
|
1700
|
-
# :stopdoc:
|
1701
|
-
end
|
1702
|
-
# there
|
1703
|
-
class Baz
|
1704
|
-
# :stopdoc:
|
1705
|
-
end
|
1706
|
-
end
|
1707
|
-
EOS
|
1708
|
-
|
1709
|
-
@parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil, ''
|
1710
|
-
|
1711
|
-
foo = @top_level.modules.first.modules.first
|
1712
|
-
assert_equal 'Foo', foo.name
|
1713
|
-
assert_equal 'hello', foo.comment
|
1714
|
-
|
1715
|
-
baz = @top_level.modules.first.classes.first
|
1716
|
-
assert_equal 'Baz', baz.name
|
1717
|
-
assert_equal 'there', baz.comment
|
1718
|
-
end
|
1719
|
-
|
1720
|
-
def tk(klass, line, char, name, text)
|
1721
|
-
klass = RDoc::RubyToken.const_get "Tk#{klass.to_s.upcase}"
|
1722
|
-
|
1723
|
-
token = if klass.instance_method(:initialize).arity == 3 then
|
1724
|
-
raise ArgumentError, "name not used for #{klass}" unless name.nil?
|
1725
|
-
klass.new nil, line, char
|
1726
|
-
else
|
1727
|
-
klass.new nil, line, char, name
|
1728
|
-
end
|
1729
|
-
|
1730
|
-
token.set_text text
|
1731
|
-
|
1732
|
-
token
|
1733
|
-
end
|
1734
|
-
|
1735
|
-
def util_parser(content)
|
1736
|
-
@parser = RDoc::Parser::Ruby.new @top_level, @filename, content, @options,
|
1737
|
-
@stats
|
1738
|
-
end
|
1739
|
-
|
1740
|
-
def util_two_parsers(first_file_content, second_file_content)
|
1741
|
-
util_parser first_file_content
|
1742
|
-
|
1743
|
-
@parser2 = RDoc::Parser::Ruby.new @top_level2, @filename,
|
1744
|
-
second_file_content, @options, @stats
|
1745
|
-
end
|
1746
|
-
|
1747
|
-
def util_top_level
|
1748
|
-
RDoc::TopLevel.reset
|
1749
|
-
@top_level = RDoc::TopLevel.new @filename
|
1750
|
-
@top_level2 = RDoc::TopLevel.new @filename2
|
1751
|
-
end
|
1752
|
-
|
1753
|
-
end
|
1754
|
-
|