rdoc 2.5.11 → 3.0
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.
- data.tar.gz.sig +0 -0
- data/.document +1 -0
- data/History.txt +95 -0
- data/Manifest.txt +13 -4
- data/README.txt +9 -3
- data/Rakefile +1 -1
- data/lib/rdoc.rb +15 -298
- data/lib/rdoc/alias.rb +65 -16
- data/lib/rdoc/any_method.rb +27 -150
- data/lib/rdoc/attr.rb +36 -115
- data/lib/rdoc/class_module.rb +236 -22
- data/lib/rdoc/code_object.rb +76 -31
- data/lib/rdoc/constant.rb +32 -4
- data/lib/rdoc/context.rb +494 -222
- data/lib/rdoc/encoding.rb +79 -0
- data/lib/rdoc/erbio.rb +37 -0
- data/lib/rdoc/gauntlet.rb +9 -5
- data/lib/rdoc/generator.rb +33 -1
- data/lib/rdoc/generator/darkfish.rb +284 -375
- data/lib/rdoc/generator/markup.rb +72 -36
- data/lib/rdoc/generator/ri.rb +4 -4
- data/lib/rdoc/generator/template/darkfish/classpage.rhtml +267 -274
- data/lib/rdoc/generator/template/darkfish/filepage.rhtml +91 -91
- data/lib/rdoc/generator/template/darkfish/index.rhtml +45 -45
- data/lib/rdoc/generator/template/darkfish/rdoc.css +298 -298
- data/lib/rdoc/include.rb +40 -1
- data/lib/rdoc/known_classes.rb +1 -0
- data/lib/rdoc/markup.rb +467 -2
- data/lib/rdoc/markup/attribute_manager.rb +24 -6
- data/lib/rdoc/markup/blank_line.rb +11 -3
- data/lib/rdoc/markup/document.rb +6 -0
- data/lib/rdoc/markup/formatter.rb +10 -0
- data/lib/rdoc/markup/formatter_test_case.rb +339 -3
- data/lib/rdoc/markup/heading.rb +3 -0
- data/lib/rdoc/markup/inline.rb +11 -1
- data/lib/rdoc/markup/list.rb +3 -0
- data/lib/rdoc/markup/list_item.rb +3 -0
- data/lib/rdoc/markup/paragraph.rb +3 -0
- data/lib/rdoc/markup/parser.rb +191 -237
- data/lib/rdoc/markup/{preprocess.rb → pre_process.rb} +50 -29
- data/lib/rdoc/markup/raw.rb +4 -0
- data/lib/rdoc/markup/rule.rb +3 -0
- data/lib/rdoc/markup/text_formatter_test_case.rb +116 -0
- data/lib/rdoc/markup/to_ansi.rb +14 -2
- data/lib/rdoc/markup/to_bs.rb +8 -2
- data/lib/rdoc/markup/to_html.rb +84 -91
- data/lib/rdoc/markup/to_html_crossref.rb +77 -26
- data/lib/rdoc/markup/to_rdoc.rb +94 -49
- data/lib/rdoc/markup/to_test.rb +9 -1
- data/lib/rdoc/markup/verbatim.rb +6 -3
- data/lib/rdoc/method_attr.rb +353 -0
- data/lib/rdoc/normal_class.rb +11 -2
- data/lib/rdoc/normal_module.rb +0 -5
- data/lib/rdoc/options.rb +373 -82
- data/lib/rdoc/parser.rb +59 -23
- data/lib/rdoc/parser/c.rb +224 -86
- data/lib/rdoc/parser/ruby.rb +219 -111
- data/lib/rdoc/parser/ruby_tools.rb +4 -1
- data/lib/rdoc/parser/simple.rb +9 -4
- data/lib/rdoc/rdoc.rb +68 -28
- data/lib/rdoc/require.rb +21 -0
- data/lib/rdoc/ri/driver.rb +20 -10
- data/lib/rdoc/ri/paths.rb +2 -2
- data/lib/rdoc/ri/store.rb +22 -5
- data/lib/rdoc/ruby_lex.rb +11 -12
- data/lib/rdoc/ruby_token.rb +2 -2
- data/lib/rdoc/single_class.rb +2 -1
- data/lib/rdoc/stats.rb +202 -162
- data/lib/rdoc/stats/normal.rb +51 -0
- data/lib/rdoc/stats/quiet.rb +59 -0
- data/lib/rdoc/stats/verbose.rb +45 -0
- data/lib/rdoc/text.rb +133 -4
- data/lib/rdoc/{tokenstream.rb → token_stream.rb} +0 -2
- data/lib/rdoc/top_level.rb +230 -39
- data/test/test_attribute_manager.rb +58 -7
- data/test/test_rdoc_alias.rb +13 -0
- data/test/test_rdoc_any_method.rb +43 -2
- data/test/test_rdoc_attr.rb +15 -8
- data/test/test_rdoc_class_module.rb +133 -0
- data/test/test_rdoc_code_object.rb +62 -5
- data/test/test_rdoc_context.rb +72 -26
- data/test/test_rdoc_encoding.rb +145 -0
- data/test/test_rdoc_generator_darkfish.rb +119 -0
- data/test/test_rdoc_generator_ri.rb +22 -2
- data/test/test_rdoc_include.rb +79 -0
- data/test/test_rdoc_markup_attribute_manager.rb +4 -4
- data/test/test_rdoc_markup_parser.rb +134 -95
- data/test/test_rdoc_markup_pre_process.rb +7 -2
- data/test/test_rdoc_markup_to_ansi.rb +43 -153
- data/test/test_rdoc_markup_to_bs.rb +42 -156
- data/test/test_rdoc_markup_to_html.rb +130 -58
- data/test/test_rdoc_markup_to_html_crossref.rb +10 -10
- data/test/test_rdoc_markup_to_rdoc.rb +40 -151
- data/test/test_rdoc_method_attr.rb +122 -0
- data/test/test_rdoc_normal_class.rb +1 -1
- data/test/test_rdoc_normal_module.rb +6 -1
- data/test/test_rdoc_options.rb +237 -12
- data/test/test_rdoc_parser.rb +3 -22
- data/test/test_rdoc_parser_c.rb +203 -2
- data/test/test_rdoc_parser_ruby.rb +403 -89
- data/test/test_rdoc_parser_simple.rb +25 -1
- data/test/test_rdoc_rdoc.rb +44 -32
- data/test/test_rdoc_ri_driver.rb +29 -24
- data/test/test_rdoc_ri_store.rb +46 -3
- data/test/test_rdoc_task.rb +1 -1
- data/test/test_rdoc_text.rb +102 -8
- data/test/test_rdoc_top_level.rb +13 -4
- data/test/xref_data.rb +8 -0
- data/test/xref_test_case.rb +6 -0
- metadata +29 -19
- metadata.gz.sig +0 -0
- data/lib/rdoc/parser/perl.rb +0 -165
- data/test/test_rdoc_parser_perl.rb +0 -73
data/test/test_rdoc_parser_c.rb
CHANGED
@@ -5,6 +5,46 @@ require 'minitest/autorun'
|
|
5
5
|
require 'rdoc/options'
|
6
6
|
require 'rdoc/parser/c'
|
7
7
|
|
8
|
+
=begin
|
9
|
+
TODO: test call-seq parsing
|
10
|
+
|
11
|
+
/*
|
12
|
+
* call-seq:
|
13
|
+
* ARGF.readlines(sep=$/) -> array
|
14
|
+
* ARGF.readlines(limit) -> array
|
15
|
+
* ARGF.readlines(sep, limit) -> array
|
16
|
+
*
|
17
|
+
* ARGF.to_a(sep=$/) -> array
|
18
|
+
* ARGF.to_a(limit) -> array
|
19
|
+
* ARGF.to_a(sep, limit) -> array
|
20
|
+
*
|
21
|
+
* Reads +ARGF+'s current file in its entirety, returning an +Array+ of its
|
22
|
+
* lines, one line per element. Lines are assumed to be separated by _sep_.
|
23
|
+
*
|
24
|
+
* lines = ARGF.readlines
|
25
|
+
* lines[0] #=> "This is line one\n"
|
26
|
+
*/
|
27
|
+
|
28
|
+
assert call-seq did not stop at first empty line
|
29
|
+
|
30
|
+
/*
|
31
|
+
* call-seq:
|
32
|
+
*
|
33
|
+
* flt ** other -> float
|
34
|
+
*
|
35
|
+
* Raises <code>float</code> the <code>other</code> power.
|
36
|
+
*
|
37
|
+
* 2.0**3 #=> 8.0
|
38
|
+
*/
|
39
|
+
|
40
|
+
assert call-seq correct (bug: was empty)
|
41
|
+
|
42
|
+
/* call-seq: flt ** other -> float */
|
43
|
+
|
44
|
+
assert call-seq correct
|
45
|
+
|
46
|
+
=end
|
47
|
+
|
8
48
|
class RDoc::Parser::C
|
9
49
|
attr_accessor :classes, :singleton_classes
|
10
50
|
|
@@ -30,6 +70,72 @@ class TestRDocParserC < MiniTest::Unit::TestCase
|
|
30
70
|
@tempfile.close
|
31
71
|
end
|
32
72
|
|
73
|
+
def test_do_attr_rb_attr
|
74
|
+
content = <<-EOF
|
75
|
+
void Init_Blah(void) {
|
76
|
+
cBlah = rb_define_class("Blah", rb_cObject);
|
77
|
+
|
78
|
+
/*
|
79
|
+
* This is an accessor
|
80
|
+
*/
|
81
|
+
rb_attr(cBlah, rb_intern("accessor"), 1, 1, Qfalse);
|
82
|
+
|
83
|
+
/*
|
84
|
+
* This is a reader
|
85
|
+
*/
|
86
|
+
rb_attr(cBlah, rb_intern("reader"), 1, 0, Qfalse);
|
87
|
+
|
88
|
+
/*
|
89
|
+
* This is a writer
|
90
|
+
*/
|
91
|
+
rb_attr(cBlah, rb_intern("writer"), 0, 1, Qfalse);
|
92
|
+
}
|
93
|
+
EOF
|
94
|
+
|
95
|
+
klass = util_get_class content, 'cBlah'
|
96
|
+
|
97
|
+
attrs = klass.attributes
|
98
|
+
assert_equal 3, attrs.length, attrs.inspect
|
99
|
+
|
100
|
+
accessor = attrs.shift
|
101
|
+
assert_equal 'accessor', accessor.name
|
102
|
+
assert_equal 'RW', accessor.rw
|
103
|
+
assert_equal 'This is an accessor', accessor.comment
|
104
|
+
|
105
|
+
reader = attrs.shift
|
106
|
+
assert_equal 'reader', reader.name
|
107
|
+
assert_equal 'R', reader.rw
|
108
|
+
assert_equal 'This is a reader', reader.comment
|
109
|
+
|
110
|
+
writer = attrs.shift
|
111
|
+
assert_equal 'writer', writer.name
|
112
|
+
assert_equal 'W', writer.rw
|
113
|
+
assert_equal 'This is a writer', writer.comment
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_do_attr_rb_define_attr
|
117
|
+
content = <<-EOF
|
118
|
+
void Init_Blah(void) {
|
119
|
+
cBlah = rb_define_class("Blah", rb_cObject);
|
120
|
+
|
121
|
+
/*
|
122
|
+
* This is an accessor
|
123
|
+
*/
|
124
|
+
rb_define_attr(cBlah, "accessor", 1, 1);
|
125
|
+
}
|
126
|
+
EOF
|
127
|
+
|
128
|
+
klass = util_get_class content, 'cBlah'
|
129
|
+
|
130
|
+
attrs = klass.attributes
|
131
|
+
assert_equal 1, attrs.length, attrs.inspect
|
132
|
+
|
133
|
+
accessor = attrs.shift
|
134
|
+
assert_equal 'accessor', accessor.name
|
135
|
+
assert_equal 'RW', accessor.rw
|
136
|
+
assert_equal 'This is an accessor', accessor.comment
|
137
|
+
end
|
138
|
+
|
33
139
|
def test_do_aliases
|
34
140
|
content = <<-EOF
|
35
141
|
/*
|
@@ -269,6 +375,26 @@ Multiline comment goes here because this comment spans multiple lines.
|
|
269
375
|
assert constants.empty?, constants.inspect
|
270
376
|
end
|
271
377
|
|
378
|
+
def test_find_alias_comment
|
379
|
+
parser = util_parser ''
|
380
|
+
|
381
|
+
comment = parser.find_alias_comment 'C', '[]', 'index'
|
382
|
+
|
383
|
+
assert_equal '', comment
|
384
|
+
|
385
|
+
parser = util_parser <<-C
|
386
|
+
/*
|
387
|
+
* comment
|
388
|
+
*/
|
389
|
+
|
390
|
+
rb_define_alias(C, "[]", "index");
|
391
|
+
C
|
392
|
+
|
393
|
+
comment = parser.find_alias_comment 'C', '[]', 'index'
|
394
|
+
|
395
|
+
assert_equal "/*\n * comment\n */\n\n", comment
|
396
|
+
end
|
397
|
+
|
272
398
|
def test_find_class_comment_include
|
273
399
|
@options.rdoc_include << File.dirname(__FILE__)
|
274
400
|
|
@@ -474,7 +600,7 @@ Init_Foo(void) {
|
|
474
600
|
assert_equal "a comment for bar", bar.comment
|
475
601
|
end
|
476
602
|
|
477
|
-
def
|
603
|
+
def test_find_modifiers_call_seq
|
478
604
|
comment = <<-COMMENT
|
479
605
|
/* call-seq:
|
480
606
|
* commercial() -> Date <br />
|
@@ -497,15 +623,90 @@ Init_Foo(void) {
|
|
497
623
|
|
498
624
|
parser.find_modifiers comment, method_obj
|
499
625
|
|
500
|
-
expected = <<-CALL_SEQ
|
626
|
+
expected = <<-CALL_SEQ.chomp
|
501
627
|
commercial() -> Date <br />
|
502
628
|
commercial(cwyear, cweek=41, cwday=5, sg=nil) -> Date [ruby 1.8] <br />
|
503
629
|
commercial(cwyear, cweek=1, cwday=1, sg=nil) -> Date [ruby 1.9]
|
630
|
+
|
504
631
|
CALL_SEQ
|
505
632
|
|
506
633
|
assert_equal expected, method_obj.call_seq
|
507
634
|
end
|
508
635
|
|
636
|
+
def test_find_modifiers_nodoc
|
637
|
+
comment = <<-COMMENT
|
638
|
+
/* :nodoc:
|
639
|
+
*
|
640
|
+
* Blah
|
641
|
+
*/
|
642
|
+
|
643
|
+
COMMENT
|
644
|
+
|
645
|
+
parser = util_parser ''
|
646
|
+
method_obj = RDoc::AnyMethod.new nil, 'blah'
|
647
|
+
|
648
|
+
parser.find_modifiers comment, method_obj
|
649
|
+
|
650
|
+
assert_equal nil, method_obj.document_self
|
651
|
+
end
|
652
|
+
|
653
|
+
def test_find_modifiers_yields
|
654
|
+
comment = <<-COMMENT
|
655
|
+
/* :yields: a, b
|
656
|
+
*
|
657
|
+
* Blah
|
658
|
+
*/
|
659
|
+
|
660
|
+
COMMENT
|
661
|
+
|
662
|
+
parser = util_parser ''
|
663
|
+
method_obj = RDoc::AnyMethod.new nil, 'blah'
|
664
|
+
|
665
|
+
parser.find_modifiers comment, method_obj
|
666
|
+
|
667
|
+
assert_equal 'a, b', method_obj.block_params
|
668
|
+
|
669
|
+
expected = <<-EXPECTED
|
670
|
+
/*
|
671
|
+
*
|
672
|
+
* Blah
|
673
|
+
*/
|
674
|
+
|
675
|
+
EXPECTED
|
676
|
+
|
677
|
+
assert_equal expected, comment
|
678
|
+
end
|
679
|
+
|
680
|
+
def test_handle_method
|
681
|
+
parser = util_parser "Document-method: BasicObject#==\n blah */"
|
682
|
+
|
683
|
+
parser.handle_method 'method', 'rb_cBasicObject', '==', 'rb_obj_equal', 1
|
684
|
+
|
685
|
+
bo = @top_level.find_module_named 'BasicObject'
|
686
|
+
|
687
|
+
assert_equal 1, bo.method_list.length
|
688
|
+
|
689
|
+
equals2 = bo.method_list.first
|
690
|
+
|
691
|
+
assert_equal '==', equals2.name
|
692
|
+
end
|
693
|
+
|
694
|
+
def test_handle_method_initialize
|
695
|
+
parser = util_parser "Document-method: BasicObject::new\n blah */"
|
696
|
+
|
697
|
+
parser.handle_method('private_method', 'rb_cBasicObject',
|
698
|
+
'initialize', 'rb_obj_dummy', -1)
|
699
|
+
|
700
|
+
bo = @top_level.find_module_named 'BasicObject'
|
701
|
+
|
702
|
+
assert_equal 1, bo.method_list.length
|
703
|
+
|
704
|
+
new = bo.method_list.first
|
705
|
+
|
706
|
+
assert_equal 'new', new.name
|
707
|
+
assert_equal :public, new.visibility
|
708
|
+
end
|
709
|
+
|
509
710
|
def test_look_for_directives_in
|
510
711
|
parser = util_parser ''
|
511
712
|
|
@@ -22,6 +22,8 @@ class TestRDocParserRuby < MiniTest::Unit::TestCase
|
|
22
22
|
util_top_level
|
23
23
|
@options = RDoc::Options.new
|
24
24
|
@options.quiet = true
|
25
|
+
@options.option_parser = OptionParser.new
|
26
|
+
|
25
27
|
@stats = RDoc::Stats.new 0
|
26
28
|
end
|
27
29
|
|
@@ -30,6 +32,30 @@ class TestRDocParserRuby < MiniTest::Unit::TestCase
|
|
30
32
|
@tempfile2.close
|
31
33
|
end
|
32
34
|
|
35
|
+
def test_get_symbol_or_name
|
36
|
+
util_parser "* & | + 5 / 4"
|
37
|
+
|
38
|
+
assert_equal '*', @parser.get_symbol_or_name
|
39
|
+
|
40
|
+
@parser.skip_tkspace
|
41
|
+
|
42
|
+
assert_equal '&', @parser.get_symbol_or_name
|
43
|
+
|
44
|
+
@parser.skip_tkspace
|
45
|
+
|
46
|
+
assert_equal '|', @parser.get_symbol_or_name
|
47
|
+
|
48
|
+
@parser.skip_tkspace
|
49
|
+
|
50
|
+
assert_equal '+', @parser.get_symbol_or_name
|
51
|
+
|
52
|
+
@parser.skip_tkspace
|
53
|
+
@parser.get_tk
|
54
|
+
@parser.skip_tkspace
|
55
|
+
|
56
|
+
assert_equal '/', @parser.get_symbol_or_name
|
57
|
+
end
|
58
|
+
|
33
59
|
def test_look_for_directives_in_attr
|
34
60
|
util_parser ""
|
35
61
|
|
@@ -52,6 +78,61 @@ class TestRDocParserRuby < MiniTest::Unit::TestCase
|
|
52
78
|
assert_equal "# :attr_writer: my_method\n", comment
|
53
79
|
end
|
54
80
|
|
81
|
+
def test_remove_private_comments
|
82
|
+
util_parser ''
|
83
|
+
|
84
|
+
comment = <<-EOS
|
85
|
+
# This is text
|
86
|
+
#--
|
87
|
+
# this is private
|
88
|
+
EOS
|
89
|
+
|
90
|
+
expected = <<-EOS
|
91
|
+
# This is text
|
92
|
+
EOS
|
93
|
+
|
94
|
+
@parser.remove_private_comments(comment)
|
95
|
+
|
96
|
+
assert_equal expected, comment
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_remove_private_comments_rule
|
100
|
+
util_parser ''
|
101
|
+
|
102
|
+
comment = <<-EOS
|
103
|
+
# This is text with a rule:
|
104
|
+
# ---
|
105
|
+
# this is also text
|
106
|
+
EOS
|
107
|
+
|
108
|
+
expected = comment.dup
|
109
|
+
|
110
|
+
@parser.remove_private_comments(comment)
|
111
|
+
|
112
|
+
assert_equal expected, comment
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_remove_private_comments_toggle
|
116
|
+
util_parser ''
|
117
|
+
|
118
|
+
comment = <<-EOS
|
119
|
+
# This is text
|
120
|
+
#--
|
121
|
+
# this is private
|
122
|
+
#++
|
123
|
+
# This is text again.
|
124
|
+
EOS
|
125
|
+
|
126
|
+
expected = <<-EOS
|
127
|
+
# This is text
|
128
|
+
# This is text again.
|
129
|
+
EOS
|
130
|
+
|
131
|
+
@parser.remove_private_comments(comment)
|
132
|
+
|
133
|
+
assert_equal expected, comment
|
134
|
+
end
|
135
|
+
|
55
136
|
def test_look_for_directives_in_commented
|
56
137
|
util_parser ""
|
57
138
|
|
@@ -70,9 +151,9 @@ class TestRDocParserRuby < MiniTest::Unit::TestCase
|
|
70
151
|
def test_look_for_directives_in_enddoc
|
71
152
|
util_parser ""
|
72
153
|
|
73
|
-
|
74
|
-
|
75
|
-
|
154
|
+
@parser.look_for_directives_in @top_level, "# :enddoc:\n"
|
155
|
+
|
156
|
+
assert @top_level.done_documenting
|
76
157
|
end
|
77
158
|
|
78
159
|
def test_look_for_directives_in_main
|
@@ -105,13 +186,11 @@ class TestRDocParserRuby < MiniTest::Unit::TestCase
|
|
105
186
|
@top_level.stop_doc
|
106
187
|
assert !@top_level.document_self
|
107
188
|
assert !@top_level.document_children
|
108
|
-
assert !@top_level.force_documentation
|
109
189
|
|
110
190
|
@parser.look_for_directives_in @top_level, "# :startdoc:\n"
|
111
191
|
|
112
192
|
assert @top_level.document_self
|
113
193
|
assert @top_level.document_children
|
114
|
-
assert @top_level.force_documentation
|
115
194
|
end
|
116
195
|
|
117
196
|
def test_look_for_directives_in_stopdoc
|
@@ -166,10 +245,11 @@ class TestRDocParserRuby < MiniTest::Unit::TestCase
|
|
166
245
|
|
167
246
|
alas = @parser.parse_alias klass, RDoc::Parser::Ruby::NORMAL, tk, 'comment'
|
168
247
|
|
169
|
-
assert_equal 'bar',
|
170
|
-
assert_equal 'next=',
|
171
|
-
assert_equal klass,
|
172
|
-
assert_equal 'comment',
|
248
|
+
assert_equal 'bar', alas.old_name
|
249
|
+
assert_equal 'next=', alas.new_name
|
250
|
+
assert_equal klass, alas.parent
|
251
|
+
assert_equal 'comment', alas.comment
|
252
|
+
assert_equal @top_level, alas.file
|
173
253
|
end
|
174
254
|
|
175
255
|
def test_parse_alias_singleton
|
@@ -182,11 +262,12 @@ class TestRDocParserRuby < MiniTest::Unit::TestCase
|
|
182
262
|
|
183
263
|
alas = @parser.parse_alias klass, RDoc::Parser::Ruby::SINGLE, tk, 'comment'
|
184
264
|
|
185
|
-
assert_equal 'bar',
|
186
|
-
assert_equal 'next=',
|
187
|
-
assert_equal klass,
|
188
|
-
assert_equal 'comment',
|
189
|
-
|
265
|
+
assert_equal 'bar', alas.old_name
|
266
|
+
assert_equal 'next=', alas.new_name
|
267
|
+
assert_equal klass, alas.parent
|
268
|
+
assert_equal 'comment', alas.comment
|
269
|
+
assert_equal @top_level, alas.file
|
270
|
+
assert alas.singleton
|
190
271
|
end
|
191
272
|
|
192
273
|
def test_parse_alias_meta
|
@@ -219,6 +300,7 @@ class TestRDocParserRuby < MiniTest::Unit::TestCase
|
|
219
300
|
foo = klass.attributes.first
|
220
301
|
assert_equal 'foo', foo.name
|
221
302
|
assert_equal 'my attr', foo.comment
|
303
|
+
assert_equal @top_level, foo.file
|
222
304
|
end
|
223
305
|
|
224
306
|
def test_parse_attr_accessor
|
@@ -239,6 +321,7 @@ class TestRDocParserRuby < MiniTest::Unit::TestCase
|
|
239
321
|
assert_equal 'foo', foo.name
|
240
322
|
assert_equal 'RW', foo.rw
|
241
323
|
assert_equal 'my attr', foo.comment
|
324
|
+
assert_equal @top_level, foo.file
|
242
325
|
|
243
326
|
bar = klass.attributes.last
|
244
327
|
assert_equal 'bar', bar.name
|
@@ -246,6 +329,21 @@ class TestRDocParserRuby < MiniTest::Unit::TestCase
|
|
246
329
|
assert_equal 'my attr', bar.comment
|
247
330
|
end
|
248
331
|
|
332
|
+
def test_parse_attr_accessor_nodoc
|
333
|
+
klass = RDoc::NormalClass.new 'Foo'
|
334
|
+
klass.parent = @top_level
|
335
|
+
|
336
|
+
comment = "##\n# my attr\n"
|
337
|
+
|
338
|
+
util_parser "attr_accessor :foo, :bar # :nodoc:"
|
339
|
+
|
340
|
+
tk = @parser.get_tk
|
341
|
+
|
342
|
+
@parser.parse_attr_accessor klass, RDoc::Parser::Ruby::NORMAL, tk, comment
|
343
|
+
|
344
|
+
assert_equal 0, klass.attributes.length
|
345
|
+
end
|
346
|
+
|
249
347
|
def test_parse_attr_accessor_writer
|
250
348
|
klass = RDoc::NormalClass.new 'Foo'
|
251
349
|
klass.parent = @top_level
|
@@ -264,6 +362,7 @@ class TestRDocParserRuby < MiniTest::Unit::TestCase
|
|
264
362
|
assert_equal 'foo', foo.name
|
265
363
|
assert_equal 'W', foo.rw
|
266
364
|
assert_equal "my attr", foo.comment
|
365
|
+
assert_equal @top_level, foo.file
|
267
366
|
|
268
367
|
bar = klass.attributes.last
|
269
368
|
assert_equal 'bar', bar.name
|
@@ -288,6 +387,7 @@ class TestRDocParserRuby < MiniTest::Unit::TestCase
|
|
288
387
|
assert_equal 'foo', foo.name
|
289
388
|
assert_equal 'RW', foo.rw
|
290
389
|
assert_equal "my method", foo.comment
|
390
|
+
assert_equal @top_level, foo.file
|
291
391
|
end
|
292
392
|
|
293
393
|
def test_parse_meta_attr_accessor
|
@@ -307,6 +407,7 @@ class TestRDocParserRuby < MiniTest::Unit::TestCase
|
|
307
407
|
assert_equal 'foo', foo.name
|
308
408
|
assert_equal 'RW', foo.rw
|
309
409
|
assert_equal 'my method', foo.comment
|
410
|
+
assert_equal @top_level, foo.file
|
310
411
|
end
|
311
412
|
|
312
413
|
def test_parse_meta_attr_named
|
@@ -326,6 +427,7 @@ class TestRDocParserRuby < MiniTest::Unit::TestCase
|
|
326
427
|
assert_equal 'foo', foo.name
|
327
428
|
assert_equal 'RW', foo.rw
|
328
429
|
assert_equal 'my method', foo.comment
|
430
|
+
assert_equal @top_level, foo.file
|
329
431
|
end
|
330
432
|
|
331
433
|
def test_parse_meta_attr_reader
|
@@ -344,6 +446,7 @@ class TestRDocParserRuby < MiniTest::Unit::TestCase
|
|
344
446
|
assert_equal 'foo', foo.name
|
345
447
|
assert_equal 'R', foo.rw
|
346
448
|
assert_equal 'my method', foo.comment
|
449
|
+
assert_equal @top_level, foo.file
|
347
450
|
end
|
348
451
|
|
349
452
|
def test_parse_meta_attr_writer
|
@@ -362,12 +465,13 @@ class TestRDocParserRuby < MiniTest::Unit::TestCase
|
|
362
465
|
assert_equal 'foo', foo.name
|
363
466
|
assert_equal 'W', foo.rw
|
364
467
|
assert_equal "my method", foo.comment
|
468
|
+
assert_equal @top_level, foo.file
|
365
469
|
end
|
366
470
|
|
367
471
|
def test_parse_class
|
368
472
|
comment = "##\n# my method\n"
|
369
473
|
|
370
|
-
util_parser
|
474
|
+
util_parser "class Foo\nend"
|
371
475
|
|
372
476
|
tk = @parser.get_tk
|
373
477
|
|
@@ -396,11 +500,12 @@ end
|
|
396
500
|
|
397
501
|
blah = foo.method_list.first
|
398
502
|
assert_equal 'Foo#blah', blah.full_name
|
503
|
+
assert_equal @top_level, blah.file
|
399
504
|
end
|
400
505
|
|
401
506
|
def test_parse_class_nested_superclass
|
402
|
-
|
403
|
-
foo
|
507
|
+
util_top_level
|
508
|
+
foo = @top_level.add_module RDoc::NormalModule, 'Foo'
|
404
509
|
|
405
510
|
util_parser "class Bar < Super\nend"
|
406
511
|
|
@@ -415,7 +520,7 @@ end
|
|
415
520
|
def test_parse_module
|
416
521
|
comment = "##\n# my module\n"
|
417
522
|
|
418
|
-
util_parser
|
523
|
+
util_parser "module Foo\nend"
|
419
524
|
|
420
525
|
tk = @parser.get_tk
|
421
526
|
|
@@ -446,6 +551,10 @@ end
|
|
446
551
|
class A
|
447
552
|
class << B
|
448
553
|
end
|
554
|
+
class << d = Object.new
|
555
|
+
def foo; end
|
556
|
+
alias bar foo
|
557
|
+
end
|
449
558
|
end
|
450
559
|
CODE
|
451
560
|
|
@@ -454,7 +563,40 @@ end
|
|
454
563
|
@parser.parse_class @top_level, false, @parser.get_tk, ''
|
455
564
|
|
456
565
|
assert_equal %w[A], RDoc::TopLevel.classes.map { |c| c.full_name }
|
457
|
-
assert_equal %w[A::B], RDoc::TopLevel.modules.map { |c| c.full_name }
|
566
|
+
assert_equal %w[A::B A::d], RDoc::TopLevel.modules.map { |c| c.full_name }
|
567
|
+
|
568
|
+
# make sure method/alias was not added to enclosing class/module
|
569
|
+
a = RDoc::TopLevel.all_classes_hash['A']
|
570
|
+
assert_empty a.method_list
|
571
|
+
|
572
|
+
# make sure non-constant-named module will be removed from documentation
|
573
|
+
d = RDoc::TopLevel.all_modules_hash['A::d']
|
574
|
+
assert d.remove_from_documentation?
|
575
|
+
|
576
|
+
end
|
577
|
+
|
578
|
+
# TODO this is really a Context#add_class test
|
579
|
+
def test_parse_class_object
|
580
|
+
code = <<-CODE
|
581
|
+
module A
|
582
|
+
class B
|
583
|
+
end
|
584
|
+
class Object
|
585
|
+
end
|
586
|
+
class C < Object
|
587
|
+
end
|
588
|
+
end
|
589
|
+
CODE
|
590
|
+
|
591
|
+
util_parser code
|
592
|
+
|
593
|
+
@parser.parse_module @top_level, false, @parser.get_tk, ''
|
594
|
+
|
595
|
+
assert_equal %w[A], RDoc::TopLevel.modules.map { |c| c.full_name }
|
596
|
+
assert_equal %w[A::B A::C A::Object], RDoc::TopLevel.classes.map { |c| c.full_name }.sort
|
597
|
+
assert_equal 'Object', RDoc::TopLevel.classes_hash['A::B'].superclass
|
598
|
+
assert_equal 'Object', RDoc::TopLevel.classes_hash['A::Object'].superclass
|
599
|
+
assert_equal 'A::Object', RDoc::TopLevel.classes_hash['A::C'].superclass.full_name
|
458
600
|
end
|
459
601
|
|
460
602
|
def test_parse_class_mistaken_for_module
|
@@ -462,7 +604,7 @@ end
|
|
462
604
|
# before Foo::Bar is encountered), but RDoc might encounter Foo::Bar
|
463
605
|
# before Foo if they live in different files.
|
464
606
|
|
465
|
-
code = <<-
|
607
|
+
code = <<-RUBY
|
466
608
|
class Foo::Bar
|
467
609
|
end
|
468
610
|
|
@@ -471,7 +613,7 @@ end
|
|
471
613
|
|
472
614
|
class Foo
|
473
615
|
end
|
474
|
-
|
616
|
+
RUBY
|
475
617
|
|
476
618
|
util_parser code
|
477
619
|
|
@@ -557,18 +699,20 @@ EOF
|
|
557
699
|
@parser.parse_comment klass, tk, comment
|
558
700
|
|
559
701
|
foo = klass.attributes.first
|
560
|
-
assert_equal 'foo',
|
561
|
-
assert_equal 'RW',
|
562
|
-
assert_equal 'my attr',
|
702
|
+
assert_equal 'foo', foo.name
|
703
|
+
assert_equal 'RW', foo.rw
|
704
|
+
assert_equal 'my attr', foo.comment
|
705
|
+
assert_equal @top_level, foo.file
|
706
|
+
|
707
|
+
assert_equal nil, foo.viewer
|
708
|
+
assert_equal true, foo.document_children
|
709
|
+
assert_equal true, foo.document_self
|
710
|
+
assert_equal false, foo.done_documenting
|
711
|
+
assert_equal false, foo.force_documentation
|
712
|
+
assert_equal klass, foo.parent
|
713
|
+
assert_equal :public, foo.visibility
|
714
|
+
assert_equal "\n", foo.text
|
563
715
|
|
564
|
-
assert_equal nil, foo.viewer
|
565
|
-
assert_equal true, foo.document_children
|
566
|
-
assert_equal true, foo.document_self
|
567
|
-
assert_equal false, foo.done_documenting
|
568
|
-
assert_equal false, foo.force_documentation
|
569
|
-
assert_equal klass, foo.parent
|
570
|
-
assert_equal :public, foo.visibility
|
571
|
-
assert_equal "\n", foo.text
|
572
716
|
assert_equal klass.current_section, foo.section
|
573
717
|
end
|
574
718
|
|
@@ -585,8 +729,9 @@ EOF
|
|
585
729
|
@parser.parse_comment klass, tk, comment
|
586
730
|
|
587
731
|
foo = klass.method_list.first
|
588
|
-
assert_equal 'foo',
|
589
|
-
assert_equal 'my method',
|
732
|
+
assert_equal 'foo', foo.name
|
733
|
+
assert_equal 'my method', foo.comment
|
734
|
+
assert_equal @top_level, foo.file
|
590
735
|
|
591
736
|
assert_equal [], foo.aliases
|
592
737
|
assert_equal nil, foo.block_params
|
@@ -614,9 +759,23 @@ EOF
|
|
614
759
|
assert_equal stream, foo.token_stream
|
615
760
|
end
|
616
761
|
|
762
|
+
def test_parse_constant_attrasgn
|
763
|
+
util_top_level
|
764
|
+
|
765
|
+
klass = @top_level.add_class RDoc::NormalClass, 'Foo'
|
766
|
+
|
767
|
+
util_parser "A[k] = v"
|
768
|
+
|
769
|
+
tk = @parser.get_tk
|
770
|
+
|
771
|
+
@parser.parse_constant klass, tk, ''
|
772
|
+
|
773
|
+
assert klass.constants.empty?
|
774
|
+
end
|
775
|
+
|
617
776
|
def test_parse_constant_alias
|
618
|
-
|
619
|
-
klass
|
777
|
+
util_top_level
|
778
|
+
klass = @top_level.add_class RDoc::NormalClass, 'Foo'
|
620
779
|
cB = klass.add_class RDoc::NormalClass, 'B'
|
621
780
|
|
622
781
|
util_parser "A = B"
|
@@ -657,8 +816,9 @@ EOF
|
|
657
816
|
@parser.parse_meta_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment
|
658
817
|
|
659
818
|
foo = klass.method_list.first
|
660
|
-
assert_equal 'foo',
|
819
|
+
assert_equal 'foo', foo.name
|
661
820
|
assert_equal 'my method', foo.comment
|
821
|
+
assert_equal @top_level, foo.file
|
662
822
|
|
663
823
|
assert_equal [], foo.aliases
|
664
824
|
assert_equal nil, foo.block_params
|
@@ -706,8 +866,9 @@ EOF
|
|
706
866
|
@parser.parse_meta_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment
|
707
867
|
|
708
868
|
foo = klass.method_list.first
|
709
|
-
assert_equal 'woo_hoo!',
|
869
|
+
assert_equal 'woo_hoo!', foo.name
|
710
870
|
assert_equal 'my method', foo.comment
|
871
|
+
assert_equal @top_level, foo.file
|
711
872
|
end
|
712
873
|
|
713
874
|
def test_parse_meta_method_singleton
|
@@ -726,6 +887,7 @@ EOF
|
|
726
887
|
assert_equal 'foo', foo.name
|
727
888
|
assert_equal true, foo.singleton, 'singleton method'
|
728
889
|
assert_equal 'my method', foo.comment
|
890
|
+
assert_equal @top_level, foo.file
|
729
891
|
end
|
730
892
|
|
731
893
|
def test_parse_meta_method_singleton_name
|
@@ -744,6 +906,7 @@ EOF
|
|
744
906
|
assert_equal 'woo_hoo!', foo.name
|
745
907
|
assert_equal true, foo.singleton, 'singleton method'
|
746
908
|
assert_equal 'my method', foo.comment
|
909
|
+
assert_equal @top_level, foo.file
|
747
910
|
end
|
748
911
|
|
749
912
|
def test_parse_meta_method_string_name
|
@@ -759,6 +922,7 @@ EOF
|
|
759
922
|
foo = klass.method_list.first
|
760
923
|
assert_equal 'foo', foo.name
|
761
924
|
assert_equal 'my method', foo.comment
|
925
|
+
assert_equal @top_level, foo.file
|
762
926
|
end
|
763
927
|
|
764
928
|
def test_parse_meta_method_unknown
|
@@ -774,6 +938,7 @@ EOF
|
|
774
938
|
foo = klass.method_list.first
|
775
939
|
assert_equal 'unknown', foo.name
|
776
940
|
assert_equal 'my method', foo.comment
|
941
|
+
assert_equal @top_level, foo.file
|
777
942
|
end
|
778
943
|
|
779
944
|
def test_parse_method
|
@@ -789,8 +954,9 @@ EOF
|
|
789
954
|
@parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment
|
790
955
|
|
791
956
|
foo = klass.method_list.first
|
792
|
-
assert_equal 'foo',
|
793
|
-
assert_equal 'my method',
|
957
|
+
assert_equal 'foo', foo.name
|
958
|
+
assert_equal 'my method', foo.comment
|
959
|
+
assert_equal @top_level, foo.file
|
794
960
|
|
795
961
|
assert_equal [], foo.aliases
|
796
962
|
assert_equal nil, foo.block_params
|
@@ -841,39 +1007,53 @@ EOF
|
|
841
1007
|
assert klass.aliases.empty?
|
842
1008
|
end
|
843
1009
|
|
844
|
-
def
|
1010
|
+
def test_parse_method_false
|
1011
|
+
util_parser "def false.foo() :bar end"
|
1012
|
+
|
1013
|
+
tk = @parser.get_tk
|
1014
|
+
|
1015
|
+
@parser.parse_method @top_level, RDoc::Parser::Ruby::NORMAL, tk, ''
|
1016
|
+
|
1017
|
+
klass = RDoc::TopLevel.find_class_named 'FalseClass'
|
1018
|
+
|
1019
|
+
foo = klass.method_list.first
|
1020
|
+
assert_equal 'foo', foo.name
|
1021
|
+
end
|
1022
|
+
|
1023
|
+
def test_parse_method_funky
|
845
1024
|
klass = RDoc::NormalClass.new 'Foo'
|
846
1025
|
klass.parent = @top_level
|
847
1026
|
|
848
|
-
|
1027
|
+
util_parser "def (blah).foo() :bar end"
|
849
1028
|
|
850
|
-
|
1029
|
+
tk = @parser.get_tk
|
851
1030
|
|
852
|
-
|
1031
|
+
@parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, ''
|
853
1032
|
|
854
|
-
|
1033
|
+
assert klass.method_list.empty?
|
1034
|
+
end
|
1035
|
+
|
1036
|
+
def test_parse_method_gvar
|
1037
|
+
util_parser "def $stdout.foo() :bar end"
|
855
1038
|
|
856
1039
|
tk = @parser.get_tk
|
857
1040
|
|
858
|
-
@parser.parse_method
|
1041
|
+
@parser.parse_method @top_level, RDoc::Parser::Ruby::NORMAL, tk, ''
|
859
1042
|
|
860
|
-
|
861
|
-
assert_equal "def \317\211", omega.text
|
1043
|
+
assert @top_level.method_list.empty?
|
862
1044
|
end
|
863
1045
|
|
864
|
-
def
|
1046
|
+
def test_parse_method_internal_gvar
|
865
1047
|
klass = RDoc::NormalClass.new 'Foo'
|
866
1048
|
klass.parent = @top_level
|
867
1049
|
|
868
|
-
|
869
|
-
|
870
|
-
util_parser "def (blah).foo() :bar end"
|
1050
|
+
util_parser "def foo() def $blah.bar() end end"
|
871
1051
|
|
872
1052
|
tk = @parser.get_tk
|
873
1053
|
|
874
|
-
@parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk,
|
1054
|
+
@parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, ''
|
875
1055
|
|
876
|
-
|
1056
|
+
assert_equal 1, klass.method_list.length
|
877
1057
|
end
|
878
1058
|
|
879
1059
|
def test_parse_method_internal_ivar
|
@@ -902,33 +1082,43 @@ EOF
|
|
902
1082
|
assert_equal 1, klass.method_list.length
|
903
1083
|
end
|
904
1084
|
|
1085
|
+
def test_parse_method_nil
|
1086
|
+
util_parser "def nil.foo() :bar end"
|
1087
|
+
|
1088
|
+
tk = @parser.get_tk
|
1089
|
+
|
1090
|
+
@parser.parse_method @top_level, RDoc::Parser::Ruby::NORMAL, tk, ''
|
1091
|
+
|
1092
|
+
klass = RDoc::TopLevel.find_class_named 'NilClass'
|
1093
|
+
|
1094
|
+
foo = klass.method_list.first
|
1095
|
+
assert_equal 'foo', foo.name
|
1096
|
+
end
|
1097
|
+
|
905
1098
|
def test_parse_method_no_parens
|
906
1099
|
klass = RDoc::NormalClass.new 'Foo'
|
907
1100
|
klass.parent = @top_level
|
908
1101
|
|
909
|
-
|
910
|
-
|
911
|
-
util_parser "def foo arg1, arg2\nend"
|
1102
|
+
util_parser "def foo arg1, arg2 = {}\nend"
|
912
1103
|
|
913
1104
|
tk = @parser.get_tk
|
914
1105
|
|
915
|
-
@parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk,
|
1106
|
+
@parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, ''
|
916
1107
|
|
917
1108
|
foo = klass.method_list.first
|
918
|
-
assert_equal '(arg1, arg2)', foo.params
|
1109
|
+
assert_equal '(arg1, arg2 = {})', foo.params
|
1110
|
+
assert_equal @top_level, foo.file
|
919
1111
|
end
|
920
1112
|
|
921
1113
|
def test_parse_method_parameters_comment
|
922
1114
|
klass = RDoc::NormalClass.new 'Foo'
|
923
1115
|
klass.parent = @top_level
|
924
1116
|
|
925
|
-
comment = "##\n# my method\n"
|
926
|
-
|
927
1117
|
util_parser "def foo arg1, arg2 # some useful comment\nend"
|
928
1118
|
|
929
1119
|
tk = @parser.get_tk
|
930
1120
|
|
931
|
-
@parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk,
|
1121
|
+
@parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, ''
|
932
1122
|
|
933
1123
|
foo = klass.method_list.first
|
934
1124
|
assert_equal '(arg1, arg2)', foo.params
|
@@ -938,13 +1128,11 @@ EOF
|
|
938
1128
|
klass = RDoc::NormalClass.new 'Foo'
|
939
1129
|
klass.parent = @top_level
|
940
1130
|
|
941
|
-
comment = "##\n# my method\n"
|
942
|
-
|
943
1131
|
util_parser "def foo arg1, arg2, # some useful comment\narg3\nend"
|
944
1132
|
|
945
1133
|
tk = @parser.get_tk
|
946
1134
|
|
947
|
-
@parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk,
|
1135
|
+
@parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, ''
|
948
1136
|
|
949
1137
|
foo = klass.method_list.first
|
950
1138
|
assert_equal '(arg1, arg2, arg3)', foo.params
|
@@ -953,18 +1141,17 @@ EOF
|
|
953
1141
|
def test_parse_method_toplevel
|
954
1142
|
klass = @top_level
|
955
1143
|
|
956
|
-
comment = "##\n# my method\n"
|
957
|
-
|
958
1144
|
util_parser "def foo arg1, arg2\nend"
|
959
1145
|
|
960
1146
|
tk = @parser.get_tk
|
961
1147
|
|
962
|
-
@parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk,
|
1148
|
+
@parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, ''
|
963
1149
|
|
964
1150
|
object = RDoc::TopLevel.find_class_named 'Object'
|
965
1151
|
|
966
1152
|
foo = object.method_list.first
|
967
1153
|
assert_equal 'Object#foo', foo.full_name
|
1154
|
+
assert_equal @top_level, foo.file
|
968
1155
|
end
|
969
1156
|
|
970
1157
|
def test_parse_method_toplevel_class
|
@@ -982,9 +1169,39 @@ EOF
|
|
982
1169
|
assert_equal 'Object::foo', foo.full_name
|
983
1170
|
end
|
984
1171
|
|
985
|
-
def
|
986
|
-
|
1172
|
+
def test_parse_method_true
|
1173
|
+
util_parser "def true.foo() :bar end"
|
1174
|
+
|
1175
|
+
tk = @parser.get_tk
|
1176
|
+
|
1177
|
+
@parser.parse_method @top_level, RDoc::Parser::Ruby::NORMAL, tk, ''
|
1178
|
+
|
1179
|
+
klass = RDoc::TopLevel.find_class_named 'TrueClass'
|
1180
|
+
|
1181
|
+
foo = klass.method_list.first
|
1182
|
+
assert_equal 'foo', foo.name
|
1183
|
+
end
|
1184
|
+
|
1185
|
+
def test_parse_method_utf8
|
1186
|
+
klass = RDoc::NormalClass.new 'Foo'
|
1187
|
+
klass.parent = @top_level
|
1188
|
+
|
1189
|
+
method = "def ω() end"
|
1190
|
+
|
1191
|
+
assert_equal Encoding::UTF_8, method.encoding if
|
1192
|
+
Object.const_defined? :Encoding
|
1193
|
+
|
1194
|
+
util_parser method
|
1195
|
+
|
1196
|
+
tk = @parser.get_tk
|
1197
|
+
|
1198
|
+
@parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, ''
|
1199
|
+
|
1200
|
+
omega = klass.method_list.first
|
1201
|
+
assert_equal "def \317\211", omega.text
|
1202
|
+
end
|
987
1203
|
|
1204
|
+
def test_parse_statements_class_if
|
988
1205
|
util_parser <<-CODE
|
989
1206
|
module Foo
|
990
1207
|
X = if TRUE then
|
@@ -1039,7 +1256,12 @@ end
|
|
1039
1256
|
end
|
1040
1257
|
|
1041
1258
|
def test_parse_statements_identifier_alias_method
|
1042
|
-
content =
|
1259
|
+
content = <<-RUBY
|
1260
|
+
class Foo
|
1261
|
+
def foo() end
|
1262
|
+
alias_method :foo2, :foo
|
1263
|
+
end
|
1264
|
+
RUBY
|
1043
1265
|
|
1044
1266
|
util_parser content
|
1045
1267
|
|
@@ -1093,10 +1315,25 @@ EOF
|
|
1093
1315
|
assert_equal 'foo4', foo4.name
|
1094
1316
|
assert_equal 'foo', foo4.is_alias_for.name
|
1095
1317
|
|
1096
|
-
assert_equal 'unknown', @top_level.classes.first.
|
1318
|
+
assert_equal 'unknown', @top_level.classes.first.external_aliases[0].old_name
|
1097
1319
|
end
|
1098
1320
|
|
1099
1321
|
def test_parse_statements_identifier_constant
|
1322
|
+
|
1323
|
+
sixth_constant = <<-EOF
|
1324
|
+
Class.new do
|
1325
|
+
rule :file do
|
1326
|
+
all(x, y, z) {
|
1327
|
+
def value
|
1328
|
+
find(:require).each {|r| require r.value }
|
1329
|
+
find(:grammar).map {|g| g.value }
|
1330
|
+
end
|
1331
|
+
def min; end
|
1332
|
+
}
|
1333
|
+
end
|
1334
|
+
end
|
1335
|
+
EOF
|
1336
|
+
|
1100
1337
|
content = <<-EOF
|
1101
1338
|
class Foo
|
1102
1339
|
FIRST_CONSTANT = 5
|
@@ -1118,6 +1355,10 @@ class Foo
|
|
1118
1355
|
end
|
1119
1356
|
|
1120
1357
|
FIFTH_CONSTANT = SECOND_CONSTANT.map { |element| element + 1 }
|
1358
|
+
|
1359
|
+
SIXTH_CONSTANT = #{sixth_constant}
|
1360
|
+
|
1361
|
+
SEVENTH_CONSTANT = proc { |i| begin i end }
|
1121
1362
|
end
|
1122
1363
|
EOF
|
1123
1364
|
|
@@ -1130,26 +1371,43 @@ EOF
|
|
1130
1371
|
constant = constants[0]
|
1131
1372
|
assert_equal 'FIRST_CONSTANT', constant.name
|
1132
1373
|
assert_equal '5', constant.value
|
1374
|
+
assert_equal @top_level, constant.file
|
1133
1375
|
|
1134
1376
|
constant = constants[1]
|
1135
1377
|
assert_equal 'SECOND_CONSTANT', constant.name
|
1136
|
-
assert_equal
|
1378
|
+
assert_equal "[\n1,\n2,\n3\n]", constant.value
|
1379
|
+
assert_equal @top_level, constant.file
|
1137
1380
|
|
1138
1381
|
constant = constants[2]
|
1139
1382
|
assert_equal 'THIRD_CONSTANT', constant.name
|
1140
|
-
assert_equal "{
|
1383
|
+
assert_equal "{\n:foo => 'bar',\n:x => 'y'\n}", constant.value
|
1384
|
+
assert_equal @top_level, constant.file
|
1141
1385
|
|
1142
1386
|
constant = constants[3]
|
1143
1387
|
assert_equal 'FOURTH_CONSTANT', constant.name
|
1144
|
-
assert_equal
|
1388
|
+
assert_equal "SECOND_CONSTANT.map do |element|\nelement + 1\nelement + 2\nend", constant.value
|
1389
|
+
assert_equal @top_level, constant.file
|
1145
1390
|
|
1146
|
-
constant = constants
|
1391
|
+
constant = constants[4]
|
1147
1392
|
assert_equal 'FIFTH_CONSTANT', constant.name
|
1148
1393
|
assert_equal 'SECOND_CONSTANT.map { |element| element + 1 }', constant.value
|
1394
|
+
assert_equal @top_level, constant.file
|
1395
|
+
|
1396
|
+
# TODO: parse as class
|
1397
|
+
constant = constants[5]
|
1398
|
+
assert_equal 'SIXTH_CONSTANT', constant.name
|
1399
|
+
assert_equal sixth_constant.lines.map(&:strip).join("\n"), constant.value
|
1400
|
+
assert_equal @top_level, constant.file
|
1401
|
+
|
1402
|
+
# TODO: parse as method
|
1403
|
+
constant = constants[6]
|
1404
|
+
assert_equal 'SEVENTH_CONSTANT', constant.name
|
1405
|
+
assert_equal "proc { |i| begin i end }", constant.value
|
1406
|
+
assert_equal @top_level, constant.file
|
1149
1407
|
end
|
1150
1408
|
|
1151
1409
|
def test_parse_statements_identifier_attr
|
1152
|
-
content = "class Foo
|
1410
|
+
content = "class Foo\nattr :foo\nend"
|
1153
1411
|
|
1154
1412
|
util_parser content
|
1155
1413
|
|
@@ -1161,7 +1419,7 @@ EOF
|
|
1161
1419
|
end
|
1162
1420
|
|
1163
1421
|
def test_parse_statements_identifier_attr_accessor
|
1164
|
-
content = "class Foo
|
1422
|
+
content = "class Foo\nattr_accessor :foo\nend"
|
1165
1423
|
|
1166
1424
|
util_parser content
|
1167
1425
|
|
@@ -1173,7 +1431,7 @@ EOF
|
|
1173
1431
|
end
|
1174
1432
|
|
1175
1433
|
def test_parse_statements_identifier_include
|
1176
|
-
content = "class Foo
|
1434
|
+
content = "class Foo\ninclude Bar\nend"
|
1177
1435
|
|
1178
1436
|
util_parser content
|
1179
1437
|
|
@@ -1185,24 +1443,24 @@ EOF
|
|
1185
1443
|
end
|
1186
1444
|
|
1187
1445
|
def test_parse_statements_identifier_module_function
|
1188
|
-
content = "module Foo
|
1446
|
+
content = "module Foo\ndef foo() end\nmodule_function :foo\nend"
|
1189
1447
|
|
1190
1448
|
util_parser content
|
1191
1449
|
|
1192
1450
|
@parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil, ''
|
1193
1451
|
|
1194
1452
|
foo, s_foo = @top_level.modules.first.method_list
|
1195
|
-
assert_equal 'foo',
|
1453
|
+
assert_equal 'foo', foo.name, 'instance method name'
|
1196
1454
|
assert_equal :private, foo.visibility, 'instance method visibility'
|
1197
|
-
assert_equal false,
|
1455
|
+
assert_equal false, foo.singleton, 'instance method singleton'
|
1198
1456
|
|
1199
|
-
assert_equal 'foo',
|
1457
|
+
assert_equal 'foo', s_foo.name, 'module function name'
|
1200
1458
|
assert_equal :public, s_foo.visibility, 'module function visibility'
|
1201
|
-
assert_equal true,
|
1459
|
+
assert_equal true, s_foo.singleton, 'module function singleton'
|
1202
1460
|
end
|
1203
1461
|
|
1204
1462
|
def test_parse_statements_identifier_private
|
1205
|
-
content = "class Foo
|
1463
|
+
content = "class Foo\nprivate\ndef foo() end\nend"
|
1206
1464
|
|
1207
1465
|
util_parser content
|
1208
1466
|
|
@@ -1250,6 +1508,24 @@ end
|
|
1250
1508
|
assert_equal 'A#b', m_b.full_name
|
1251
1509
|
end
|
1252
1510
|
|
1511
|
+
def test_parse_symbol_in_arg
|
1512
|
+
util_parser ':blah "blah" "#{blah}" blah'
|
1513
|
+
|
1514
|
+
assert_equal 'blah', @parser.parse_symbol_in_arg
|
1515
|
+
|
1516
|
+
@parser.skip_tkspace
|
1517
|
+
|
1518
|
+
assert_equal 'blah', @parser.parse_symbol_in_arg
|
1519
|
+
|
1520
|
+
@parser.skip_tkspace
|
1521
|
+
|
1522
|
+
assert_equal nil, @parser.parse_symbol_in_arg
|
1523
|
+
|
1524
|
+
@parser.skip_tkspace
|
1525
|
+
|
1526
|
+
assert_equal nil, @parser.parse_symbol_in_arg
|
1527
|
+
end
|
1528
|
+
|
1253
1529
|
def test_parse_top_level_statements_alias_method
|
1254
1530
|
content = <<-CONTENT
|
1255
1531
|
class A
|
@@ -1267,6 +1543,20 @@ end
|
|
1267
1543
|
@parser.parse_statements @top_level
|
1268
1544
|
end
|
1269
1545
|
|
1546
|
+
def test_parse_yield_in_braces_with_parens
|
1547
|
+
klass = RDoc::NormalClass.new 'Foo'
|
1548
|
+
klass.parent = @top_level
|
1549
|
+
|
1550
|
+
util_parser "def foo\nn.times { |i| yield nth(i) }\nend"
|
1551
|
+
|
1552
|
+
tk = @parser.get_tk
|
1553
|
+
|
1554
|
+
@parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, ''
|
1555
|
+
|
1556
|
+
foo = klass.method_list.first
|
1557
|
+
assert_equal 'nth(i)', foo.block_params
|
1558
|
+
end
|
1559
|
+
|
1270
1560
|
def test_sanity_integer
|
1271
1561
|
util_parser '1'
|
1272
1562
|
assert_equal '1', @parser.get_tk.text
|
@@ -1287,7 +1577,6 @@ end
|
|
1287
1577
|
# If you're writing code like this you're doing it wrong
|
1288
1578
|
|
1289
1579
|
def test_sanity_interpolation_crazy
|
1290
|
-
last_tk = nil
|
1291
1580
|
util_parser '"#{"#{"a")}" if b}"'
|
1292
1581
|
|
1293
1582
|
assert_equal '"#{"#{"a")}" if b}"', @parser.get_tk.text
|
@@ -1295,7 +1584,6 @@ end
|
|
1295
1584
|
end
|
1296
1585
|
|
1297
1586
|
def test_sanity_interpolation_curly
|
1298
|
-
last_tk = nil
|
1299
1587
|
util_parser '%{ #{} }'
|
1300
1588
|
|
1301
1589
|
assert_equal '%{ #{} }', @parser.get_tk.text
|
@@ -1305,13 +1593,39 @@ end
|
|
1305
1593
|
def test_sanity_interpolation_format
|
1306
1594
|
util_parser '"#{stftime("%m-%d")}"'
|
1307
1595
|
|
1308
|
-
while
|
1596
|
+
while @parser.get_tk do end
|
1309
1597
|
end
|
1310
1598
|
|
1311
1599
|
def test_sanity_symbol_interpolation
|
1312
1600
|
util_parser ':"#{bar}="'
|
1313
1601
|
|
1314
|
-
while
|
1602
|
+
while @parser.get_tk do end
|
1603
|
+
end
|
1604
|
+
|
1605
|
+
def test_stopdoc_after_comment
|
1606
|
+
|
1607
|
+
util_parser <<-EOS
|
1608
|
+
module Bar
|
1609
|
+
# hello
|
1610
|
+
module Foo
|
1611
|
+
# :stopdoc:
|
1612
|
+
end
|
1613
|
+
# there
|
1614
|
+
class Baz
|
1615
|
+
# :stopdoc:
|
1616
|
+
end
|
1617
|
+
end
|
1618
|
+
EOS
|
1619
|
+
|
1620
|
+
@parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil, ''
|
1621
|
+
|
1622
|
+
foo = @top_level.modules.first.modules.first
|
1623
|
+
assert_equal 'Foo', foo.name
|
1624
|
+
assert_equal 'hello', foo.comment
|
1625
|
+
|
1626
|
+
baz = @top_level.modules.first.classes.first
|
1627
|
+
assert_equal 'Baz', baz.name
|
1628
|
+
assert_equal 'there', baz.comment
|
1315
1629
|
end
|
1316
1630
|
|
1317
1631
|
def tk(klass, line, char, name, text)
|