55require 'fileutils'
66require 'stringio'
77require 'rdoc/ri/driver'
8+ require 'rdoc/rdoc'
89
910class TestRDocRIDriver < MiniTest ::Unit ::TestCase
1011
@@ -223,7 +224,7 @@ def test_add_method_list_interative
223224 def test_add_method_list_none
224225 out = @RM ::Document . new
225226
226- @driver . add_method_list out , nil , 'Class'
227+ @driver . add_method_list out , [ ] , 'Class'
227228
228229 assert_equal @RM ::Document . new , out
229230 end
@@ -249,6 +250,46 @@ def test_classes
249250 assert_equal expected , @driver . classes
250251 end
251252
253+ def test_class_document
254+ util_store
255+
256+ tl1 = RDoc ::TopLevel . new 'one.rb'
257+ tl2 = RDoc ::TopLevel . new 'two.rb'
258+
259+ @cFoo . add_comment 'one' , tl1
260+ @cFoo . add_comment 'two' , tl2
261+ @store . save_class @cFoo
262+
263+ found = [
264+ [ @store , @store . load_class ( @cFoo . full_name ) ]
265+ ]
266+
267+ out = @driver . class_document @cFoo . full_name , found , [ ] , [ ]
268+
269+ expected = @RM ::Document . new
270+ @driver . add_class expected , 'Foo' , [ ]
271+ @driver . add_includes expected , [ ]
272+ @driver . add_from expected , @store
273+ expected << @RM ::Rule . new ( 1 )
274+
275+ doc = @RM ::Document . new ( @RM ::Paragraph . new ( 'one' ) )
276+ doc . file = 'one.rb'
277+ expected . push doc
278+ expected << @RM ::BlankLine . new
279+ doc = @RM ::Document . new ( @RM ::Paragraph . new ( 'two' ) )
280+ doc . file = 'two.rb'
281+ expected . push doc
282+
283+ expected << @RM ::Rule . new ( 1 )
284+ expected << @RM ::Heading . new ( 1 , 'Instance methods:' )
285+ expected << @RM ::BlankLine . new
286+ expected << @RM ::Verbatim . new ( 'inherit' )
287+ expected << @RM ::Verbatim . new ( 'override' )
288+ expected << @RM ::BlankLine . new
289+
290+ assert_equal expected , out
291+ end
292+
252293 def test_complete
253294 store = RDoc ::RI ::Store . new @home_ri
254295 store . cache [ :ancestors ] = {
@@ -633,8 +674,24 @@ def test_list_known_classes_name
633674 def test_list_methods_matching
634675 util_store
635676
636- assert_equal %w[ Foo::Bar#attr Foo::Bar#blah Foo::Bar#bother Foo::Bar::new ] ,
637- @driver . list_methods_matching ( 'Foo::Bar.' )
677+ assert_equal %w[
678+ Foo::Bar#attr
679+ Foo::Bar#blah
680+ Foo::Bar#bother
681+ Foo::Bar::new
682+ ] ,
683+ @driver . list_methods_matching ( 'Foo::Bar.' ) . sort
684+ end
685+
686+ def test_list_methods_matching_inherit
687+ util_multi_store
688+
689+ assert_equal %w[
690+ Bar#baz
691+ Bar#inherit
692+ Bar#override
693+ ] ,
694+ @driver . list_methods_matching ( 'Bar.' ) . sort
638695 end
639696
640697 def test_list_methods_matching_regexp
@@ -900,29 +957,28 @@ def util_ancestors_store
900957
901958 def util_multi_store
902959 util_store
960+
903961 @store1 = @store
904962
963+ @top_level = RDoc ::TopLevel . new 'file.rb'
964+
905965 @home_ri2 = "#{ @home_ri } 2"
906966 @store2 = RDoc ::RI ::Store . new @home_ri2
907967
908968 # as if seen in a namespace like class Ambiguous::Other
909- @mAmbiguous = RDoc ::NormalModule . new 'Ambiguous'
969+ @mAmbiguous = @top_level . add_module RDoc ::NormalModule , 'Ambiguous'
910970
911- @cFoo = RDoc ::NormalClass . new 'Foo'
971+ @cFoo = @top_level . add_class RDoc ::NormalClass , 'Foo'
912972
913- @cBar = RDoc ::NormalClass . new 'Bar'
914- @cBar . superclass = 'Foo'
915- @cFoo_Baz = RDoc ::NormalClass . new 'Baz'
916- @cFoo_Baz . parent = @cFoo
973+ @cBar = @top_level . add_class RDoc ::NormalClass , 'Bar' , 'Foo'
974+ @cFoo_Baz = @cFoo . add_class RDoc ::NormalClass , 'Baz'
917975
918- @baz = RDoc ::AnyMethod . new nil , 'baz'
976+ @baz = @cBar . add_method RDoc ::AnyMethod . new ( nil , 'baz' )
919977 @baz . record_location @top_level
920- @cBar . add_method @baz
921978
922- @override = RDoc ::AnyMethod . new nil , 'override'
979+ @override = @cBar . add_method RDoc ::AnyMethod . new ( nil , 'override' )
923980 @override . comment = 'must be displayed'
924981 @override . record_location @top_level
925- @cBar . add_method @override
926982
927983 @store2 . save_class @mAmbiguous
928984 @store2 . save_class @cBar
@@ -934,60 +990,51 @@ def util_multi_store
934990 @store2 . save_cache
935991
936992 @driver . stores = [ @store1 , @store2 ]
993+
994+ RDoc ::RDoc . reset
937995 end
938996
939997 def util_store
940998 @store = RDoc ::RI ::Store . new @home_ri
941999
9421000 @top_level = RDoc ::TopLevel . new 'file.rb'
9431001
944- @cFoo = RDoc ::NormalClass . new 'Foo'
945- @mInc = RDoc ::NormalModule . new 'Inc'
946- @cAmbiguous = RDoc ::NormalClass . new 'Ambiguous'
1002+ @cFoo = @top_level . add_class RDoc ::NormalClass , 'Foo'
1003+ @mInc = @top_level . add_module RDoc ::NormalModule , 'Inc'
1004+ @cAmbiguous = @top_level . add_class RDoc ::NormalClass , 'Ambiguous'
9471005
9481006 doc = @RM ::Document . new @RM ::Paragraph . new ( 'Include thingy' )
949-
950- @cFooInc = RDoc ::Include . new 'Inc' , doc
1007+ @cFooInc = @cFoo . add_include RDoc ::Include . new ( 'Inc' , doc )
9511008 @cFooInc . record_location @top_level
952- @cFoo . add_include @cFooInc
9531009
954- @cFoo_Bar = RDoc ::NormalClass . new 'Bar'
955- @cFoo_Bar . parent = @cFoo
1010+ @cFoo_Bar = @cFoo . add_class RDoc ::NormalClass , 'Bar'
9561011
957- @blah = RDoc ::AnyMethod . new nil , 'blah'
1012+ @blah = @cFoo_Bar . add_method RDoc ::AnyMethod . new ( nil , 'blah' )
9581013 @blah . call_seq = "blah(5) => 5\n blah(6) => 6\n "
9591014 @blah . record_location @top_level
9601015
961- @bother = RDoc ::AnyMethod . new nil , 'bother'
1016+ @bother = @cFoo_Bar . add_method RDoc ::AnyMethod . new ( nil , 'bother' )
9621017 @bother . block_params = "stuff"
9631018 @bother . params = "(things)"
9641019 @bother . record_location @top_level
9651020
966- @new = RDoc ::AnyMethod . new nil , 'new'
1021+ @new = @cFoo_Bar . add_method RDoc ::AnyMethod . new nil , 'new'
9671022 @new . record_location @top_level
9681023 @new . singleton = true
9691024
970- @cFoo_Bar . add_method @blah
971- @cFoo_Bar . add_method @bother
972- @cFoo_Bar . add_method @new
973-
974- @attr = RDoc ::Attr . new nil , 'attr' , 'RW' , ''
1025+ @attr = @cFoo_Bar . add_attribute RDoc ::Attr . new nil , 'attr' , 'RW' , ''
9751026 @attr . record_location @top_level
9761027
977- @cFoo_Bar . add_attribute @attr
1028+ @cFoo_Baz = @cFoo . add_class RDoc ::NormalClass , 'Baz'
1029+ @cFoo_Baz . record_location @top_level
9781030
979- @cFoo_Baz = RDoc ::NormalClass . new 'Baz'
980- @cFoo_Baz . parent = @cFoo
981-
982- @inherit = RDoc ::AnyMethod . new nil , 'inherit'
1031+ @inherit = @cFoo . add_method RDoc ::AnyMethod . new ( nil , 'inherit' )
9831032 @inherit . record_location @top_level
984- @cFoo . add_method @inherit
9851033
9861034 # overriden by Bar in multi_store
987- @overriden = RDoc ::AnyMethod . new nil , 'override'
1035+ @overriden = @cFoo . add_method RDoc ::AnyMethod . new ( nil , 'override' )
9881036 @overriden . comment = 'must not be displayed'
9891037 @overriden . record_location @top_level
990- @cFoo . add_method @overriden
9911038
9921039 @store . save_class @cFoo
9931040 @store . save_class @cFoo_Bar
@@ -1006,6 +1053,8 @@ def util_store
10061053 @store . save_cache
10071054
10081055 @driver . stores = [ @store ]
1056+
1057+ RDoc ::RDoc . reset
10091058 end
10101059
10111060end
0 commit comments