35
def test_collect_first_comment
36
p = util_parser <<-CONTENT
43
comment = p.collect_first_comment
45
assert_equal "# first\n", comment
48
def test_collect_first_comment_encoding
49
skip "Encoding not implemented" unless Object.const_defined? :Encoding
51
@options.encoding = Encoding::CP852
53
p = util_parser <<-CONTENT
60
comment = p.collect_first_comment
62
assert_equal Encoding::CP852, comment.encoding
65
def test_extract_call_seq
66
m = RDoc::AnyMethod.new nil, 'm'
71
# bla => true or false
76
p.extract_call_seq comment, m
78
assert_equal "bla => true or false\n", m.call_seq
81
def test_extract_call_seq_blank
82
m = RDoc::AnyMethod.new nil, 'm'
87
# bla => true or false
91
p.extract_call_seq comment, m
93
assert_equal "bla => true or false\n", m.call_seq
96
def test_extract_call_seq_no_blank
97
m = RDoc::AnyMethod.new nil, 'm'
102
# bla => true or false
105
p.extract_call_seq comment, m
107
assert_equal "bla => true or false\n", m.call_seq
110
def test_extract_call_seq_undent
111
m = RDoc::AnyMethod.new nil, 'm'
116
# bla => true or false
120
p.extract_call_seq comment, m
122
assert_equal "bla => true or false\nmoar comment\n", m.call_seq
125
def test_get_symbol_or_name
126
util_parser "* & | + 5 / 4"
128
assert_equal '*', @parser.get_symbol_or_name
132
assert_equal '&', @parser.get_symbol_or_name
136
assert_equal '|', @parser.get_symbol_or_name
140
assert_equal '+', @parser.get_symbol_or_name
146
assert_equal '/', @parser.get_symbol_or_name
33
149
def test_look_for_directives_in_attr
52
168
assert_equal "# :attr_writer: my_method\n", comment
171
def test_remove_private_comments
184
@parser.remove_private_comments(comment)
186
assert_equal expected, comment
189
def test_remove_private_comments_encoding
190
skip "Encoding not implemented" unless Object.const_defined? :Encoding
199
comment.force_encoding Encoding::IBM437
201
@parser.remove_private_comments comment
203
assert_equal Encoding::IBM437, comment.encoding
206
def test_remove_private_comments_long
220
@parser.remove_private_comments(comment)
222
assert_equal expected, comment
225
def test_remove_private_comments_rule
229
# This is text with a rule:
234
expected = comment.dup
236
@parser.remove_private_comments(comment)
238
assert_equal expected, comment
241
def test_remove_private_comments_toggle
249
# This is text again.
254
# This is text again.
257
@parser.remove_private_comments(comment)
259
assert_equal expected, comment
262
def test_remove_private_comments_toggle_encoding
263
skip "Encoding not implemented" unless Object.const_defined? :Encoding
272
# This is text again.
275
comment.force_encoding Encoding::IBM437
277
@parser.remove_private_comments comment
279
assert_equal Encoding::IBM437, comment.encoding
282
def test_remove_private_comments_toggle_encoding_ruby_bug?
283
skip "Encoding not implemented" unless Object.const_defined? :Encoding
291
# This is text again.
294
comment.force_encoding Encoding::IBM437
296
@parser.remove_private_comments comment
298
assert_equal Encoding::IBM437, comment.encoding
55
301
def test_look_for_directives_in_commented
99
329
assert_equal "# :singleton-method: my_method\n", comment
102
def test_look_for_directives_in_startdoc
106
assert !@top_level.document_self
107
assert !@top_level.document_children
108
assert !@top_level.force_documentation
110
@parser.look_for_directives_in @top_level, "# :startdoc:\n"
112
assert @top_level.document_self
113
assert @top_level.document_children
114
assert @top_level.force_documentation
117
def test_look_for_directives_in_stopdoc
120
assert @top_level.document_self
121
assert @top_level.document_children
123
@parser.look_for_directives_in @top_level, "# :stopdoc:\n"
125
assert !@top_level.document_self
126
assert !@top_level.document_children
129
332
def test_look_for_directives_in_section
167
362
alas = @parser.parse_alias klass, RDoc::Parser::Ruby::NORMAL, tk, 'comment'
169
assert_equal 'bar', alas.old_name
170
assert_equal 'next=', alas.new_name
171
assert_equal klass, alas.parent
172
assert_equal 'comment', alas.comment
364
assert_equal 'bar', alas.old_name
365
assert_equal 'next=', alas.new_name
366
assert_equal klass, alas.parent
367
assert_equal 'comment', alas.comment
368
assert_equal @top_level, alas.file
369
assert_equal 0, alas.offset
370
assert_equal 1, alas.line
373
def test_parse_alias_singleton
374
klass = RDoc::NormalClass.new 'Foo'
375
klass.parent = @top_level
377
util_parser "alias :next= :bar"
381
alas = @parser.parse_alias klass, RDoc::Parser::Ruby::SINGLE, tk, 'comment'
383
assert_equal 'bar', alas.old_name
384
assert_equal 'next=', alas.new_name
385
assert_equal klass, alas.parent
386
assert_equal 'comment', alas.comment
387
assert_equal @top_level, alas.file
388
assert alas.singleton
391
def test_parse_alias_stopdoc
392
klass = RDoc::NormalClass.new 'Foo'
393
klass.parent = @top_level
396
util_parser "alias :next= :bar"
400
@parser.parse_alias klass, RDoc::Parser::Ruby::NORMAL, tk, 'comment'
402
assert_empty klass.aliases
403
assert_empty klass.unmatched_alias_lists
175
406
def test_parse_alias_meta
229
482
assert_equal 'my attr', bar.comment
485
def test_parse_attr_accessor_nodoc
486
klass = RDoc::NormalClass.new 'Foo'
487
klass.parent = @top_level
489
comment = "##\n# my attr\n"
491
util_parser "attr_accessor :foo, :bar # :nodoc:"
495
@parser.parse_attr_accessor klass, RDoc::Parser::Ruby::NORMAL, tk, comment
497
assert_equal 0, klass.attributes.length
500
def test_parse_attr_accessor_stopdoc
501
klass = RDoc::NormalClass.new 'Foo'
502
klass.parent = @top_level
505
comment = "##\n# my attr\n"
507
util_parser "attr_accessor :foo, :bar"
511
@parser.parse_attr_accessor klass, RDoc::Parser::Ruby::NORMAL, tk, comment
513
assert_empty klass.attributes
232
516
def test_parse_attr_accessor_writer
233
517
klass = RDoc::NormalClass.new 'Foo'
234
518
klass.parent = @top_level
380
689
blah = foo.method_list.first
381
690
assert_equal 'Foo#blah', blah.full_name
691
assert_equal @top_level, blah.file
694
def test_parse_class_multi_ghost_methods
695
util_parser <<-'CLASS'
707
[:one, :two].each do |t|
708
eval("def #{t}; \"#{t}\"; end")
715
@parser.parse_class @top_level, RDoc::Parser::Ruby::NORMAL, tk, ''
717
foo = @top_level.classes.first
718
assert_equal 'Foo', foo.full_name
720
assert_equal 2, foo.method_list.length
723
def test_parse_class_nodoc
724
comment = "##\n# my class\n"
726
util_parser "class Foo # :nodoc:\nend"
730
@parser.parse_class @top_level, RDoc::Parser::Ruby::NORMAL, tk, comment
732
foo = @top_level.classes.first
733
assert_equal 'Foo', foo.full_name
734
assert_empty foo.comment
735
assert_equal [@top_level], foo.in_files
736
assert_equal 0, foo.offset
737
assert_equal 1, foo.line
740
def test_parse_class_stopdoc
743
comment = "##\n# my class\n"
745
util_parser "class Foo\nend"
749
@parser.parse_class @top_level, RDoc::Parser::Ruby::NORMAL, tk, comment
751
assert_empty @top_level.classes.first.comment
754
def test_parse_multi_ghost_methods
755
util_parser <<-'CLASS'
767
[:one, :two].each do |t|
768
eval("def #{t}; \"#{t}\"; end")
775
@parser.parse_class @top_level, RDoc::Parser::Ruby::NORMAL, tk, ''
777
foo = @top_level.classes.first
778
assert_equal 'Foo', foo.full_name
780
assert_equal 2, foo.method_list.length
783
def test_parse_const_fail_w_meta
791
OtherModule.define_attr(self, :one)
797
@parser.parse_class @top_level, RDoc::Parser::Ruby::NORMAL, tk, ''
799
const_fail_meta = @top_level.classes.first
800
assert_equal 'ConstFailMeta', const_fail_meta.full_name
802
assert_equal 1, const_fail_meta.attributes.length
384
805
def test_parse_class_nested_superclass
385
foo = RDoc::NormalModule.new 'Foo'
386
foo.parent = @top_level
807
foo = @top_level.add_module RDoc::NormalModule, 'Foo'
388
809
util_parser "class Bar < Super\nend"
398
819
def test_parse_module
399
820
comment = "##\n# my module\n"
401
util_parser 'module Foo; end'
822
util_parser "module Foo\nend"
826
@parser.parse_module @top_level, RDoc::Parser::Ruby::NORMAL, tk, comment
828
foo = @top_level.modules.first
829
assert_equal 'Foo', foo.full_name
830
assert_equal 'my module', foo.comment
833
def test_parse_module_nodoc
836
comment = "##\n# my module\n"
838
util_parser "module Foo # :nodoc:\nend"
842
@parser.parse_module @top_level, RDoc::Parser::Ruby::NORMAL, tk, comment
844
foo = @top_level.modules.first
845
assert_equal 'Foo', foo.full_name
846
assert_empty foo.comment
849
def test_parse_module_stopdoc
852
comment = "##\n# my module\n"
854
util_parser "module Foo\nend"
403
856
tk = @parser.get_tk
439
894
@parser.parse_class @top_level, false, @parser.get_tk, ''
441
896
assert_equal %w[A], RDoc::TopLevel.classes.map { |c| c.full_name }
442
assert_equal %w[A::B], RDoc::TopLevel.modules.map { |c| c.full_name }
897
assert_equal %w[A::B A::d], RDoc::TopLevel.modules.map { |c| c.full_name }
899
b = RDoc::TopLevel.modules.first
900
assert_equal 10, b.offset
901
assert_equal 2, b.line
903
# make sure method/alias was not added to enclosing class/module
904
a = RDoc::TopLevel.all_classes_hash['A']
905
assert_empty a.method_list
907
# make sure non-constant-named module will be removed from documentation
908
d = RDoc::TopLevel.all_modules_hash['A::d']
909
assert d.remove_from_documentation?
913
# TODO this is really a Context#add_class test
914
def test_parse_class_object
928
@parser.parse_module @top_level, false, @parser.get_tk, ''
930
assert_equal %w[A], RDoc::TopLevel.modules.map { |c| c.full_name }
931
assert_equal %w[A::B A::C A::Object], RDoc::TopLevel.classes.map { |c| c.full_name }.sort
932
assert_equal 'Object', RDoc::TopLevel.classes_hash['A::B'].superclass
933
assert_equal 'Object', RDoc::TopLevel.classes_hash['A::Object'].superclass
934
assert_equal 'A::Object', RDoc::TopLevel.classes_hash['A::C'].superclass.full_name
445
937
def test_parse_class_mistaken_for_module
542
1034
@parser.parse_comment klass, tk, comment
544
1036
foo = klass.attributes.first
545
assert_equal 'foo', foo.name
546
assert_equal 'RW', foo.rw
547
assert_equal 'my attr', foo.comment
549
assert_equal nil, foo.viewer
550
assert_equal true, foo.document_children
551
assert_equal true, foo.document_self
552
assert_equal false, foo.done_documenting
553
assert_equal false, foo.force_documentation
554
assert_equal klass, foo.parent
555
assert_equal :public, foo.visibility
556
assert_equal "\n", foo.text
1037
assert_equal 'foo', foo.name
1038
assert_equal 'RW', foo.rw
1039
assert_equal 'my attr', foo.comment
1040
assert_equal @top_level, foo.file
1041
assert_equal 0, foo.offset
1042
assert_equal 1, foo.line
1044
assert_equal nil, foo.viewer
1045
assert_equal true, foo.document_children
1046
assert_equal true, foo.document_self
1047
assert_equal false, foo.done_documenting
1048
assert_equal false, foo.force_documentation
1049
assert_equal klass, foo.parent
1050
assert_equal :public, foo.visibility
1051
assert_equal "\n", foo.text
557
1053
assert_equal klass.current_section, foo.section
1056
def test_parse_comment_attr_stopdoc
1057
klass = RDoc::NormalClass.new 'Foo'
1058
klass.parent = @top_level
1061
comment = "##\n# :attr: foo\n# my attr\n"
1067
@parser.parse_comment klass, tk, comment
1069
assert_empty klass.attributes
560
1072
def test_parse_comment_method
561
1073
klass = RDoc::NormalClass.new 'Foo'
562
1074
klass.parent = @top_level
599
1114
assert_equal stream, foo.token_stream
1117
def test_parse_comment_method_stopdoc
1118
klass = RDoc::NormalClass.new 'Foo'
1119
klass.parent = @top_level
1122
comment = "##\n# :method: foo\n# my method\n"
1128
@parser.parse_comment klass, tk, comment
1130
assert_empty klass.method_list
1133
def test_parse_constant
1136
klass = @top_level.add_class RDoc::NormalClass, 'Foo'
1142
@parser.parse_constant klass, tk, ''
1144
foo = klass.constants.first
1146
assert_equal 'A', foo.name
1147
assert_equal @top_level, foo.file
1148
assert_equal 0, foo.offset
1149
assert_equal 1, foo.line
1152
def test_parse_constant_attrasgn
1155
klass = @top_level.add_class RDoc::NormalClass, 'Foo'
1157
util_parser "A[k] = v"
1161
@parser.parse_constant klass, tk, ''
1163
assert klass.constants.empty?
602
1166
def test_parse_constant_alias
603
klass = RDoc::NormalClass.new 'Foo'
604
klass.parent = @top_level
1168
klass = @top_level.add_class RDoc::NormalClass, 'Foo'
605
1169
cB = klass.add_class RDoc::NormalClass, 'B'
607
1171
util_parser "A = B"
629
1193
assert_equal top_bar, bar.find_module_named('A')
1196
def test_parse_constant_stopdoc
1199
klass = @top_level.add_class RDoc::NormalClass, 'Foo'
1206
@parser.parse_constant klass, tk, ''
1208
assert_empty klass.constants
1211
def test_parse_include
1212
klass = RDoc::NormalClass.new 'C'
1213
klass.parent = @top_level
1215
comment = "# my include\n"
1217
util_parser "include I"
1219
@parser.get_tk # include
1221
@parser.parse_include klass, comment
1223
assert_equal 1, klass.includes.length
1225
incl = klass.includes.first
1226
assert_equal 'I', incl.name
1227
assert_equal 'my include', incl.comment
1228
assert_equal @top_level, incl.file
632
1231
def test_parse_meta_method
633
1232
klass = RDoc::NormalClass.new 'Foo'
634
1233
klass.parent = @top_level
826
1473
assert klass.aliases.empty?
829
def test_parse_method_utf8
830
klass = RDoc::NormalClass.new 'Foo'
831
klass.parent = @top_level
833
comment = "##\n# my method\n"
835
method = "def ω() end"
837
assert_equal Encoding::UTF_8, method.encoding if defined? ::Encoding
1476
def test_parse_method_false
1477
util_parser "def false.foo() :bar end"
841
1479
tk = @parser.get_tk
843
@parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment
845
omega = klass.method_list.first
846
assert_equal "def \317\211", omega.text
1481
@parser.parse_method @top_level, RDoc::Parser::Ruby::NORMAL, tk, ''
1483
klass = RDoc::TopLevel.find_class_named 'FalseClass'
1485
foo = klass.method_list.first
1486
assert_equal 'foo', foo.name
849
1489
def test_parse_method_funky
850
1490
klass = RDoc::NormalClass.new 'Foo'
851
1491
klass.parent = @top_level
853
comment = "##\n# my method\n"
855
1493
util_parser "def (blah).foo() :bar end"
857
1495
tk = @parser.get_tk
859
@parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment
1497
@parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, ''
861
1499
assert klass.method_list.empty?
1502
def test_parse_method_gvar
1503
util_parser "def $stdout.foo() :bar end"
1507
@parser.parse_method @top_level, RDoc::Parser::Ruby::NORMAL, tk, ''
1509
assert @top_level.method_list.empty?
1512
def test_parse_method_internal_gvar
1513
klass = RDoc::NormalClass.new 'Foo'
1514
klass.parent = @top_level
1516
util_parser "def foo() def $blah.bar() end end"
1520
@parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, ''
1522
assert_equal 1, klass.method_list.length
864
1525
def test_parse_method_internal_ivar
865
1526
klass = RDoc::NormalClass.new 'Foo'
866
1527
klass.parent = @top_level
887
1548
assert_equal 1, klass.method_list.length
1551
def test_parse_method_nil
1552
util_parser "def nil.foo() :bar end"
1556
@parser.parse_method @top_level, RDoc::Parser::Ruby::NORMAL, tk, ''
1558
klass = RDoc::TopLevel.find_class_named 'NilClass'
1560
foo = klass.method_list.first
1561
assert_equal 'foo', foo.name
890
1564
def test_parse_method_no_parens
891
1565
klass = RDoc::NormalClass.new 'Foo'
892
1566
klass.parent = @top_level
894
comment = "##\n# my method\n"
896
util_parser "def foo arg1, arg2\nend"
1568
util_parser "def foo arg1, arg2 = {}\nend"
898
1570
tk = @parser.get_tk
900
@parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment
1572
@parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, ''
902
1574
foo = klass.method_list.first
903
assert_equal '(arg1, arg2)', foo.params
1575
assert_equal '(arg1, arg2 = {})', foo.params
1576
assert_equal @top_level, foo.file
906
1579
def test_parse_method_parameters_comment
907
1580
klass = RDoc::NormalClass.new 'Foo'
908
1581
klass.parent = @top_level
910
comment = "##\n# my method\n"
912
1583
util_parser "def foo arg1, arg2 # some useful comment\nend"
914
1585
tk = @parser.get_tk
916
@parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment
1587
@parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, ''
918
1589
foo = klass.method_list.first
919
1590
assert_equal '(arg1, arg2)', foo.params
923
1594
klass = RDoc::NormalClass.new 'Foo'
924
1595
klass.parent = @top_level
926
comment = "##\n# my method\n"
928
1597
util_parser "def foo arg1, arg2, # some useful comment\narg3\nend"
930
1599
tk = @parser.get_tk
932
@parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment
1601
@parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, ''
934
1603
foo = klass.method_list.first
935
1604
assert_equal '(arg1, arg2, arg3)', foo.params
1607
def test_parse_method_stopdoc
1608
klass = RDoc::NormalClass.new 'Foo'
1609
klass.parent = @top_level
1612
comment = "##\n# my method\n"
1614
util_parser "def foo() :bar end"
1618
@parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment
1620
assert_empty klass.method_list
938
1623
def test_parse_method_toplevel
939
1624
klass = @top_level
941
comment = "##\n# my method\n"
943
1626
util_parser "def foo arg1, arg2\nend"
945
1628
tk = @parser.get_tk
947
@parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment
1630
@parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, ''
949
1632
object = RDoc::TopLevel.find_class_named 'Object'
951
1634
foo = object.method_list.first
952
1635
assert_equal 'Object#foo', foo.full_name
1636
assert_equal @top_level, foo.file
955
1639
def test_parse_method_toplevel_class
967
1651
assert_equal 'Object::foo', foo.full_name
1654
def test_parse_method_true
1655
util_parser "def true.foo() :bar end"
1659
@parser.parse_method @top_level, RDoc::Parser::Ruby::NORMAL, tk, ''
1661
klass = RDoc::TopLevel.find_class_named 'TrueClass'
1663
foo = klass.method_list.first
1664
assert_equal 'foo', foo.name
1667
def test_parse_method_utf8
1668
klass = RDoc::NormalClass.new 'Foo'
1669
klass.parent = @top_level
1671
method = "def ω() end"
1673
assert_equal Encoding::UTF_8, method.encoding if
1674
Object.const_defined? :Encoding
1680
@parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, ''
1682
omega = klass.method_list.first
1683
assert_equal "def \317\211", omega.text
970
1686
def test_parse_statements_class_if
971
comment = "##\n# my method\n"
973
1687
util_parser <<-CODE
975
1689
X = if TRUE then
1105
1861
FIFTH_CONSTANT = SECOND_CONSTANT.map { |element| element + 1 }
1863
SIXTH_CONSTANT = #{sixth_constant}
1865
SEVENTH_CONSTANT = proc { |i| begin i end }
1109
1869
util_parser content
1111
@parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil, ''
1871
@parser.parse_statements @top_level
1113
1873
constants = @top_level.classes.first.constants
1115
1875
constant = constants[0]
1116
1876
assert_equal 'FIRST_CONSTANT', constant.name
1117
1877
assert_equal '5', constant.value
1878
assert_equal @top_level, constant.file
1119
1880
constant = constants[1]
1120
1881
assert_equal 'SECOND_CONSTANT', constant.name
1121
assert_equal '[ 1, 2, 3 ]', constant.value
1882
assert_equal "[\n1,\n2,\n3\n]", constant.value
1883
assert_equal @top_level, constant.file
1123
1885
constant = constants[2]
1124
1886
assert_equal 'THIRD_CONSTANT', constant.name
1125
assert_equal "{ :foo => 'bar', :x => 'y' }", constant.value
1887
assert_equal "{\n:foo => 'bar',\n:x => 'y'\n}", constant.value
1888
assert_equal @top_level, constant.file
1127
1890
constant = constants[3]
1128
1891
assert_equal 'FOURTH_CONSTANT', constant.name
1129
assert_equal 'SECOND_CONSTANT.map do |element| element + 1 element + 2 end', constant.value
1892
assert_equal "SECOND_CONSTANT.map do |element|\nelement + 1\nelement + 2\nend", constant.value
1893
assert_equal @top_level, constant.file
1131
constant = constants.last
1895
constant = constants[4]
1132
1896
assert_equal 'FIFTH_CONSTANT', constant.name
1133
1897
assert_equal 'SECOND_CONSTANT.map { |element| element + 1 }', constant.value
1898
assert_equal @top_level, constant.file
1900
# TODO: parse as class
1901
constant = constants[5]
1902
assert_equal 'SIXTH_CONSTANT', constant.name
1903
assert_equal sixth_constant.lines.map(&:strip).join("\n"), constant.value
1904
assert_equal @top_level, constant.file
1906
# TODO: parse as method
1907
constant = constants[6]
1908
assert_equal 'SEVENTH_CONSTANT', constant.name
1909
assert_equal "proc { |i| begin i end }", constant.value
1910
assert_equal @top_level, constant.file
1136
1913
def test_parse_statements_identifier_attr
1137
content = "class Foo; attr :foo; end"
1914
content = "class Foo\nattr :foo\nend"
1139
1916
util_parser content
1141
@parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil, ''
1918
@parser.parse_statements @top_level
1143
1920
foo = @top_level.classes.first.attributes.first
1144
1921
assert_equal 'foo', foo.name
1172
1949
def test_parse_statements_identifier_module_function
1173
content = "module Foo def foo() end; module_function :foo; end"
1950
content = "module Foo\ndef foo() end\nmodule_function :foo\nend"
1175
1952
util_parser content
1177
@parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil, ''
1954
@parser.parse_statements @top_level
1179
1956
foo, s_foo = @top_level.modules.first.method_list
1180
assert_equal 'foo', foo.name, 'instance method name'
1957
assert_equal 'foo', foo.name, 'instance method name'
1181
1958
assert_equal :private, foo.visibility, 'instance method visibility'
1182
assert_equal false, foo.singleton, 'instance method singleton'
1959
assert_equal false, foo.singleton, 'instance method singleton'
1184
assert_equal 'foo', s_foo.name, 'module function name'
1961
assert_equal 'foo', s_foo.name, 'module function name'
1185
1962
assert_equal :public, s_foo.visibility, 'module function visibility'
1186
assert_equal true, s_foo.singleton, 'module function singleton'
1963
assert_equal true, s_foo.singleton, 'module function singleton'
1189
1966
def test_parse_statements_identifier_private
1190
content = "class Foo private; def foo() end end"
1967
content = "class Foo\nprivate\ndef foo() end\nend"
1192
1969
util_parser content
1194
@parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil, ''
1971
@parser.parse_statements @top_level
1196
1973
foo = @top_level.classes.first.method_list.first
1197
1974
assert_equal 'foo', foo.name
1198
1975
assert_equal :private, foo.visibility
1978
def test_parse_statements_identifier_public_class_method
1979
content = <<-CONTENT
1982
private_class_method :now
1985
class DateTime < Date
1986
public_class_method :now
1992
@parser.parse_statements @top_level
1994
date, date_time = @top_level.classes
1996
date_now = date.method_list.first
1997
date_time_now = date_time.method_list.first
1999
assert_equal :private, date_now.visibility
2000
assert_equal :public, date_time_now.visibility
2003
def test_parse_statements_identifier_private_class_method
2004
content = <<-CONTENT
2007
public_class_method :now
2010
class DateTime < Date
2011
private_class_method :now
2017
@parser.parse_statements @top_level
2019
date, date_time = @top_level.classes
2021
date_now = date.method_list.first
2022
date_time_now = date_time.method_list.first
2024
assert_equal :public, date_now.visibility, date_now.full_name
2025
assert_equal :private, date_time_now.visibility, date_time_now.full_name
1201
2028
def test_parse_statements_identifier_require
1202
2029
content = "require 'bar'"
1204
2031
util_parser content
1206
@parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil, ''
2033
@parser.parse_statements @top_level
1208
2035
assert_equal 1, @top_level.requires.length
2038
def test_parse_statements_stopdoc_TkALIAS
2041
klass = @top_level.add_class RDoc::NormalClass, 'Foo'
2043
util_parser "\n# :stopdoc:\nalias old new"
2045
@parser.parse_statements klass, RDoc::Parser::Ruby::NORMAL, nil
2047
assert_empty klass.aliases
2048
assert_empty klass.unmatched_alias_lists
2051
def test_parse_statements_stopdoc_TkIDENTIFIER_alias_method
2054
klass = @top_level.add_class RDoc::NormalClass, 'Foo'
2056
util_parser "\n# :stopdoc:\nalias_method :old :new"
2058
@parser.parse_statements klass, RDoc::Parser::Ruby::NORMAL, nil
2060
assert_empty klass.aliases
2061
assert_empty klass.unmatched_alias_lists
2064
def test_parse_statements_stopdoc_TkIDENTIFIER_metaprogrammed
2067
klass = @top_level.add_class RDoc::NormalClass, 'Foo'
2069
util_parser "\n# :stopdoc:\n# attr :meta"
2071
@parser.parse_statements klass, RDoc::Parser::Ruby::NORMAL, nil
2073
assert_empty klass.method_list
2074
assert_empty klass.attributes
2077
def test_parse_statements_stopdoc_TkCONSTANT
2080
klass = @top_level.add_class RDoc::NormalClass, 'Foo'
2082
util_parser "\n# :stopdoc:\nA = v"
2084
@parser.parse_statements klass, RDoc::Parser::Ruby::NORMAL, nil
2086
assert_empty klass.constants
2089
def test_parse_statements_stopdoc_TkDEF
2092
klass = @top_level.add_class RDoc::NormalClass, 'Foo'
2094
util_parser "\n# :stopdoc:\ndef m\n end"
2096
@parser.parse_statements klass, RDoc::Parser::Ruby::NORMAL, nil
2098
assert_empty klass.method_list
1211
2101
def test_parse_statements_while_begin
1212
2102
util_parser <<-RUBY
1250
2158
util_parser content
1252
2160
@parser.parse_statements @top_level
2162
# HACK where are the assertions?
2165
def test_parse_top_level_statements_stopdoc
2167
content = "# this is the top-level comment"
2171
@parser.parse_top_level_statements @top_level
2173
assert_empty @top_level.comment
2176
def test_parse_top_level_statements_stopdoc_integration
2177
content = <<-CONTENT
2188
@parser.parse_top_level_statements @top_level
2190
assert_equal 1, @top_level.classes.length
2191
assert_empty @top_level.modules
2193
assert @top_level.find_module_named('Example').ignored?
2196
# This tests parse_comment
2197
def test_parse_top_level_statements_constant_nodoc_integration
2198
content = <<-CONTENT
2206
@parser.parse_top_level_statements @top_level
2208
klass = @top_level.find_module_named('A')
2210
c = klass.constants.first
2212
assert_nil c.document_self, 'C should not be documented'
2215
def test_parse_yield_in_braces_with_parens
2216
klass = RDoc::NormalClass.new 'Foo'
2217
klass.parent = @top_level
2219
util_parser "def foo\nn.times { |i| yield nth(i) }\nend"
2223
@parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, ''
2225
foo = klass.method_list.first
2226
assert_equal 'nth(i)', foo.block_params
1255
2229
def test_sanity_integer
1290
2262
def test_sanity_interpolation_format
1291
2263
util_parser '"#{stftime("%m-%d")}"'
1293
while tk = @parser.get_tk do end
2265
while @parser.get_tk do end
1296
2268
def test_sanity_symbol_interpolation
1297
2269
util_parser ':"#{bar}="'
1299
while tk = @parser.get_tk do end
2271
while @parser.get_tk do end
2275
content = <<-CONTENT
2288
c = @top_level.classes.first
2290
assert_equal 1, c.method_list.length
2293
def test_scan_block_comment
2294
content = <<-CONTENT
2313
foo = @top_level.classes.first
2315
assert_equal 'Foo comment', foo.comment
2317
m = foo.method_list.first
2319
assert_equal 'm comment', m.comment
2322
def test_scan_block_comment_nested # Issue #41
2323
content = <<-CONTENT
2338
foo = @top_level.modules.first
2340
assert_equal 'Foo', foo.full_name
2341
assert_equal 'findmeindoc', foo.comment
2343
bar = foo.classes.first
2345
assert_equal 'Foo::Bar', bar.full_name
2346
assert_equal '', bar.comment
2349
def test_scan_block_comment_notflush
2352
# The previous test assumes that between the =begin/=end blocs that there is
2353
# only one line, or minima formatting directives. This test tests for those
2354
# who use the =begin bloc with longer / more advanced formatting within.
2357
content = <<-CONTENT
2362
This is a simple test class
2369
class StevenSimpleClass
2370
# A band on my iPhone as I wrote this test
2371
FRUIT_BATS="Make nice music"
2378
puts "Summoning Lauren!"
2386
foo = @top_level.classes.first
2388
assert_equal "= DESCRIPTION\n\nThis is a simple test class\n\n= RUMPUS\n\nIs a silly word",
2391
m = foo.method_list.first
2393
assert_equal 'A nice girl', m.comment
2396
def test_scan_meta_method_block
2397
content = <<-CONTENT
2403
inline(:my_method) do |*args|
2404
"this method used to cause z to disappear"
2415
assert_equal 2, @top_level.classes.first.method_list.length
2418
def test_stopdoc_after_comment
2432
@parser.parse_statements @top_level
2434
foo = @top_level.modules.first.modules.first
2435
assert_equal 'Foo', foo.name
2436
assert_equal 'hello', foo.comment
2438
baz = @top_level.modules.first.classes.first
2439
assert_equal 'Baz', baz.name
2440
assert_equal 'there', baz.comment
1302
2443
def tk(klass, line, char, name, text)