From 0b6da24a5e24ff9ce8e153d2f073c2363e94b28e Mon Sep 17 00:00:00 2001 From: drbrain Date: Sat, 14 May 2011 00:39:16 +0000 Subject: * lib/rdoc.rb: Updated to RDoc 3.6 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31558 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/rdoc/test_rdoc_class_module.rb | 17 ++++ test/rdoc/test_rdoc_code_object.rb | 10 +++ test/rdoc/test_rdoc_context.rb | 151 +++++++++++++++++++++++++++++++++++ test/rdoc/test_rdoc_markup_parser.rb | 19 +++++ test/rdoc/test_rdoc_parser_c.rb | 33 +++++++- test/rdoc/test_rdoc_parser_ruby.rb | 97 ++++++++++++++++++++++ test/rdoc/test_rdoc_ri_driver.rb | 51 ++++++++++-- test/rdoc/test_rdoc_top_level.rb | 6 +- test/rdoc/xref_data.rb | 9 +++ test/rdoc/xref_test_case.rb | 7 +- 10 files changed, 391 insertions(+), 9 deletions(-) (limited to 'test/rdoc') diff --git a/test/rdoc/test_rdoc_class_module.rb b/test/rdoc/test_rdoc_class_module.rb index e7a68c2b4c..59190a6e3b 100644 --- a/test/rdoc/test_rdoc_class_module.rb +++ b/test/rdoc/test_rdoc_class_module.rb @@ -8,6 +8,10 @@ class TestRDocClassModule < XrefTestCase @RM = RDoc::Markup end + def test_ancestors + assert_equal [@parent], @child.ancestors + end + def test_comment_equals cm = RDoc::ClassModule.new 'Klass' cm.comment = '# comment 1' @@ -23,6 +27,16 @@ class TestRDocClassModule < XrefTestCase assert_equal "comment 1\n---\ncomment 2\n---\n* comment 3", cm.comment end + def test_each_ancestor + ancestors = [] + + @child.each_ancestor do |mod| + ancestors << mod + end + + assert_equal [@parent], ancestors + end + # handle making a short module alias of yourself def test_find_class_named @@ -36,6 +50,7 @@ class TestRDocClassModule < XrefTestCase cm1.comment = 'klass 1' cm1.add_attribute RDoc::Attr.new(nil, 'a1', 'RW', '') cm1.add_attribute RDoc::Attr.new(nil, 'a3', 'R', '') + cm1.add_attribute RDoc::Attr.new(nil, 'a4', 'R', '') cm1.add_constant RDoc::Constant.new('C1', nil, '') cm1.add_include RDoc::Include.new('I1', '') cm1.add_method RDoc::AnyMethod.new(nil, 'm1') @@ -46,6 +61,7 @@ class TestRDocClassModule < XrefTestCase @RM::Paragraph.new('klass 2'))) cm2.add_attribute RDoc::Attr.new(nil, 'a2', 'RW', '') cm2.add_attribute RDoc::Attr.new(nil, 'a3', 'W', '') + cm2.add_attribute RDoc::Attr.new(nil, 'a4', 'R', '') cm2.add_constant RDoc::Constant.new('C2', nil, '') cm2.add_include RDoc::Include.new('I2', '') cm2.add_method RDoc::AnyMethod.new(nil, 'm2') @@ -62,6 +78,7 @@ class TestRDocClassModule < XrefTestCase RDoc::Attr.new(nil, 'a1', 'RW', ''), RDoc::Attr.new(nil, 'a2', 'RW', ''), RDoc::Attr.new(nil, 'a3', 'RW', ''), + RDoc::Attr.new(nil, 'a4', 'R', ''), ] expected.each do |a| a.parent = cm1 end diff --git a/test/rdoc/test_rdoc_code_object.rb b/test/rdoc/test_rdoc_code_object.rb index 5328ab26b1..b4ebfc4b3e 100644 --- a/test/rdoc/test_rdoc_code_object.rb +++ b/test/rdoc/test_rdoc_code_object.rb @@ -119,6 +119,16 @@ class TestRDocCodeObject < XrefTestCase assert @co.document_children end + def test_each_parent + parents = [] + + @parent_m.each_parent do |code_object| + parents << code_object + end + + assert_equal [@parent, @xref_data], parents + end + def test_full_name_equals @co.full_name = 'hi' diff --git a/test/rdoc/test_rdoc_context.rb b/test/rdoc/test_rdoc_context.rb index 71870c545f..02f7311d01 100644 --- a/test/rdoc/test_rdoc_context.rb +++ b/test/rdoc/test_rdoc_context.rb @@ -143,6 +143,16 @@ class TestRDocContext < XrefTestCase assert_equal [incl], @context.includes end + def test_add_include_twice + incl1 = RDoc::Include.new 'Name', 'comment' + @context.add_include incl1 + + incl2 = RDoc::Include.new 'Name', 'comment' + @context.add_include incl2 + + assert_equal [incl1], @context.includes + end + def test_add_method meth = RDoc::AnyMethod.new nil, 'old_name' meth.visibility = nil @@ -438,5 +448,146 @@ class TestRDocContext < XrefTestCase assert_equal expected, @c1.methods_by_type(separate) end + def test_methods_matching + methods = [] + + @parent.methods_matching 'm' do |m| + methods << m + end + + assert_equal [@parent_m], methods + end + + def test_methods_matching_singleton + methods = [] + + @parent.methods_matching 'm', true do |m| + methods << m + end + + assert_equal [@parent__m], methods + end + + def test_methods_matching_inherit + methods = [] + + @child.methods_matching 'm' do |m| + methods << m + end + + assert_equal [@parent_m], methods + end + + def test_remove_invisible_private + util_visibilities + + @vis.remove_invisible :private + + assert_equal [@pub, @prot, @priv], @vis.method_list + assert_equal [@apub, @aprot, @apriv], @vis.attributes + end + + def test_remove_invisible_protected + util_visibilities + + @vis.remove_invisible :protected + + assert_equal [@pub, @prot], @vis.method_list + assert_equal [@apub, @aprot], @vis.attributes + end + + def test_remove_invisible_public + util_visibilities + + @vis.remove_invisible :public + + assert_equal [@pub], @vis.method_list + assert_equal [@apub], @vis.attributes + end + + def test_remove_invisible_public_force + util_visibilities + + @priv.force_documentation = true + @prot.force_documentation = true + @apriv.force_documentation = true + @aprot.force_documentation = true + + @vis.remove_invisible :public + + assert_equal [@pub, @prot, @priv], @vis.method_list + assert_equal [@apub, @aprot, @apriv], @vis.attributes + end + + def test_remove_invisible_in_protected + util_visibilities + + methods = [@pub, @prot, @priv] + + @c1.remove_invisible_in methods, :protected + + assert_equal [@pub, @prot], methods + end + + def test_remove_invisible_in_protected_force + util_visibilities + + @priv.force_documentation = true + + methods = [@pub, @prot, @priv] + + @c1.remove_invisible_in methods, :protected + + assert_equal [@pub, @prot, @priv], methods + end + + def test_remove_invisible_in_public + util_visibilities + + methods = [@pub, @prot, @priv] + + @c1.remove_invisible_in methods, :public + + assert_equal [@pub], methods + end + + def test_remove_invisible_in_public_force + util_visibilities + + @prot.force_documentation = true + @priv.force_documentation = true + + methods = [@pub, @prot, @priv] + + @c1.remove_invisible_in methods, :public + + assert_equal [@pub, @prot, @priv], methods + end + + def util_visibilities + @pub = RDoc::AnyMethod.new nil, 'pub' + @prot = RDoc::AnyMethod.new nil, 'prot' + @priv = RDoc::AnyMethod.new nil, 'priv' + + @apub = RDoc::Attr.new nil, 'pub', 'RW', nil + @aprot = RDoc::Attr.new nil, 'prot', 'RW', nil + @apriv = RDoc::Attr.new nil, 'priv', 'RW', nil + + @vis = RDoc::NormalClass.new 'Vis' + @vis.add_method @pub + @vis.add_method @prot + @vis.add_method @priv + + @vis.add_attribute @apub + @vis.add_attribute @aprot + @vis.add_attribute @apriv + + @prot.visibility = :protected + @priv.visibility = :private + + @aprot.visibility = :protected + @apriv.visibility = :private + end + end diff --git a/test/rdoc/test_rdoc_markup_parser.rb b/test/rdoc/test_rdoc_markup_parser.rb index a7951d9d01..98c16a18ef 100644 --- a/test/rdoc/test_rdoc_markup_parser.rb +++ b/test/rdoc/test_rdoc_markup_parser.rb @@ -625,6 +625,25 @@ for all good men assert_equal expected, @RMP.parse(str).parts end + def test_parse_rule + str = <<-STR +now is the time + +--- + +for all good men + STR + + expected = [ + @RM::Paragraph.new('now is the time'), + @RM::BlankLine.new, + @RM::Rule.new(1), + @RM::BlankLine.new, + @RM::Paragraph.new('for all good men')] + + assert_equal expected, @RMP.parse(str).parts + end + def test_parse_ualpha str = <<-STR A. l1 diff --git a/test/rdoc/test_rdoc_parser_c.rb b/test/rdoc/test_rdoc_parser_c.rb index 6a3a92001a..9649933fd0 100644 --- a/test/rdoc/test_rdoc_parser_c.rb +++ b/test/rdoc/test_rdoc_parser_c.rb @@ -680,7 +680,7 @@ Init_Foo(void) { baz = methods.last assert_equal 'Foo#baz', baz.full_name - assert_equal "a comment for bar", bar.comment + assert_equal "a comment for bar", baz.comment end def test_find_modifiers_call_seq @@ -911,6 +911,37 @@ rb_io_s_read(argc, argv, io) { } +void +Init_IO(void) { + /* + * a comment for class Foo on rb_define_class + */ + VALUE rb_cIO = rb_define_class("IO", rb_cObject); + rb_define_singleton_method(rb_cIO, "read", rb_io_s_read, -1); +} + EOF + + klass = util_get_class content, 'rb_cIO' + read_method = klass.method_list.first + assert_equal "read", read_method.name + assert_equal "Method Comment! ", read_method.comment + assert_equal "rb_io_s_read", read_method.c_function + assert read_method.singleton + end + + def test_define_method_with_prototype + content = <<-EOF +static VALUE rb_io_s_read(int, VALUE*, VALUE); + +/* Method Comment! */ +static VALUE +rb_io_s_read(argc, argv, io) + int argc; + VALUE *argv; + VALUE io; +{ +} + void Init_IO(void) { /* diff --git a/test/rdoc/test_rdoc_parser_ruby.rb b/test/rdoc/test_rdoc_parser_ruby.rb index ff1f1c9191..6c2b445ef3 100644 --- a/test/rdoc/test_rdoc_parser_ruby.rb +++ b/test/rdoc/test_rdoc_parser_ruby.rb @@ -1799,6 +1799,56 @@ EOF assert_equal :private, foo.visibility end + def test_parse_statements_identifier_public_class_method + content = <<-CONTENT +class Date + def self.now; end + private_class_method :now +end + +class DateTime < Date + public_class_method :now +end + CONTENT + + util_parser content + + @parser.parse_statements @top_level + + date, date_time = @top_level.classes + + date_now = date.method_list.first + date_time_now = date_time.method_list.first + + assert_equal :private, date_now.visibility + assert_equal :public, date_time_now.visibility + end + + def test_parse_statements_identifier_private_class_method + content = <<-CONTENT +class Date + def self.now; end + public_class_method :now +end + +class DateTime < Date + private_class_method :now +end + CONTENT + + util_parser content + + @parser.parse_statements @top_level + + date, date_time = @top_level.classes + + date_now = date.method_list.first + date_time_now = date_time.method_list.first + + assert_equal :public, date_now.visibility, date_now.full_name + assert_equal :private, date_time_now.visibility, date_time_now.full_name + end + def test_parse_statements_identifier_require content = "require 'bar'" @@ -1978,6 +2028,53 @@ end assert_equal 'm comment', m.comment end + def test_scan_block_comment_notflush + ## + # + # The previous test assumes that between the =begin/=end blocs that there is + # only one line, or minima formatting directives. This test tests for those + # who use the =begin bloc with longer / more advanced formatting within. + # + ## + content = <<-CONTENT +=begin rdoc + += DESCRIPTION + +This is a simple test class + += RUMPUS + +Is a silly word + +=end +class StevenSimpleClass + # A band on my iPhone as I wrote this test + FRUIT_BATS="Make nice music" + +=begin rdoc +A nice girl +=end + + def lauren + puts "Summoning Lauren!" + end +end + CONTENT + util_parser content + + @parser.scan + + foo = @top_level.classes.first + + assert_equal "= DESCRIPTION\n\nThis is a simple test class\n\n= RUMPUS\n\nIs a silly word", + foo.comment + + m = foo.method_list.first + + assert_equal 'A nice girl', m.comment + end + def test_scan_meta_method_block content = <<-CONTENT class C diff --git a/test/rdoc/test_rdoc_ri_driver.rb b/test/rdoc/test_rdoc_ri_driver.rb index 2d735044dd..b0e0e787c0 100644 --- a/test/rdoc/test_rdoc_ri_driver.rb +++ b/test/rdoc/test_rdoc_ri_driver.rb @@ -3,6 +3,7 @@ require 'rubygems' require 'minitest/autorun' require 'tmpdir' require 'fileutils' +require 'stringio' require 'rdoc/ri/driver' class TestRDocRIDriver < MiniTest::Unit::TestCase @@ -249,12 +250,14 @@ class TestRDocRIDriver < MiniTest::Unit::TestCase @driver.stores = [store] - assert_equal %w[Foo Foo::Bar], @driver.complete('F') + assert_equal %w[Foo ], @driver.complete('F') assert_equal %w[ Foo::Bar], @driver.complete('Foo::B') - assert_equal %w[Foo#Bar], @driver.complete('Foo#'), 'Foo#' - assert_equal %w[Foo#Bar Foo::bar], @driver.complete('Foo.'), 'Foo.' - assert_equal %w[Foo::Bar Foo::bar], @driver.complete('Foo::'), 'Foo::' + assert_equal %w[Foo#Bar], @driver.complete('Foo#'), 'Foo#' + assert_equal %w[Foo#Bar Foo::bar], @driver.complete('Foo.'), 'Foo.' + assert_equal %w[Foo::Bar Foo::bar], @driver.complete('Foo::'), 'Foo::' + + assert_equal %w[ Foo::bar], @driver.complete('Foo::b'), 'Foo::b' end def test_complete_ancestor @@ -269,7 +272,7 @@ class TestRDocRIDriver < MiniTest::Unit::TestCase def test_complete_classes util_store - assert_equal %w[Foo Foo::Bar Foo::Baz], @driver.complete('F') + assert_equal %w[Foo ], @driver.complete('F') assert_equal %w[Foo:: Foo::Bar Foo::Baz], @driver.complete('Foo::') assert_equal %w[ Foo::Bar Foo::Baz], @driver.complete('Foo::B') end @@ -278,7 +281,8 @@ class TestRDocRIDriver < MiniTest::Unit::TestCase util_multi_store assert_equal %w[Bar], @driver.complete('B') - assert_equal %w[Foo Foo::Bar Foo::Baz], @driver.complete('F') + assert_equal %w[Foo], @driver.complete('F') + assert_equal %w[Foo::Bar Foo::Baz], @driver.complete('Foo::B') end def test_display @@ -572,11 +576,18 @@ Foo::Bar#bother def test_name_regexp assert_equal %r%^RDoc::AnyMethod#new$%, @driver.name_regexp('RDoc::AnyMethod#new') + assert_equal %r%^RDoc::AnyMethod::new$%, @driver.name_regexp('RDoc::AnyMethod::new') assert_equal %r%^RDoc::AnyMethod(#|::)new$%, @driver.name_regexp('RDoc::AnyMethod.new') + + assert_equal %r%^Hash(#|::)\[\]$%, + @driver.name_regexp('Hash.[]') + + assert_equal %r%^Hash::\[\]$%, + @driver.name_regexp('Hash::[]') end def test_list_known_classes @@ -589,6 +600,16 @@ Foo::Bar#bother assert_equal "Ambiguous\nFoo\nFoo::Bar\nFoo::Baz\nInc\n", out end + def test_list_known_classes_name + util_store + + out, = capture_io do + @driver.list_known_classes %w[F I] + end + + assert_equal "Foo\nFoo::Bar\nFoo::Baz\nInc\n", out + end + def test_list_methods_matching util_store @@ -596,6 +617,24 @@ Foo::Bar#bother @driver.list_methods_matching('Foo::Bar.') end + def test_list_methods_matching_regexp + util_store + + index = RDoc::AnyMethod.new nil, '[]' + @cFoo.add_method index + @store.save_method @cFoo, index + + c_index = RDoc::AnyMethod.new nil, '[]' + c_index.singleton = true + @cFoo.add_method c_index + @store.save_method @cFoo, c_index + + @store.save_cache + + assert_equal %w[Foo#[]], @driver.list_methods_matching('Foo#[]') + assert_equal %w[Foo::[]], @driver.list_methods_matching('Foo::[]') + end + def test_load_method util_store diff --git a/test/rdoc/test_rdoc_top_level.rb b/test/rdoc/test_rdoc_top_level.rb index a1eef0fa22..89f64247f9 100644 --- a/test/rdoc/test_rdoc_top_level.rb +++ b/test/rdoc/test_rdoc_top_level.rb @@ -12,7 +12,10 @@ class TestRDocTopLevel < XrefTestCase def test_class_all_classes_and_modules expected = %w[ - C1 C2 C2::C3 C2::C3::H1 C3 C3::H1 C3::H2 C4 C4::C4 C5 C5::C1 M1 M1::M2 + C1 C2 C2::C3 C2::C3::H1 C3 C3::H1 C3::H2 C4 C4::C4 C5 C5::C1 + Child + M1 M1::M2 + Parent ] assert_equal expected, @@ -22,6 +25,7 @@ class TestRDocTopLevel < XrefTestCase def test_class_classes expected = %w[ C1 C2 C2::C3 C2::C3::H1 C3 C3::H1 C3::H2 C4 C4::C4 C5 C5::C1 + Child Parent ] assert_equal expected, RDoc::TopLevel.classes.map { |m| m.full_name }.sort diff --git a/test/rdoc/xref_data.rb b/test/rdoc/xref_data.rb index 5a7e98d671..4525a293ab 100644 --- a/test/rdoc/xref_data.rb +++ b/test/rdoc/xref_data.rb @@ -63,5 +63,14 @@ end module M1::M2 end + +class Parent + def m() end + def self.m() end +end + +class Child < Parent +end + XREF_DATA diff --git a/test/rdoc/xref_test_case.rb b/test/rdoc/xref_test_case.rb index 307e8f3350..00c6e8e09d 100644 --- a/test/rdoc/xref_test_case.rb +++ b/test/rdoc/xref_test_case.rb @@ -38,7 +38,6 @@ class XrefTestCase < MiniTest::Unit::TestCase @c1_m = @c1.method_list.last # C1#m @c1__m = @c1.method_list.first # C1::m - @c2 = @xref_data.find_module_named 'C2' @c2_a = @c2.method_list.last @c2_b = @c2.method_list.first @@ -55,6 +54,12 @@ class XrefTestCase < MiniTest::Unit::TestCase @m1_m = @m1.method_list.first @m1_m2 = @xref_data.find_module_named 'M1::M2' + + @parent = @xref_data.find_module_named 'Parent' + @child = @xref_data.find_module_named 'Child' + + @parent_m = @parent.method_list.first # Parent#m + @parent__m = @parent.method_list.last # Parent::m end end -- cgit v1.2.3