From b7528b5edb1f9148ea00ebb6151720e5943b3f0b Mon Sep 17 00:00:00 2001 From: drbrain Date: Thu, 16 Jun 2011 04:59:24 +0000 Subject: * lib/rdoc.rb: Import RDoc 3.7 release candidate git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32115 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/rdoc/test_rdoc_any_method.rb | 68 ++++ test/rdoc/test_rdoc_attr.rb | 62 +++ test/rdoc/test_rdoc_class_module.rb | 488 +++++++++++++++++++++-- test/rdoc/test_rdoc_code_object.rb | 17 + test/rdoc/test_rdoc_context.rb | 70 ++++ test/rdoc/test_rdoc_generator_ri.rb | 17 +- test/rdoc/test_rdoc_markup.rb | 25 +- test/rdoc/test_rdoc_markup_document.rb | 77 ++++ test/rdoc/test_rdoc_markup_indented_paragraph.rb | 40 ++ test/rdoc/test_rdoc_markup_paragraph.rb | 12 + test/rdoc/test_rdoc_markup_pre_process.rb | 21 + test/rdoc/test_rdoc_markup_to_ansi.rb | 4 + test/rdoc/test_rdoc_markup_to_bs.rb | 4 + test/rdoc/test_rdoc_markup_to_html.rb | 10 +- test/rdoc/test_rdoc_markup_to_rdoc.rb | 14 + test/rdoc/test_rdoc_markup_to_tt_only.rb | 4 + test/rdoc/test_rdoc_parser_c.rb | 304 +++++++++++++- test/rdoc/test_rdoc_parser_ruby.rb | 47 +++ test/rdoc/test_rdoc_rdoc.rb | 51 ++- test/rdoc/test_rdoc_ri_driver.rb | 47 ++- test/rdoc/test_rdoc_ri_store.rb | 134 +++++-- test/rdoc/test_rdoc_rubygems_hook.rb | 201 ++++++++++ test/rdoc/test_rdoc_stats.rb | 24 +- test/rdoc/test_rdoc_text.rb | 17 + test/rdoc/test_rdoc_top_level.rb | 35 ++ 25 files changed, 1703 insertions(+), 90 deletions(-) create mode 100644 test/rdoc/test_rdoc_markup_indented_paragraph.rb create mode 100644 test/rdoc/test_rdoc_rubygems_hook.rb (limited to 'test/rdoc') diff --git a/test/rdoc/test_rdoc_any_method.rb b/test/rdoc/test_rdoc_any_method.rb index 930d9773bd..c0feccef95 100644 --- a/test/rdoc/test_rdoc_any_method.rb +++ b/test/rdoc/test_rdoc_any_method.rb @@ -83,6 +83,40 @@ method(a, b) { |c, d| ... } assert_equal '', @c2_a.markup_code end + def test_marshal_dump + top_level = RDoc::TopLevel.new 'file.rb' + m = RDoc::AnyMethod.new nil, 'method' + m.block_params = 'some_block' + m.call_seq = 'call_seq' + m.comment = 'this is a comment' + m.params = 'param' + m.record_location top_level + + cm = RDoc::ClassModule.new 'Klass' + cm.add_method m + + al = RDoc::Alias.new nil, 'method', 'aliased', 'alias comment' + al_m = m.add_alias al, cm + + loaded = Marshal.load Marshal.dump m + + comment = RDoc::Markup::Document.new( + RDoc::Markup::Paragraph.new('this is a comment')) + + assert_equal m, loaded + + assert_equal [al_m], loaded.aliases + assert_equal 'some_block', loaded.block_params + assert_equal 'call_seq', loaded.call_seq + assert_equal comment, loaded.comment + assert_equal top_level, loaded.file + assert_equal 'Klass#method', loaded.full_name + assert_equal 'method', loaded.name + assert_equal 'param', loaded.params + assert_equal nil, loaded.singleton # defaults to nil + assert_equal :public, loaded.visibility + end + def test_marshal_load instance_method = Marshal.load Marshal.dump(@c1.method_list.last) @@ -103,6 +137,40 @@ method(a, b) { |c, d| ... } assert_equal '()', class_method.params end + def test_marshal_load_version_0 + m = RDoc::AnyMethod.new nil, 'method' + cm = RDoc::ClassModule.new 'Klass' + cm.add_method m + al = RDoc::Alias.new nil, 'method', 'aliased', 'alias comment' + al_m = m.add_alias al, cm + + loaded = Marshal.load "\x04\bU:\x14RDoc::AnyMethod[\x0Fi\x00I" \ + "\"\vmethod\x06:\x06EF\"\x11Klass#method0:\vpublic" \ + "o:\eRDoc::Markup::Document\x06:\v@parts[\x06" \ + "o:\x1CRDoc::Markup::Paragraph\x06;\t[\x06I" \ + "\"\x16this is a comment\x06;\x06FI" \ + "\"\rcall_seq\x06;\x06FI\"\x0Fsome_block\x06;\x06F" \ + "[\x06[\aI\"\faliased\x06;\x06Fo;\b\x06;\t[\x06" \ + "o;\n\x06;\t[\x06I\"\x12alias comment\x06;\x06FI" \ + "\"\nparam\x06;\x06F" + + comment = RDoc::Markup::Document.new( + RDoc::Markup::Paragraph.new('this is a comment')) + + assert_equal m, loaded + + assert_equal [al_m], loaded.aliases + assert_equal 'some_block', loaded.block_params + assert_equal 'call_seq', loaded.call_seq + assert_equal comment, loaded.comment + assert_equal 'Klass#method', loaded.full_name + assert_equal 'method', loaded.name + assert_equal 'param', loaded.params + assert_equal nil, loaded.singleton # defaults to nil + assert_equal :public, loaded.visibility + assert_equal nil, loaded.file + end + def test_name m = RDoc::AnyMethod.new nil, nil diff --git a/test/rdoc/test_rdoc_attr.rb b/test/rdoc/test_rdoc_attr.rb index 9751cc175d..b69d8c6499 100644 --- a/test/rdoc/test_rdoc_attr.rb +++ b/test/rdoc/test_rdoc_attr.rb @@ -42,6 +42,68 @@ class TestRDocAttr < MiniTest::Unit::TestCase assert_equal '(unknown)#attr', @a.full_name end + def test_marshal_dump + tl = RDoc::TopLevel.new 'file.rb' + + @a.comment = 'this is a comment' + @a.record_location tl + + cm = RDoc::ClassModule.new 'Klass' + cm.add_attribute @a + + loaded = Marshal.load Marshal.dump @a + + assert_equal @a, loaded + + comment = RDoc::Markup::Document.new( + RDoc::Markup::Paragraph.new('this is a comment')) + + assert_equal comment, loaded.comment + assert_equal 'file.rb', loaded.file.relative_name + assert_equal 'Klass#attr', loaded.full_name + assert_equal 'attr', loaded.name + assert_equal 'RW', loaded.rw + assert_equal false, loaded.singleton + assert_equal :public, loaded.visibility + + @a.rw = 'R' + @a.singleton = true + @a.visibility = :protected + + loaded = Marshal.load Marshal.dump @a + + assert_equal @a, loaded + + assert_equal comment, loaded.comment + assert_equal 'Klass::attr', loaded.full_name + assert_equal 'attr', loaded.name + assert_equal 'R', loaded.rw + assert_equal true, loaded.singleton + assert_equal :protected, loaded.visibility + end + + def test_marshal_load_version_1 + data = "\x04\bU:\x0FRDoc::Attr[\fi\x06I\"\tattr\x06:\x06EF" \ + "\"\x0FKlass#attrI\"\aRW\x06;\x06F:\vpublic" \ + "o:\eRDoc::Markup::Document\x06:\v@parts[\x06" \ + "o:\x1CRDoc::Markup::Paragraph\x06;\t[\x06I" \ + "\"\x16this is a comment\x06;\x06FF" + + loaded = Marshal.load data + + comment = RDoc::Markup::Document.new( + RDoc::Markup::Paragraph.new('this is a comment')) + + assert_equal comment, loaded.comment + assert_equal 'Klass#attr', loaded.full_name + assert_equal 'attr', loaded.name + assert_equal 'RW', loaded.rw + assert_equal false, loaded.singleton + assert_equal :public, loaded.visibility + + assert_equal nil, loaded.file # version 2 + end + def test_params assert_nil @a.params end diff --git a/test/rdoc/test_rdoc_class_module.rb b/test/rdoc/test_rdoc_class_module.rb index 59190a6e3b..1ac0eda298 100644 --- a/test/rdoc/test_rdoc_class_module.rb +++ b/test/rdoc/test_rdoc_class_module.rb @@ -1,3 +1,4 @@ +require 'pp' require File.expand_path '../xref_test_case', __FILE__ class TestRDocClassModule < XrefTestCase @@ -8,6 +9,37 @@ class TestRDocClassModule < XrefTestCase @RM = RDoc::Markup end + def mu_pp obj + s = '' + s = PP.pp obj, s + s.force_encoding Encoding.default_external if defined? Encoding + s.chomp + end + + def test_add_comment + tl1 = RDoc::TopLevel.new 'one.rb' + tl2 = RDoc::TopLevel.new 'two.rb' + tl3 = RDoc::TopLevel.new 'three.rb' + + cm = RDoc::ClassModule.new 'Klass' + cm.add_comment '# comment 1', tl1 + + assert_equal [['comment 1', tl1]], cm.comment_location + assert_equal 'comment 1', cm.comment + + cm.add_comment '# comment 2', tl2 + + assert_equal [['comment 1', tl1], ['comment 2', tl2]], cm.comment_location + assert_equal "comment 1\n---\ncomment 2", cm.comment + + cm.add_comment "# * comment 3", tl3 + + assert_equal [['comment 1', tl1], + ['comment 2', tl2], + ['* comment 3', tl3]], cm.comment_location + assert_equal "comment 1\n---\ncomment 2\n---\n* comment 3", cm.comment + end + def test_ancestors assert_equal [@parent], @child.ancestors end @@ -45,70 +77,468 @@ class TestRDocClassModule < XrefTestCase assert_nil @c2.find_class_named('C1') end - def test_merge + def test_from_module_comment + tl = RDoc::TopLevel.new 'file.rb' + klass = tl.add_class RDoc::NormalModule, 'Klass' + klass.add_comment 'really a class', tl + + klass = RDoc::ClassModule.from_module RDoc::NormalClass, klass + + assert_equal [['really a class', tl]], klass.comment_location + end + + def test_marshal_dump + tl = RDoc::TopLevel.new 'file.rb' + + ns = tl.add_module RDoc::NormalModule, 'Namespace' + + cm = ns.add_class RDoc::NormalClass, 'Klass', 'Super' + cm.record_location tl + + a1 = RDoc::Attr.new nil, 'a1', 'RW', '' + a1.record_location tl + a2 = RDoc::Attr.new nil, 'a2', 'RW', '', true + a2.record_location tl + + m1 = RDoc::AnyMethod.new nil, 'm1' + m1.record_location tl + + c1 = RDoc::Constant.new 'C1', nil, '' + c1.record_location tl + + i1 = RDoc::Include.new 'I1', '' + i1.record_location tl + + cm.add_attribute a1 + cm.add_attribute a2 + cm.add_method m1 + cm.add_constant c1 + cm.add_include i1 + cm.add_comment 'this is a comment', tl + + loaded = Marshal.load Marshal.dump cm + + assert_equal cm, loaded + + inner = RDoc::Markup::Document.new( + RDoc::Markup::Paragraph.new('this is a comment')) + inner.file = tl.absolute_name + + comment = RDoc::Markup::Document.new inner + + assert_equal [a2, a1], loaded.attributes.sort + assert_equal comment, loaded.comment + assert_equal [c1], loaded.constants + assert_equal 'Namespace::Klass', loaded.full_name + assert_equal [i1], loaded.includes + assert_equal [m1], loaded.method_list + assert_equal 'Klass', loaded.name + assert_equal 'Super', loaded.superclass + + assert_equal tl, loaded.attributes.first.file + + assert_equal tl, loaded.constants.first.file + + assert_equal tl, loaded.includes.first.file + + assert_equal tl, loaded.method_list.first.file + end + + def test_marshal_load_version_0 + tl = RDoc::TopLevel.new 'file.rb' + ns = tl.add_module RDoc::NormalModule, 'Namespace' + cm = ns.add_class RDoc::NormalClass, 'Klass', 'Super' + + a = RDoc::Attr.new(nil, 'a1', 'RW', '') + m = RDoc::AnyMethod.new(nil, 'm1') + c = RDoc::Constant.new('C1', nil, '') + i = RDoc::Include.new('I1', '') + + cm.add_attribute a + cm.add_method m + cm.add_constant c + cm.add_include i + cm.add_comment 'this is a comment', tl + + loaded = Marshal.load "\x04\bU:\x16RDoc::NormalClass[\x0Ei\x00\"\nKlass" \ + "\"\x15Namespace::KlassI\"\nSuper\x06:\x06EF" \ + "o:\eRDoc::Markup::Document\x06:\v@parts[\x06" \ + "o:\x1CRDoc::Markup::Paragraph\x06;\b[\x06I" \ + "\"\x16this is a comment\x06;\x06F[\x06[\aI" \ + "\"\aa1\x06;\x06FI\"\aRW\x06;\x06F[\x06[\aI" \ + "\"\aC1\x06;\x06Fo;\a\x06;\b[\x00[\x06[\aI" \ + "\"\aI1\x06;\x06Fo;\a\x06;\b[\x00[\a[\aI" \ + "\"\nclass\x06;\x06F[\b[\a:\vpublic[\x00[\a" \ + ":\x0Eprotected[\x00[\a:\fprivate[\x00[\aI" \ + "\"\rinstance\x06;\x06F[\b[\a;\n[\x06I" \ + "\"\am1\x06;\x06F[\a;\v[\x00[\a;\f[\x00" + + assert_equal cm, loaded + + comment = RDoc::Markup::Document.new( + RDoc::Markup::Paragraph.new('this is a comment')) + + assert_equal [a], loaded.attributes + assert_equal comment, loaded.comment + assert_equal [c], loaded.constants + assert_equal 'Namespace::Klass', loaded.full_name + assert_equal [i], loaded.includes + assert_equal [m], loaded.method_list + assert_equal 'Klass', loaded.name + assert_equal 'Super', loaded.superclass + assert_equal nil, loaded.file + end + + def test_merge_attributes + tl1 = RDoc::TopLevel.new 'one.rb' + tl2 = RDoc::TopLevel.new 'two.rb' + cm1 = RDoc::ClassModule.new 'Klass' - 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') + + attr = cm1.add_attribute RDoc::Attr.new(nil, 'a1', 'RW', '') + attr.record_location tl1 + attr = cm1.add_attribute RDoc::Attr.new(nil, 'a3', 'R', '') + attr.record_location tl1 + attr = cm1.add_attribute RDoc::Attr.new(nil, 'a4', 'R', '') + attr.record_location tl1 cm2 = RDoc::ClassModule.new 'Klass' - cm2.instance_variable_set(:@comment, - @RM::Document.new( - @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') + # TODO allow merging when comment == '' + cm2.instance_variable_set :@comment, @RM::Document.new + + attr = cm2.add_attribute RDoc::Attr.new(nil, 'a2', 'RW', '') + attr.record_location tl2 + attr = cm2.add_attribute RDoc::Attr.new(nil, 'a3', 'W', '') + attr.record_location tl1 + attr = cm2.add_attribute RDoc::Attr.new(nil, 'a4', 'W', '') + attr.record_location tl1 cm1.merge cm2 - document = @RM::Document.new( - @RM::Paragraph.new('klass 2'), - @RM::Paragraph.new('klass 1')) + expected = [ + RDoc::Attr.new(nil, 'a2', 'RW', ''), + RDoc::Attr.new(nil, 'a3', 'W', ''), + RDoc::Attr.new(nil, 'a4', 'W', ''), + ] + + expected.each do |a| a.parent = cm1 end + assert_equal expected, cm1.attributes.sort + end + + def test_merge_attributes_version_0 + tl1 = RDoc::TopLevel.new 'one.rb' + + cm1 = RDoc::ClassModule.new 'Klass' + + attr = cm1.add_attribute RDoc::Attr.new(nil, 'a1', 'RW', '') + attr.record_location tl1 + attr = cm1.add_attribute RDoc::Attr.new(nil, 'a3', 'R', '') + attr.record_location tl1 + attr = cm1.add_attribute RDoc::Attr.new(nil, 'a4', 'R', '') + attr.record_location tl1 + + cm2 = RDoc::ClassModule.new 'Klass' + # TODO allow merging when comment == '' + cm2.instance_variable_set :@comment, @RM::Document.new + + attr = cm2.add_attribute RDoc::Attr.new(nil, 'a2', 'RW', '') + attr = cm2.add_attribute RDoc::Attr.new(nil, 'a3', 'W', '') + attr = cm2.add_attribute RDoc::Attr.new(nil, 'a4', 'W', '') - assert_equal document, cm1.comment + cm1.merge cm2 expected = [ RDoc::Attr.new(nil, 'a1', 'RW', ''), RDoc::Attr.new(nil, 'a2', 'RW', ''), RDoc::Attr.new(nil, 'a3', 'RW', ''), - RDoc::Attr.new(nil, 'a4', 'R', ''), + RDoc::Attr.new(nil, 'a4', 'RW', ''), ] expected.each do |a| a.parent = cm1 end assert_equal expected, cm1.attributes.sort + end + + def test_merge_comment + tl1 = RDoc::TopLevel.new 'one.rb' + tl2 = RDoc::TopLevel.new 'two.rb' + + cm1 = RDoc::ClassModule.new 'Klass' + cm1.add_comment 'klass 1', tl1 + + cm2 = RDoc::ClassModule.new 'Klass' + cm2.add_comment 'klass 2', tl2 + cm2.add_comment 'klass 3', tl1 + + cm2 = Marshal.load Marshal.dump cm2 + + cm1.merge cm2 + + inner1 = @RM::Document.new @RM::Paragraph.new 'klass 3' + inner1.file = 'one.rb' + inner2 = @RM::Document.new @RM::Paragraph.new 'klass 2' + inner2.file = 'two.rb' + + expected = @RM::Document.new inner2, inner1 + + assert_equal expected, cm1.comment + end + + def test_merge_comment_version_0 + tl = RDoc::TopLevel.new 'file.rb' + + cm1 = RDoc::ClassModule.new 'Klass' + cm1.add_comment 'klass 1', tl + + cm2 = RDoc::ClassModule.new 'Klass' + + cm2.instance_variable_set(:@comment, + @RM::Document.new( + @RM::Paragraph.new('klass 2'))) + cm2.instance_variable_set :@comment_location, @RM::Document.new(cm2.comment) + + cm1.merge cm2 + + inner = @RM::Document.new @RM::Paragraph.new 'klass 1' + inner.file = 'file.rb' + + expected = @RM::Document.new \ + inner, + @RM::Document.new(@RM::Paragraph.new('klass 2')) + + assert_equal expected, cm1.comment + end + + def test_merge_constants + tl1 = RDoc::TopLevel.new 'one.rb' + tl2 = RDoc::TopLevel.new 'two.rb' + + cm1 = RDoc::ClassModule.new 'Klass' + + const = cm1.add_constant RDoc::Constant.new('C1', nil, 'one') + const.record_location tl1 + const = cm1.add_constant RDoc::Constant.new('C3', nil, 'one') + const.record_location tl1 + + cm2 = RDoc::ClassModule.new 'Klass' + cm2.instance_variable_set :@comment, @RM::Document.new + + const = cm2.add_constant RDoc::Constant.new('C2', nil, 'two') + const.record_location tl2 + const = cm2.add_constant RDoc::Constant.new('C3', nil, 'one') + const.record_location tl1 + const = cm2.add_constant RDoc::Constant.new('C4', nil, 'one') + const.record_location tl1 + + cm1.merge cm2 + + expected = [ + RDoc::Constant.new('C2', nil, 'two'), + RDoc::Constant.new('C3', nil, 'one'), + RDoc::Constant.new('C4', nil, 'one'), + ] + + expected.each do |a| a.parent = cm1 end + + assert_equal expected, cm1.constants.sort + end + + def test_merge_constants_version_0 + tl1 = RDoc::TopLevel.new 'one.rb' + + cm1 = RDoc::ClassModule.new 'Klass' + + const = cm1.add_constant RDoc::Constant.new('C1', nil, 'one') + const.record_location tl1 + const = cm1.add_constant RDoc::Constant.new('C3', nil, 'one') + const.record_location tl1 + + cm2 = RDoc::ClassModule.new 'Klass' + cm2.instance_variable_set :@comment, @RM::Document.new + + const = cm2.add_constant RDoc::Constant.new('C2', nil, 'two') + const = cm2.add_constant RDoc::Constant.new('C3', nil, 'two') + const = cm2.add_constant RDoc::Constant.new('C4', nil, 'two') + + cm1.merge cm2 expected = [ - RDoc::Constant.new('C1', nil, ''), - RDoc::Constant.new('C2', nil, ''), + RDoc::Constant.new('C1', nil, 'one'), + RDoc::Constant.new('C2', nil, 'two'), + RDoc::Constant.new('C3', nil, 'one'), + RDoc::Constant.new('C4', nil, 'two'), ] - expected.each do |c| c.parent = cm1 end + expected.each do |a| a.parent = cm1 end + assert_equal expected, cm1.constants.sort + end + + def test_merge_includes + tl1 = RDoc::TopLevel.new 'one.rb' + tl2 = RDoc::TopLevel.new 'two.rb' + + cm1 = RDoc::ClassModule.new 'Klass' + + incl = cm1.add_include RDoc::Include.new('I1', 'one') + incl.record_location tl1 + incl = cm1.add_include RDoc::Include.new('I3', 'one') + incl.record_location tl1 + + cm2 = RDoc::ClassModule.new 'Klass' + cm2.instance_variable_set :@comment, @RM::Document.new + + incl = cm2.add_include RDoc::Include.new('I2', 'two') + incl.record_location tl2 + incl = cm2.add_include RDoc::Include.new('I3', 'one') + incl.record_location tl1 + incl = cm2.add_include RDoc::Include.new('I4', 'one') + incl.record_location tl1 + + cm1.merge cm2 + + expected = [ + RDoc::Include.new('I2', 'two'), + RDoc::Include.new('I3', 'one'), + RDoc::Include.new('I4', 'one'), + ] + + expected.each do |a| a.parent = cm1 end + + assert_equal expected, cm1.includes.sort + end + + def test_merge_includes_version_0 + tl1 = RDoc::TopLevel.new 'one.rb' + + cm1 = RDoc::ClassModule.new 'Klass' + + incl = cm1.add_include RDoc::Include.new('I1', 'one') + incl.record_location tl1 + incl = cm1.add_include RDoc::Include.new('I3', 'one') + incl.record_location tl1 + + cm2 = RDoc::ClassModule.new 'Klass' + cm2.instance_variable_set :@comment, @RM::Document.new + + incl = cm2.add_include RDoc::Include.new('I2', 'two') + incl = cm2.add_include RDoc::Include.new('I3', 'two') + incl = cm2.add_include RDoc::Include.new('I4', 'two') + + cm1.merge cm2 expected = [ - RDoc::Include.new('I1', ''), - RDoc::Include.new('I2', ''), + RDoc::Include.new('I1', 'one'), + RDoc::Include.new('I2', 'two'), + RDoc::Include.new('I3', 'one'), + RDoc::Include.new('I4', 'two'), ] - expected.each do |i| i.parent = cm1 end + expected.each do |a| a.parent = cm1 end + assert_equal expected, cm1.includes.sort + end + + def test_merge_methods + tl1 = RDoc::TopLevel.new 'one.rb' + tl2 = RDoc::TopLevel.new 'two.rb' + + cm1 = RDoc::ClassModule.new 'Klass' + + meth = cm1.add_method RDoc::AnyMethod.new(nil, 'm1') + meth.record_location tl1 + meth = cm1.add_method RDoc::AnyMethod.new(nil, 'm3') + meth.record_location tl1 + + cm2 = RDoc::ClassModule.new 'Klass' + cm2.instance_variable_set :@comment, @RM::Document.new + + meth = cm2.add_method RDoc::AnyMethod.new(nil, 'm2') + meth.record_location tl2 + meth = cm2.add_method RDoc::AnyMethod.new(nil, 'm3') + meth.record_location tl1 + meth = cm2.add_method RDoc::AnyMethod.new(nil, 'm4') + meth.record_location tl1 + + cm1.merge cm2 + + expected = [ + RDoc::AnyMethod.new(nil, 'm2'), + RDoc::AnyMethod.new(nil, 'm3'), + RDoc::AnyMethod.new(nil, 'm4'), + ] + + expected.each do |a| a.parent = cm1 end + + assert_equal expected, cm1.method_list.sort + end + + def test_merge_methods_version_0 + tl1 = RDoc::TopLevel.new 'one.rb' + + cm1 = RDoc::ClassModule.new 'Klass' + + meth = cm1.add_method RDoc::AnyMethod.new(nil, 'm1') + meth.record_location tl1 + meth = cm1.add_method RDoc::AnyMethod.new(nil, 'm3') + meth.record_location tl1 + + cm2 = RDoc::ClassModule.new 'Klass' + cm2.instance_variable_set :@comment, @RM::Document.new + + meth = cm2.add_method RDoc::AnyMethod.new(nil, 'm2') + meth = cm2.add_method RDoc::AnyMethod.new(nil, 'm3') + meth = cm2.add_method RDoc::AnyMethod.new(nil, 'm4') + + cm1.merge cm2 expected = [ RDoc::AnyMethod.new(nil, 'm1'), RDoc::AnyMethod.new(nil, 'm2'), + RDoc::AnyMethod.new(nil, 'm3'), + RDoc::AnyMethod.new(nil, 'm4'), ] - expected.each do |m| m.parent = cm1 end + expected.each do |a| a.parent = cm1 end + assert_equal expected, cm1.method_list.sort end + def test_parse + tl1 = RDoc::TopLevel.new 'one.rb' + tl2 = RDoc::TopLevel.new 'two.rb' + + cm = RDoc::ClassModule.new 'Klass' + cm.add_comment 'comment 1', tl1 + cm.add_comment 'comment 2', tl2 + + doc1 = @RM::Document.new @RM::Paragraph.new 'comment 1' + doc1.file = tl1.absolute_name + doc2 = @RM::Document.new @RM::Paragraph.new 'comment 2' + doc2.file = tl2.absolute_name + + expected = @RM::Document.new doc1, doc2 + + assert_equal expected, cm.parse(cm.comment_location) + end + + def test_parse_comment_location + tl1 = RDoc::TopLevel.new 'one.rb' + tl2 = RDoc::TopLevel.new 'two.rb' + + cm = RDoc::ClassModule.new 'Klass' + cm.add_comment 'comment 1', tl1 + cm.add_comment 'comment 2', tl2 + + cm = Marshal.load Marshal.dump cm + + doc1 = @RM::Document.new @RM::Paragraph.new 'comment 1' + doc1.file = tl1.absolute_name + doc2 = @RM::Document.new @RM::Paragraph.new 'comment 2' + doc2.file = tl2.absolute_name + + assert_same cm.comment_location, cm.parse(cm.comment_location) + end + def test_remove_nodoc_children parent = RDoc::ClassModule.new 'A' parent.modules_hash.replace 'B' => true, 'C' => true diff --git a/test/rdoc/test_rdoc_code_object.rb b/test/rdoc/test_rdoc_code_object.rb index b4ebfc4b3e..cdac7eeed6 100644 --- a/test/rdoc/test_rdoc_code_object.rb +++ b/test/rdoc/test_rdoc_code_object.rb @@ -30,6 +30,15 @@ class TestRDocCodeObject < XrefTestCase assert_equal 'I am a comment', @co.comment end + def test_comment_equals_document + doc = RDoc::Markup::Document.new + @co.comment = doc + + @co.comment = '' + + assert_equal doc, @co.comment + end + def test_comment_equals_encoding skip "Encoding not implemented" unless Object.const_defined? :Encoding @@ -129,6 +138,14 @@ class TestRDocCodeObject < XrefTestCase assert_equal [@parent, @xref_data], parents end + def test_file_name + assert_equal nil, @co.file_name + + @co.record_location RDoc::TopLevel.new 'lib/file.rb' + + assert_equal 'lib/file.rb', @co.file_name + 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 55c6c6e6e3..2fb8ef7bb7 100644 --- a/test/rdoc/test_rdoc_context.rb +++ b/test/rdoc/test_rdoc_context.rb @@ -17,6 +17,7 @@ class TestRDocContext < XrefTestCase assert_equal nil, @context.parent assert_equal :public, @context.visibility assert_equal 1, @context.sections.length + assert_equal nil, @context.temporary_section assert_empty @context.classes_hash assert_empty @context.modules_hash @@ -137,6 +138,13 @@ class TestRDocContext < XrefTestCase assert_equal 'Object', object.superclass.full_name end + def test_add_class_singleton + @c1.add_class RDoc::NormalClass, 'Klass', 'Object' + + assert_includes @c1.classes.map { |k| k.full_name }, 'C1::Klass' + assert_includes RDoc::TopLevel.classes.map { |k| k.full_name }, 'C1::Klass' + end + def test_add_class_superclass @c1.add_class RDoc::NormalClass, 'Klass', 'Object' @c1.add_class RDoc::NormalClass, 'Klass', 'Other' @@ -244,6 +252,29 @@ class TestRDocContext < XrefTestCase assert_includes @c1.top_level.requires, req end + def test_add_section + default_section = @context.sections.first + + @context.add_section nil, '# comment' + + assert_equal 1, @context.sections.length + assert_equal '# comment', @context.sections.first.comment + + @context.add_section nil, '# new comment' + + assert_equal 1, @context.sections.length + assert_equal "# comment\n# ---\n# new comment", + @context.sections.first.comment + + @context.add_section 'other', '' + + assert_equal 2, @context.sections.length + + new_section = @context.sections.find { |section| section.title == 'other' } + assert new_section + assert_equal default_section, @context.current_section + end + def test_add_to incl = RDoc::Include.new 'Name', 'comment' arr = [] @@ -254,6 +285,19 @@ class TestRDocContext < XrefTestCase assert_equal @context.current_section, incl.section end + def test_add_to_temporary_section + incl = RDoc::Include.new 'Name', 'comment' + arr = [] + section = @context.add_section 'temporary', '' + @context.temporary_section = section + + @context.add_to arr, incl + + assert_includes arr, incl + assert_equal @context, incl.parent + assert_equal section, incl.section + end + def test_add_to_no_document_self incl = RDoc::Include.new 'Name', 'comment' arr = [] @@ -281,6 +325,16 @@ class TestRDocContext < XrefTestCase assert_equal %w[C3::H1 C3::H2], @c3.classes.map { |k| k.full_name } end + def test_current_section + default_section = @context.current_section + + new_section = @context.add_section 'other', '' + @context.temporary_section = new_section + + assert_equal new_section, @context.current_section + assert_equal default_section, @context.current_section + end + def test_defined_in_eh assert @c1.defined_in?(@c1.top_level) @@ -596,6 +650,22 @@ class TestRDocContext < XrefTestCase assert_equal [@pub, @prot, @priv], methods end + def test_set_current_section + default_section = @context.sections.first + + @context.set_current_section nil, '' + + assert_equal default_section, @context.current_section + + @context.set_current_section 'other', '' + + new_section = @context.sections.find { |section| + section != default_section + } + + assert_equal new_section, @context.current_section + end + def util_visibilities @pub = RDoc::AnyMethod.new nil, 'pub' @prot = RDoc::AnyMethod.new nil, 'prot' diff --git a/test/rdoc/test_rdoc_generator_ri.rb b/test/rdoc/test_rdoc_generator_ri.rb index 780d9cc570..2be006843c 100644 --- a/test/rdoc/test_rdoc_generator_ri.rb +++ b/test/rdoc/test_rdoc_generator_ri.rb @@ -9,6 +9,7 @@ class TestRDocGeneratorRI < MiniTest::Unit::TestCase def setup @options = RDoc::Options.new + @options.encoding = Encoding::UTF_8 if Object.const_defined? :Encoding @pwd = Dir.pwd RDoc::TopLevel.reset @@ -21,9 +22,15 @@ class TestRDocGeneratorRI < MiniTest::Unit::TestCase @top_level = RDoc::TopLevel.new 'file.rb' @klass = @top_level.add_class RDoc::NormalClass, 'Object' + @meth = RDoc::AnyMethod.new nil, 'method' + @meth.record_location @top_level + @meth_bang = RDoc::AnyMethod.new nil, 'method!' + @meth_bang.record_location @top_level + @attr = RDoc::Attr.new nil, 'attr', 'RW', '' + @attr.record_location @top_level @klass.add_method @meth @klass.add_method @meth_bang @@ -44,9 +51,6 @@ class TestRDocGeneratorRI < MiniTest::Unit::TestCase end def test_generate - top_level = RDoc::TopLevel.new 'file.rb' - top_level.add_class @klass.class, @klass.name - @g.generate nil assert_file File.join(@tmpdir, 'cache.ri') @@ -56,6 +60,13 @@ class TestRDocGeneratorRI < MiniTest::Unit::TestCase assert_file File.join(@tmpdir, 'Object', 'attr-i.ri') assert_file File.join(@tmpdir, 'Object', 'method-i.ri') assert_file File.join(@tmpdir, 'Object', 'method%21-i.ri') + + store = RDoc::RI::Store.new @tmpdir + store.load_cache + + encoding = Object.const_defined?(:Encoding) ? Encoding::UTF_8 : nil + + assert_equal encoding, store.encoding end def test_generate_dry_run diff --git a/test/rdoc/test_rdoc_markup.rb b/test/rdoc/test_rdoc_markup.rb index 9f7866fb5a..48683dbcda 100644 --- a/test/rdoc/test_rdoc_markup.rb +++ b/test/rdoc/test_rdoc_markup.rb @@ -18,7 +18,10 @@ the time STR m = RDoc::Markup.new - out = m.convert str, RDoc::Markup::ToTest.new + + tt = RDoc::Markup::ToTest.new m + + out = m.convert str, tt expected = [ "now is the time", @@ -33,5 +36,25 @@ the time assert_equal expected, out end + def test_convert_custom_markup + str = <<-STR +{stricken} + STR + + m = RDoc::Markup.new + m.add_word_pair '{', '}', :STRIKE + + tt = RDoc::Markup::ToTest.new m + tt.add_tag :STRIKE, 'STRIKE ', ' STRIKE' + + out = m.convert str, tt + + expected = [ + "STRIKE stricken STRIKE", + ] + + assert_equal expected, out + end + end diff --git a/test/rdoc/test_rdoc_markup_document.rb b/test/rdoc/test_rdoc_markup_document.rb index ab2f1c2362..70fb3efb16 100644 --- a/test/rdoc/test_rdoc_markup_document.rb +++ b/test/rdoc/test_rdoc_markup_document.rb @@ -47,5 +47,82 @@ class TestRDocMarkupDocument < MiniTest::Unit::TestCase end end + def test_empty_eh + assert_empty @d + + @d << @RM::BlankLine.new + + refute_empty @d + end + + def test_equals2 + d2 = @RM::Document.new + + assert_equal @d, d2 + + d2 << @RM::BlankLine.new + + refute_equal @d, d2 + end + + def test_equals2_file + d2 = @RM::Document.new + d2.file = 'file.rb' + + refute_equal @d, d2 + + @d.file = 'file.rb' + + assert_equal @d, d2 + end + + def test_lt2 + @d << @RM::BlankLine.new + + refute_empty @d + end + + def test_merge + original = @RM::Document.new @RM::Paragraph.new 'original' + original.file = 'file.rb' + root = @RM::Document.new original + + replace = @RM::Document.new @RM::Paragraph.new 'replace' + replace.file = 'file.rb' + + other = @RM::Document.new replace + + result = root.merge other + + inner = @RM::Document.new @RM::Paragraph.new 'replace' + inner.file = 'file.rb' + expected = @RM::Document.new inner + + assert_equal expected, result + end + + def test_merge_add + original = @RM::Document.new @RM::Paragraph.new 'original' + original.file = 'file.rb' + root = @RM::Document.new original + + addition = @RM::Document.new @RM::Paragraph.new 'addition' + addition.file = 'other.rb' + + other = @RM::Document.new addition + + result = root.merge other + + expected = @RM::Document.new original, addition + + assert_equal expected, result + end + + def test_push + @d.push @RM::BlankLine.new, @RM::BlankLine.new + + refute_empty @d + end + end diff --git a/test/rdoc/test_rdoc_markup_indented_paragraph.rb b/test/rdoc/test_rdoc_markup_indented_paragraph.rb new file mode 100644 index 0000000000..e3e2b630e1 --- /dev/null +++ b/test/rdoc/test_rdoc_markup_indented_paragraph.rb @@ -0,0 +1,40 @@ +require 'pp' +require 'rubygems' +require 'minitest/autorun' +require 'rdoc/markup' + +class TestRDocMarkupIndentedParagraph < MiniTest::Unit::TestCase + + def setup + @IP = RDoc::Markup::IndentedParagraph + end + + def test_initialize + ip = @IP.new 2, 'a', 'b' + + assert_equal 2, ip.indent + assert_equal %w[a b], ip.parts + end + + def test_accept + visitor = Object.new + def visitor.accept_indented_paragraph(obj) @obj = obj end + def visitor.obj() @obj end + + paragraph = @IP.new 0 + + paragraph.accept visitor + + assert_equal paragraph, visitor.obj + end + + def test_equals2 + one = @IP.new 1 + two = @IP.new 2 + + assert_equal one, one + refute_equal one, two + end + +end + diff --git a/test/rdoc/test_rdoc_markup_paragraph.rb b/test/rdoc/test_rdoc_markup_paragraph.rb index a1eba7038d..6ae1ad9a84 100644 --- a/test/rdoc/test_rdoc_markup_paragraph.rb +++ b/test/rdoc/test_rdoc_markup_paragraph.rb @@ -5,5 +5,17 @@ require 'rdoc/markup' class TestRDocMarkupParagraph < MiniTest::Unit::TestCase + def test_accept + visitor = Object.new + def visitor.accept_paragraph(obj) @obj = obj end + def visitor.obj() @obj end + + paragraph = RDoc::Markup::Paragraph.new + + paragraph.accept visitor + + assert_equal paragraph, visitor.obj + end + end diff --git a/test/rdoc/test_rdoc_markup_pre_process.rb b/test/rdoc/test_rdoc_markup_pre_process.rb index 9fff53df77..db5fca5ac1 100644 --- a/test/rdoc/test_rdoc_markup_pre_process.rb +++ b/test/rdoc/test_rdoc_markup_pre_process.rb @@ -40,6 +40,11 @@ Regular expressions (regexps) are patterns which describe the contents of a string. EXPECTED + # FIXME 1.9 fix on windoze + # preprocessor uses binread, so line endings are \r\n + expected.gsub!("\n", "\r\n") if + RUBY_VERSION =~ /^1.9/ && RUBY_PLATFORM =~ /mswin|mingw/ + assert_equal expected, content end @@ -59,6 +64,11 @@ contents of a string. expected = "?\n" + # FIXME 1.9 fix on windoze + # preprocessor uses binread, so line endings are \r\n + expected.gsub!("\n", "\r\n") if + RUBY_VERSION =~ /^1.9/ && RUBY_PLATFORM =~ /mswin|mingw/ + assert_equal expected, content end @@ -86,6 +96,17 @@ contents of a string. assert_equal "", text end + def test_handle_category + context = RDoc::Context.new + original_section = context.current_section + + text = "# :category: other\n" + + @pp.handle text, context + + refute_equal original_section, context.current_section + end + def test_handle_code_object cd = RDoc::CodeObject.new text = "# :x: y\n" diff --git a/test/rdoc/test_rdoc_markup_to_ansi.rb b/test/rdoc/test_rdoc_markup_to_ansi.rb index 1334ac71c4..f60d1999c2 100644 --- a/test/rdoc/test_rdoc_markup_to_ansi.rb +++ b/test/rdoc/test_rdoc_markup_to_ansi.rb @@ -18,6 +18,10 @@ class TestRDocMarkupToAnsi < RDoc::Markup::TextFormatterTestCase assert_equal "\e[0m\n", @to.res.join end + def accept_document + assert_equal "\e[0mhello\n", @to.res.join + end + def accept_heading assert_equal "\e[0mHello\n", @to.res.join end diff --git a/test/rdoc/test_rdoc_markup_to_bs.rb b/test/rdoc/test_rdoc_markup_to_bs.rb index 3d2e4da8de..35a9266b5d 100644 --- a/test/rdoc/test_rdoc_markup_to_bs.rb +++ b/test/rdoc/test_rdoc_markup_to_bs.rb @@ -18,6 +18,10 @@ class TestRDocMarkupToBs < RDoc::Markup::TextFormatterTestCase assert_equal "\n", @to.res.join end + def accept_document + assert_equal "hello\n", @to.res.join + end + def accept_heading skip "No String#chars, upgrade your ruby" unless ''.respond_to? :chars assert_equal "===== H\bHe\bel\bll\blo\bo\n", @to.res.join diff --git a/test/rdoc/test_rdoc_markup_to_html.rb b/test/rdoc/test_rdoc_markup_to_html.rb index 8a2971155b..b43adf1560 100644 --- a/test/rdoc/test_rdoc_markup_to_html.rb +++ b/test/rdoc/test_rdoc_markup_to_html.rb @@ -30,6 +30,10 @@ class TestRDocMarkupToHtml < RDoc::Markup::FormatterTestCase assert_empty @to.res.join end + def accept_document + assert_equal "\n

hello

\n", @to.res.join + end + def accept_heading assert_equal "\n
Hello
\n", @to.res.join end @@ -69,7 +73,7 @@ class TestRDocMarkupToHtml < RDoc::Markup::FormatterTestCase assert_equal [], @to.list assert_equal [], @to.in_list_entry - assert_equal "
\n", @to.res.join + assert_equal "
\n", @to.res.join end def accept_list_end_lalpha @@ -129,7 +133,7 @@ class TestRDocMarkupToHtml < RDoc::Markup::FormatterTestCase end def accept_list_item_start_label - assert_equal "
cat
\n
", @to.res.join + assert_equal "
cat
\n
", @to.res.join end def accept_list_item_start_lalpha @@ -171,7 +175,7 @@ class TestRDocMarkupToHtml < RDoc::Markup::FormatterTestCase assert_equal [:LABEL], @to.list assert_equal [false], @to.in_list_entry - assert_equal "
", @to.res.join + assert_equal '
', @to.res.join end def accept_list_start_lalpha diff --git a/test/rdoc/test_rdoc_markup_to_rdoc.rb b/test/rdoc/test_rdoc_markup_to_rdoc.rb index 20ff937c5a..06cae078c6 100644 --- a/test/rdoc/test_rdoc_markup_to_rdoc.rb +++ b/test/rdoc/test_rdoc_markup_to_rdoc.rb @@ -18,6 +18,10 @@ class TestRDocMarkupToRDoc < RDoc::Markup::TextFormatterTestCase assert_equal "\n", @to.res.join end + def accept_document + assert_equal "hello\n", @to.res.join + end + def accept_heading assert_equal "===== Hello\n", @to.res.join end @@ -323,5 +327,15 @@ words words words words assert_equal expected, @to.end_accepting end + def test_accept_indented_paragraph + ip = RDoc::Markup::IndentedParagraph.new 2, 'cats are cool' + + @to.start_accepting + + @to.accept_indented_paragraph ip + + assert_equal " cats are cool\n", @to.end_accepting + end + end diff --git a/test/rdoc/test_rdoc_markup_to_tt_only.rb b/test/rdoc/test_rdoc_markup_to_tt_only.rb index dd50ba8fde..f5bb662897 100644 --- a/test/rdoc/test_rdoc_markup_to_tt_only.rb +++ b/test/rdoc/test_rdoc_markup_to_tt_only.rb @@ -17,6 +17,10 @@ class TestRDocMarkupToTtOnly < RDoc::Markup::FormatterTestCase assert_empty @to.end_accepting end + def accept_document + assert_equal [], @to.res + end + def accept_heading assert_empty @to.end_accepting end diff --git a/test/rdoc/test_rdoc_parser_c.rb b/test/rdoc/test_rdoc_parser_c.rb index 45d0b1e341..438eeee2ab 100644 --- a/test/rdoc/test_rdoc_parser_c.rb +++ b/test/rdoc/test_rdoc_parser_c.rb @@ -46,7 +46,7 @@ assert call-seq correct =end class RDoc::Parser::C - attr_accessor :classes, :singleton_classes + attr_accessor :classes public :do_classes, :do_constants end @@ -70,6 +70,22 @@ class TestRDocParserC < MiniTest::Unit::TestCase @tempfile.close end + def test_class_can_parse + c_parser = RDoc::Parser::C + + assert_equal c_parser, c_parser.can_parse('file.C') + assert_equal c_parser, c_parser.can_parse('file.CC') + assert_equal c_parser, c_parser.can_parse('file.H') + assert_equal c_parser, c_parser.can_parse('file.HH') + assert_equal c_parser, c_parser.can_parse('file.c') + assert_equal c_parser, c_parser.can_parse('file.cc') + assert_equal c_parser, c_parser.can_parse('file.cpp') + assert_equal c_parser, c_parser.can_parse('file.cxx') + assert_equal c_parser, c_parser.can_parse('file.h') + assert_equal c_parser, c_parser.can_parse('file.hh') + assert_equal c_parser, c_parser.can_parse('file.y') + end + def test_do_attr_rb_attr content = <<-EOF void Init_Blah(void) { @@ -224,6 +240,21 @@ VALUE cFoo = boot_defclass("Foo", 0); assert_equal nil, klass.superclass end + def test_do_aliases_missing_class + content = <<-EOF +void Init_Blah(void) { + rb_define_alias(cDate, "b", "a"); +} + EOF + + _, err = capture_io do + refute util_get_class(content, 'cDate') + end + + assert_equal "Enclosing class/module \"cDate\" for alias b a not known\n", + err + end + def test_do_classes_class content = <<-EOF /* Document-class: Foo @@ -398,6 +429,140 @@ Multiline comment goes here because this comment spans multiple lines. assert constants.empty?, constants.inspect end + def test_do_constants_curses + content = <<-EOF +void Init_curses(){ + mCurses = rb_define_module("Curses"); + + /* + * Document-const: Curses::COLOR_BLACK + * + * Value of the color black + */ + rb_curses_define_const(COLOR_BLACK); +} + EOF + + @parser = util_parser content + + @parser.do_classes + @parser.do_constants + + klass = @parser.classes['mCurses'] + + constants = klass.constants + refute_empty klass.constants + + assert_equal 'COLOR_BLACK', constants.first.name + assert_equal 'UINT2NUM(COLOR_BLACK)', constants.first.value + assert_equal 'Value of the color black', constants.first.comment + end + + def test_do_includes + content = <<-EOF +Init_foo() { + VALUE cFoo = rb_define_class("Foo", rb_cObject); + VALUE mInc = rb_define_module("Inc"); + + rb_include_module(cFoo, mInc); +} + EOF + + klass = util_get_class content, 'cFoo' + + incl = klass.includes.first + assert_equal 'Inc', incl.name + assert_equal '', incl.comment + assert_equal @top_level, incl.file + end + + # HACK parsing warning instead of setting up in file + def test_do_methods_in_c + content = <<-EOF +VALUE blah(VALUE klass, VALUE year) { +} + +void Init_Blah(void) { + cDate = rb_define_class("Date", rb_cObject); + + rb_define_method(cDate, "blah", blah, 1); /* in blah.c */ +} + EOF + + klass = nil + + _, err = capture_io do + klass = util_get_class content, 'cDate' + end + + assert_match ' blah.c ', err + end + + # HACK parsing warning instead of setting up in file + def test_do_methods_in_cpp + content = <<-EOF +VALUE blah(VALUE klass, VALUE year) { +} + +void Init_Blah(void) { + cDate = rb_define_class("Date", rb_cObject); + + rb_define_method(cDate, "blah", blah, 1); /* in blah.cpp */ +} + EOF + + klass = nil + + _, err = capture_io do + klass = util_get_class content, 'cDate' + end + + assert_match ' blah.cpp ', err + end + + # HACK parsing warning instead of setting up in file + def test_do_methods_in_y + content = <<-EOF +VALUE blah(VALUE klass, VALUE year) { +} + +void Init_Blah(void) { + cDate = rb_define_class("Date", rb_cObject); + + rb_define_method(cDate, "blah", blah, 1); /* in blah.y */ +} + EOF + + klass = nil + + _, err = capture_io do + klass = util_get_class content, 'cDate' + end + + assert_match ' blah.y ', err + end + + def test_do_methods_singleton_class + content = <<-EOF +VALUE blah(VALUE klass, VALUE year) { +} + +void Init_Blah(void) { + cDate = rb_define_class("Date", rb_cObject); + sDate = rb_singleton_class(cDate); + + rb_define_method(sDate, "blah", blah, 1); +} + EOF + + klass = util_get_class content, 'cDate' + + methods = klass.method_list + assert_equal 1, methods.length + assert_equal 'blah', methods.first.name + assert methods.first.singleton + end + def test_find_alias_comment parser = util_parser '' @@ -525,6 +690,53 @@ Init_Foo(void) { assert_equal '', klass.comment end + def test_find_const_comment_rb_define + content = <<-EOF +/* + * A comment + */ +rb_define_const(cFoo, "CONST", value); + EOF + + parser = util_parser content + + comment = parser.find_const_comment 'const', 'CONST' + + assert_equal "/*\n * A comment\n */\n", comment + end + + def test_find_const_comment_document_const + content = <<-EOF +/* + * Document-const: CONST + * + * A comment + */ + EOF + + parser = util_parser content + + comment = parser.find_const_comment nil, 'CONST' + + assert_equal " *\n * A comment\n */", comment + end + + def test_find_const_comment_document_const_full_name + content = <<-EOF +/* + * Document-const: Foo::CONST + * + * A comment + */ + EOF + + parser = util_parser content + + comment = parser.find_const_comment nil, 'CONST', 'Foo' + + assert_equal " *\n * A comment\n */", comment + end + def test_find_body content = <<-EOF /* @@ -699,6 +911,81 @@ Init_Foo(void) { assert_equal "a comment for bar", baz.comment end + def test_find_body_document_method_equals + content = <<-EOF +/* + * Document-method: Zlib::GzipFile#mtime= + * + * A comment + */ +static VALUE +rb_gzfile_set_mtime(VALUE obj, VALUE mtime) +{ + +void +Init_zlib() { + mZlib = rb_define_module("Zlib"); + cGzipFile = rb_define_class_under(mZlib, "GzipFile", rb_cObject); + cGzipWriter = rb_define_class_under(mZlib, "GzipWriter", cGzipFile); + rb_define_method(cGzipWriter, "mtime=", rb_gzfile_set_mtime, 1); +} + EOF + + klass = util_get_class content, 'cGzipWriter' + assert_equal 1, klass.method_list.length + + methods = klass.method_list.sort + + bar = methods.first + assert_equal 'Zlib::GzipWriter#mtime=', bar.full_name + assert_equal 'A comment', bar.comment + end + + def test_find_body_document_method_same + content = <<-EOF +VALUE +s_bar() { +} + +VALUE +bar() { +} + +/* + * Document-method: Foo::bar + * + * a comment for Foo::bar + */ + +/* + * Document-method: Foo#bar + * + * a comment for Foo#bar + */ + +void +Init_Foo(void) { + VALUE foo = rb_define_class("Foo", rb_cObject); + + rb_define_singleton_method(foo, "bar", s_bar, 0); + rb_define_method(foo, "bar", bar, 0); +} + EOF + + klass = util_get_class content, 'foo' + assert_equal 2, klass.method_list.length + + methods = klass.method_list.sort + + s_bar = methods.first + assert_equal 'Foo::bar', s_bar.full_name + assert_equal "a comment for Foo::bar", s_bar.comment + + bar = methods.last + assert_equal 'Foo#bar', bar.full_name + assert_equal "a comment for Foo#bar", bar.comment + end + def test_find_modifiers_call_seq comment = <<-COMMENT /* call-seq: @@ -830,7 +1117,6 @@ rb_m(int argc, VALUE *argv, VALUE obj) { assert_equal '(p1)', m.params end - def test_handle_method_args_0 parser = util_parser "Document-method: BasicObject#==\n blah */" @@ -905,6 +1191,20 @@ rb_m(int argc, VALUE *argv, VALUE obj) { assert_equal :public, new.visibility end + def test_handle_singleton + parser = util_parser <<-SINGLE +void Init_Blah(void) { + cDate = rb_define_class("Date", rb_cObject); + sDate = rb_singleton_class(cDate); +} + SINGLE + + parser.scan + + assert_equal 'Date', parser.known_classes['sDate'] + assert_equal 'Date', parser.singleton_classes['sDate'] + end + def test_look_for_directives_in parser = util_parser '' diff --git a/test/rdoc/test_rdoc_parser_ruby.rb b/test/rdoc/test_rdoc_parser_ruby.rb index 87ac45a073..e02ed56beb 100644 --- a/test/rdoc/test_rdoc_parser_ruby.rb +++ b/test/rdoc/test_rdoc_parser_ruby.rb @@ -1084,6 +1084,26 @@ EOF assert_equal top_bar, bar.find_module_named('A') end + def test_parse_include + klass = RDoc::NormalClass.new 'C' + klass.parent = @top_level + + comment = "# my include\n" + + util_parser "include I" + + @parser.get_tk # include + + @parser.parse_include klass, comment + + assert_equal 1, klass.includes.length + + incl = klass.includes.first + assert_equal 'I', incl.name + assert_equal 'my include', incl.comment + assert_equal @top_level, incl.file + end + def test_parse_meta_method klass = RDoc::NormalClass.new 'Foo' klass.parent = @top_level @@ -2028,6 +2048,33 @@ end assert_equal 'm comment', m.comment end + def test_scan_block_comment_nested # Issue #41 + content = <<-CONTENT +require 'something' +=begin rdoc +findmeindoc +=end +module Foo + class Bar + end +end + CONTENT + + util_parser content + + @parser.scan + + foo = @top_level.modules.first + + assert_equal 'Foo', foo.full_name + assert_equal 'findmeindoc', foo.comment + + bar = foo.classes.first + + assert_equal 'Foo::Bar', bar.full_name + assert_equal '', bar.comment + end + def test_scan_block_comment_notflush ## # diff --git a/test/rdoc/test_rdoc_rdoc.rb b/test/rdoc/test_rdoc_rdoc.rb index 0f465d724f..aedccc9dbf 100644 --- a/test/rdoc/test_rdoc_rdoc.rb +++ b/test/rdoc/test_rdoc_rdoc.rb @@ -16,12 +16,27 @@ class TestRDocRDoc < MiniTest::Unit::TestCase @stats = RDoc::Stats.new 0, 0 @rdoc.instance_variable_set :@stats, @stats - - @tempfile = Tempfile.new 'test_rdoc_rdoc' end - def teardown - @tempfile.close rescue nil # HACK for 1.8.6 + def test_class_reset + tl = RDoc::TopLevel.new 'file.rb' + tl.add_class RDoc::NormalClass, 'C' + tl.add_class RDoc::NormalModule, 'M' + + c = RDoc::Parser::C + enclosure_classes = c.send :class_variable_get, :@@enclosure_classes + enclosure_classes['A'] = 'B' + known_bodies = c.send :class_variable_get, :@@known_bodies + known_bodies['A'] = 'B' + + RDoc::RDoc.reset + + assert_empty RDoc::TopLevel.all_classes_hash + assert_empty RDoc::TopLevel.all_files_hash + assert_empty RDoc::TopLevel.all_modules_hash + + assert_empty c.send :class_variable_get, :@@enclosure_classes + assert_empty c.send :class_variable_get, :@@known_bodies end def test_gather_files @@ -47,6 +62,20 @@ class TestRDocRDoc < MiniTest::Unit::TestCase assert_empty files end + def test_parse_file_encoding + skip "Encoding not implemented" unless Object.const_defined? :Encoding + @rdoc.options.encoding = Encoding::ISO_8859_1 + + Tempfile.open 'test.txt' do |io| + io.write 'hi' + io.rewind + + top_level = @rdoc.parse_file io.path + + assert_equal Encoding::ISO_8859_1, top_level.absolute_name.encoding + end + end + def test_remove_unparseable file_list = %w[ blah.class @@ -120,14 +149,16 @@ class TestRDocRDoc < MiniTest::Unit::TestCase end def test_setup_output_dir_exists_file - path = @tempfile.path + Tempfile.open 'test_rdoc_rdoc' do |tempfile| + path = tempfile.path - e = assert_raises RDoc::Error do - @rdoc.setup_output_dir path, false - end + e = assert_raises RDoc::Error do + @rdoc.setup_output_dir path, false + end - assert_match(%r%#{Regexp.escape path} exists and is not a directory%, - e.message) + assert_match(%r%#{Regexp.escape path} exists and is not a directory%, + e.message) + end end def test_setup_output_dir_exists_not_rdoc diff --git a/test/rdoc/test_rdoc_ri_driver.rb b/test/rdoc/test_rdoc_ri_driver.rb index b0e0e787c0..da7d160047 100644 --- a/test/rdoc/test_rdoc_ri_driver.rb +++ b/test/rdoc/test_rdoc_ri_driver.rb @@ -22,11 +22,11 @@ class TestRDocRIDriver < MiniTest::Unit::TestCase ENV['HOME'] = @tmpdir ENV.delete 'RI' - options = RDoc::RI::Driver.process_args [] - options[:home] = @tmpdir - options[:use_stdout] = true - options[:formatter] = @RM::ToRdoc - @driver = RDoc::RI::Driver.new options + @options = RDoc::RI::Driver.process_args [] + @options[:home] = @tmpdir + @options[:use_stdout] = true + @options[:formatter] = @RM::ToRdoc + @driver = RDoc::RI::Driver.new @options end def teardown @@ -191,12 +191,30 @@ class TestRDocRIDriver < MiniTest::Unit::TestCase def test_add_method_list out = @RM::Document.new - @driver.add_method_list out, %w[new], 'Class methods' + @driver.add_method_list out, %w[new parse], 'Class methods' expected = @RM::Document.new( @RM::Heading.new(1, 'Class methods:'), @RM::BlankLine.new, @RM::Verbatim.new('new'), + @RM::Verbatim.new('parse'), + @RM::BlankLine.new) + + assert_equal expected, out + end + + def test_add_method_list_interative + @options[:interactive] = true + driver = RDoc::RI::Driver.new @options + + out = @RM::Document.new + + driver.add_method_list out, %w[new parse], 'Class methods' + + expected = @RM::Document.new( + @RM::Heading.new(1, 'Class methods:'), + @RM::BlankLine.new, + @RM::IndentedParagraph.new(2, 'new, parse'), @RM::BlankLine.new) assert_equal expected, out @@ -272,6 +290,8 @@ class TestRDocRIDriver < MiniTest::Unit::TestCase def test_complete_classes util_store + assert_equal %w[ ], @driver.complete('[') + assert_equal %w[ ], @driver.complete('[::') 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') @@ -621,11 +641,13 @@ Foo::Bar#bother util_store index = RDoc::AnyMethod.new nil, '[]' + index.record_location @top_level @cFoo.add_method index @store.save_method @cFoo, index c_index = RDoc::AnyMethod.new nil, '[]' c_index.singleton = true + c_index.record_location @top_level @cFoo.add_method c_index @store.save_method @cFoo, c_index @@ -858,10 +880,12 @@ Foo::Bar#bother @cFoo_Baz.parent = @cFoo @baz = RDoc::AnyMethod.new nil, 'baz' + @baz.record_location @top_level @cBar.add_method @baz @override = RDoc::AnyMethod.new nil, 'override' @override.comment = 'must be displayed' + @override.record_location @top_level @cBar.add_method @override @store2.save_class @mAmbiguous @@ -879,6 +903,8 @@ Foo::Bar#bother def util_store @store = RDoc::RI::Store.new @home_ri + @top_level = RDoc::TopLevel.new 'file.rb' + @cFoo = RDoc::NormalClass.new 'Foo' @mInc = RDoc::NormalModule.new 'Inc' @cAmbiguous = RDoc::NormalClass.new 'Ambiguous' @@ -886,6 +912,7 @@ Foo::Bar#bother doc = @RM::Document.new @RM::Paragraph.new('Include thingy') @cFooInc = RDoc::Include.new 'Inc', doc + @cFooInc.record_location @top_level @cFoo.add_include @cFooInc @cFoo_Bar = RDoc::NormalClass.new 'Bar' @@ -893,12 +920,15 @@ Foo::Bar#bother @blah = RDoc::AnyMethod.new nil, 'blah' @blah.call_seq = "blah(5) => 5\nblah(6) => 6\n" + @blah.record_location @top_level @bother = RDoc::AnyMethod.new nil, 'bother' - @bother.params = "(things)" @bother.block_params = "stuff" + @bother.params = "(things)" + @bother.record_location @top_level @new = RDoc::AnyMethod.new nil, 'new' + @new.record_location @top_level @new.singleton = true @cFoo_Bar.add_method @blah @@ -906,6 +936,7 @@ Foo::Bar#bother @cFoo_Bar.add_method @new @attr = RDoc::Attr.new nil, 'attr', 'RW', '' + @attr.record_location @top_level @cFoo_Bar.add_attribute @attr @@ -913,11 +944,13 @@ Foo::Bar#bother @cFoo_Baz.parent = @cFoo @inherit = RDoc::AnyMethod.new nil, 'inherit' + @inherit.record_location @top_level @cFoo.add_method @inherit # overriden by Bar in multi_store @overriden = RDoc::AnyMethod.new nil, 'override' @overriden.comment = 'must not be displayed' + @overriden.record_location @top_level @cFoo.add_method @overriden @store.save_class @cFoo diff --git a/test/rdoc/test_rdoc_ri_store.rb b/test/rdoc/test_rdoc_ri_store.rb index 83aebf009b..1077383d86 100644 --- a/test/rdoc/test_rdoc_ri_store.rb +++ b/test/rdoc/test_rdoc_ri_store.rb @@ -4,9 +4,12 @@ require 'rdoc/ri' require 'rdoc/markup' require 'tmpdir' require 'fileutils' +require 'pp' class TestRDocRIStore < MiniTest::Unit::TestCase + OBJECT_ANCESTORS = defined?(::BasicObject) ? %w[BasicObject] : [] + def setup RDoc::TopLevel.reset @@ -16,15 +19,20 @@ class TestRDocRIStore < MiniTest::Unit::TestCase @top_level = RDoc::TopLevel.new 'file.rb' @klass = @top_level.add_class RDoc::NormalClass, 'Object' - @klass.comment = 'original' + @klass.add_comment 'original', @top_level @cmeth = RDoc::AnyMethod.new nil, 'cmethod' @cmeth.singleton = true + @cmeth.record_location @top_level @meth = RDoc::AnyMethod.new nil, 'method' + @meth.record_location @top_level + @meth_bang = RDoc::AnyMethod.new nil, 'method!' + @meth_bang.record_location @top_level @attr = RDoc::Attr.new nil, 'attr', 'RW', '' + @attr.record_location @top_level @klass.add_method @cmeth @klass.add_method @meth @@ -33,7 +41,10 @@ class TestRDocRIStore < MiniTest::Unit::TestCase @nest_klass = @klass.add_class RDoc::NormalClass, 'SubClass' @nest_meth = RDoc::AnyMethod.new nil, 'method' + @nest_meth.record_location @top_level + @nest_incl = RDoc::Include.new 'Incl', '' + @nest_incl.record_location @top_level @nest_klass.add_method @nest_meth @nest_klass.add_include @nest_incl @@ -45,15 +56,32 @@ class TestRDocRIStore < MiniTest::Unit::TestCase FileUtils.rm_rf @tmpdir end + def mu_pp obj + s = '' + s = PP.pp obj, s + s.force_encoding Encoding.default_external if defined? Encoding + s.chomp + end + def assert_cache imethods, cmethods, attrs, modules, ancestors = {} + imethods ||= { 'Object' => %w[method method!] } + cmethods ||= { 'Object' => %w[cmethod] } + attrs ||= { 'Object' => ['attr_accessor attr'] } + + # this is sort-of a hack + @s.clean_cache_collection ancestors + expected = { + :ancestors => ancestors, + :attributes => attrs, :class_methods => cmethods, + :encoding => nil, :instance_methods => imethods, - :attributes => attrs, :modules => modules, - :ancestors => ancestors } + @s.save_cache + assert_equal expected, @s.cache end @@ -138,8 +166,9 @@ class TestRDocRIStore < MiniTest::Unit::TestCase def test_load_cache cache = { - :methods => %w[Object#method], - :modules => %w[Object], + :encoding => :encoding_value, + :methods => %w[Object#method], + :modules => %w[Object], } Dir.mkdir @tmpdir @@ -151,6 +180,32 @@ class TestRDocRIStore < MiniTest::Unit::TestCase @s.load_cache assert_equal cache, @s.cache + + assert_equal :encoding_value, @s.encoding + end + + def test_load_cache_encoding_differs + skip "Encoding not implemented" unless Object.const_defined? :Encoding + + cache = { + :encoding => Encoding::ISO_8859_1, + :methods => %w[Object#method], + :modules => %w[Object], + } + + Dir.mkdir @tmpdir + + open File.join(@tmpdir, 'cache.ri'), 'wb' do |io| + Marshal.dump cache, io + end + + @s.encoding = Encoding::UTF_8 + + @s.load_cache + + assert_equal cache, @s.cache + + assert_equal Encoding::UTF_8, @s.encoding end def test_load_cache_no_cache @@ -158,6 +213,7 @@ class TestRDocRIStore < MiniTest::Unit::TestCase :ancestors => {}, :attributes => {}, :class_methods => {}, + :encoding => nil, :instance_methods => {}, :modules => [], } @@ -199,6 +255,7 @@ class TestRDocRIStore < MiniTest::Unit::TestCase @s.save_method @klass, @meth @s.save_method @klass, @cmeth @s.save_class @nest_klass + @s.encoding = :encoding_value @s.save_cache @@ -207,12 +264,15 @@ class TestRDocRIStore < MiniTest::Unit::TestCase expected = { :attributes => { 'Object' => ['attr_accessor attr'] }, :class_methods => { 'Object' => %w[cmethod] }, - :instance_methods => { 'Object' => %w[method] }, + :instance_methods => { + 'Object' => %w[method method!], + 'Object::SubClass' => %w[method], + }, :modules => %w[Object Object::SubClass], :ancestors => { - 'Object' => %w[], 'Object::SubClass' => %w[Incl Object], }, + :encoding => :encoding_value, } expected[:ancestors]['Object'] = %w[BasicObject] if defined?(::BasicObject) @@ -252,10 +312,7 @@ class TestRDocRIStore < MiniTest::Unit::TestCase assert_directory File.join(@tmpdir, 'Object') assert_file File.join(@tmpdir, 'Object', 'cdesc-Object.ri') - object_ancestors = defined?(::BasicObject) ? %w[BasicObject] : [] - - assert_cache({}, {}, { 'Object' => ['attr_accessor attr'] }, %w[Object], - 'Object' => object_ancestors) + assert_cache nil, nil, nil, %w[Object], 'Object' => OBJECT_ANCESTORS assert_equal @klass, @s.load_class('Object') end @@ -268,12 +325,45 @@ class TestRDocRIStore < MiniTest::Unit::TestCase assert_directory File.join(@tmpdir, 'Object') assert_file File.join(@tmpdir, 'Object', 'cdesc-Object.ri') - assert_cache({}, {}, { 'Object' => ['attr_accessor attr'] }, %w[Object], - 'Object' => %w[]) + assert_cache(nil, nil, nil, %w[Object]) assert_equal @klass, @s.load_class('Object') end + def test_save_class_delete + # save original + @s.save_class @klass + @s.save_method @klass, @meth + @s.save_method @klass, @meth_bang + @s.save_method @klass, @cmeth + @s.save_cache + + klass = RDoc::NormalClass.new 'Object' + + meth = klass.add_method RDoc::AnyMethod.new(nil, 'replace') + meth.record_location @top_level + + # load original, save newly updated class + @s = RDoc::RI::Store.new @tmpdir + @s.load_cache + @s.save_class klass + @s.save_cache + + # load from disk again + @s = RDoc::RI::Store.new @tmpdir + @s.load_cache + + @s.load_class 'Object' + + assert_cache({ 'Object' => %w[replace] }, {}, + { 'Object' => %w[attr_accessor\ attr] }, %w[Object], + 'Object' => OBJECT_ANCESTORS) + + refute File.exist? @s.method_file(@klass.full_name, @meth.full_name) + refute File.exist? @s.method_file(@klass.full_name, @meth_bang.full_name) + refute File.exist? @s.method_file(@klass.full_name, @cmeth.full_name) + end + def test_save_class_dry_run @s.dry_run = true @@ -287,16 +377,17 @@ class TestRDocRIStore < MiniTest::Unit::TestCase @s.save_class @klass klass = RDoc::NormalClass.new 'Object' - klass.comment = 'new class' + klass.add_comment 'new comment', @top_level s = RDoc::RI::Store.new @tmpdir s.save_class klass s = RDoc::RI::Store.new @tmpdir - document = @RM::Document.new( - @RM::Paragraph.new('original'), - @RM::Paragraph.new('new class')) + inner = @RM::Document.new @RM::Paragraph.new 'new comment' + inner.file = @top_level.absolute_name + + document = @RM::Document.new inner assert_equal document, s.load_class('Object').comment end @@ -307,10 +398,7 @@ class TestRDocRIStore < MiniTest::Unit::TestCase assert_directory File.join(@tmpdir, 'Object') assert_file File.join(@tmpdir, 'Object', 'cdesc-Object.ri') - object_ancestors = defined?(::BasicObject) ? %w[BasicObject] : [] - - assert_cache({}, {}, { 'Object' => ['attr_accessor attr'] }, %w[Object], - 'Object' => object_ancestors) + assert_cache nil, nil, nil, %w[Object], 'Object' => OBJECT_ANCESTORS assert_equal @klass, @s.load_class('Object') end @@ -321,8 +409,8 @@ class TestRDocRIStore < MiniTest::Unit::TestCase assert_directory File.join(@tmpdir, 'Object', 'SubClass') assert_file File.join(@tmpdir, 'Object', 'SubClass', 'cdesc-SubClass.ri') - assert_cache({}, {}, {}, %w[Object::SubClass], - 'Object::SubClass' => %w[Incl Object]) + assert_cache({ 'Object::SubClass' => %w[method] }, {}, {}, + %w[Object::SubClass], 'Object::SubClass' => %w[Incl Object]) end def test_save_method diff --git a/test/rdoc/test_rdoc_rubygems_hook.rb b/test/rdoc/test_rdoc_rubygems_hook.rb new file mode 100644 index 0000000000..e8f8621820 --- /dev/null +++ b/test/rdoc/test_rdoc_rubygems_hook.rb @@ -0,0 +1,201 @@ +require 'rubygems/test_case' +require 'rubygems' +require 'rdoc/rubygems_hook' + +class TestRDocRubygemsHook < Gem::TestCase + + def setup + super + skip 'requires RubyGems 1.9+' unless + Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.9') + + @a = quick_spec 'a' + + @rdoc = RDoc::RubygemsHook.new @a + + begin + RDoc::RubygemsHook.load_rdoc + rescue Gem::DocumentError => e + skip e.message + end + + Gem.configuration[:rdoc] = nil + end + + def test_initialize + assert @rdoc.generate_rdoc + assert @rdoc.generate_ri + + rdoc = RDoc::RubygemsHook.new @a, false, false + + refute rdoc.generate_rdoc + refute rdoc.generate_ri + end + + def test_delete_legacy_args + args = %w[ + --inline-source + --one-file + --promiscuous + -p + ] + + @rdoc.delete_legacy_args args + + assert_empty args + end + + def test_document + options = RDoc::Options.new + options.files = [] + + @rdoc.instance_variable_set :@rdoc, @rdoc.new_rdoc + @rdoc.instance_variable_set :@file_info, [] + + @rdoc.document 'darkfish', options, @a.doc_dir('rdoc') + + assert @rdoc.rdoc_installed? + end + + def test_generate + FileUtils.mkdir_p @a.doc_dir + FileUtils.mkdir_p File.join(@a.gem_dir, 'lib') + + @rdoc.generate + + assert @rdoc.rdoc_installed? + assert @rdoc.ri_installed? + + rdoc = @rdoc.instance_variable_get :@rdoc + + refute rdoc.options.hyperlink_all + end + + def test_generate_configuration_rdoc_array + Gem.configuration[:rdoc] = %w[-A] + + FileUtils.mkdir_p @a.doc_dir + FileUtils.mkdir_p File.join(@a.gem_dir, 'lib') + + @rdoc.generate + + rdoc = @rdoc.instance_variable_get :@rdoc + + assert rdoc.options.hyperlink_all + end + + def test_generate_configuration_rdoc_string + Gem.configuration[:rdoc] = '-A' + + FileUtils.mkdir_p @a.doc_dir + FileUtils.mkdir_p File.join(@a.gem_dir, 'lib') + + @rdoc.generate + + rdoc = @rdoc.instance_variable_get :@rdoc + + assert rdoc.options.hyperlink_all + end + + def test_generate_disabled + @rdoc.generate_rdoc = false + @rdoc.generate_ri = false + + @rdoc.generate + + refute @rdoc.rdoc_installed? + refute @rdoc.ri_installed? + end + + def test_generate_force + FileUtils.mkdir_p @a.doc_dir 'ri' + FileUtils.mkdir_p @a.doc_dir 'rdoc' + FileUtils.mkdir_p File.join(@a.gem_dir, 'lib') + + @rdoc.force = true + + @rdoc.generate + + assert_path_exists File.join(@a.doc_dir('rdoc'), 'index.html') + assert_path_exists File.join(@a.doc_dir('ri'), 'cache.ri') + end + + def test_generate_no_overwrite + FileUtils.mkdir_p @a.doc_dir 'ri' + FileUtils.mkdir_p @a.doc_dir 'rdoc' + FileUtils.mkdir_p File.join(@a.gem_dir, 'lib') + + @rdoc.generate + + refute_path_exists File.join(@a.doc_dir('rdoc'), 'index.html') + refute_path_exists File.join(@a.doc_dir('ri'), 'cache.ri') + end + + def test_new_rdoc + assert_kind_of RDoc::RDoc, @rdoc.new_rdoc + end + + def test_rdoc_installed? + refute @rdoc.rdoc_installed? + + FileUtils.mkdir_p @a.doc_dir 'rdoc' + + assert @rdoc.rdoc_installed? + end + + def test_remove + FileUtils.mkdir_p @a.doc_dir 'rdoc' + FileUtils.mkdir_p @a.doc_dir 'ri' + + @rdoc.remove + + refute @rdoc.rdoc_installed? + refute @rdoc.ri_installed? + + assert_path_exists @a.doc_dir + end + + def test_remove_unwritable + skip 'chmod not supported' if Gem.win_platform? + FileUtils.mkdir_p @a.base_dir + FileUtils.chmod 0, @a.base_dir + + e = assert_raises Gem::FilePermissionError do + @rdoc.remove + end + + assert_equal @a.base_dir, e.directory + ensure + FileUtils.chmod 0755, @a.base_dir + end + + def test_ri_installed? + refute @rdoc.ri_installed? + + FileUtils.mkdir_p @a.doc_dir 'ri' + + assert @rdoc.ri_installed? + end + + def test_setup + @rdoc.setup + + assert_path_exists @a.doc_dir + end + + def test_setup_unwritable + skip 'chmod not supported' if Gem.win_platform? + FileUtils.mkdir_p @a.doc_dir + FileUtils.chmod 0, @a.doc_dir + + e = assert_raises Gem::FilePermissionError do + @rdoc.setup + end + + assert_equal @a.doc_dir, e.directory + ensure + FileUtils.chmod 0755, @a.doc_dir + end + +end + diff --git a/test/rdoc/test_rdoc_stats.rb b/test/rdoc/test_rdoc_stats.rb index 17458adaa4..0bf08334da 100644 --- a/test/rdoc/test_rdoc_stats.rb +++ b/test/rdoc/test_rdoc_stats.rb @@ -17,7 +17,7 @@ class TestRDocStats < MiniTest::Unit::TestCase tl = RDoc::TopLevel.new 'file.rb' c = tl.add_class RDoc::NormalClass, 'C' c.record_location tl - c.comment = 'C' + c.add_comment 'C', tl a = RDoc::Attr.new nil, 'a', 'RW', nil a.record_location tl @@ -43,7 +43,7 @@ end tl = RDoc::TopLevel.new 'file.rb' c = tl.add_class RDoc::NormalClass, 'C' c.record_location tl - c.comment = 'C' + c.add_comment 'C', tl a = RDoc::Attr.new nil, 'a', 'RW', 'a' a.record_location tl @@ -60,7 +60,7 @@ end tl = RDoc::TopLevel.new 'file.rb' m = tl.add_module RDoc::NormalModule, 'M' m.record_location tl - m.comment = 'M' + m.add_comment 'M', tl c = RDoc::Constant.new 'C', nil, nil c.record_location tl @@ -152,7 +152,7 @@ end tl = RDoc::TopLevel.new 'file.rb' c = tl.add_class RDoc::NormalClass, 'C' c.record_location tl - c.comment = 'C' + c.add_comment 'C', tl m = RDoc::AnyMethod.new nil, 'm' m.record_location tl @@ -170,7 +170,7 @@ end tl = RDoc::TopLevel.new 'file.rb' c1 = tl.add_class RDoc::NormalClass, 'C1' c1.record_location tl - c1.comment = 'C1' + c1.add_comment 'C1', tl m1 = RDoc::AnyMethod.new nil, 'm1' m1.record_location tl @@ -231,7 +231,7 @@ The following items are not documented: c2 = tl.add_class RDoc::NormalClass, 'C2' c2.record_location tl - c2.comment = 'C2' + c2.add_comment 'C2', tl RDoc::TopLevel.complete :public @@ -291,7 +291,7 @@ end tl = RDoc::TopLevel.new 'file.rb' c = tl.add_class RDoc::NormalClass, 'C' c.record_location tl - c.comment = 'C' + c.add_comment 'C', tl m1 = RDoc::AnyMethod.new nil, 'm1' m1.record_location tl @@ -324,7 +324,7 @@ end tl = RDoc::TopLevel.new 'file.rb' c = tl.add_class RDoc::NormalClass, 'C' c.record_location tl - c.comment = 'C' + c.add_comment 'C', tl m = RDoc::AnyMethod.new nil, 'm' m.record_location tl @@ -342,7 +342,7 @@ end tl = RDoc::TopLevel.new 'file.rb' c = tl.add_class RDoc::NormalClass, 'C' c.record_location tl - c.comment = 'C' + c.add_comment 'C', tl m1 = RDoc::AnyMethod.new nil, 'm1' m1.record_location tl @@ -379,7 +379,7 @@ end tl = RDoc::TopLevel.new 'file.rb' c = tl.add_class RDoc::NormalClass, 'C' c.record_location tl - c.comment = 'C' + c.add_comment 'C', tl m = RDoc::AnyMethod.new nil, 'm' m.record_location tl @@ -399,7 +399,7 @@ end tl = RDoc::TopLevel.new 'file.rb' c = tl.add_class RDoc::NormalClass, 'C' c.record_location tl - c.comment = 'C' + c.add_comment 'C', tl m = RDoc::AnyMethod.new nil, 'm' m.record_location tl @@ -505,7 +505,7 @@ Total: 1 (1 undocumented) tl = RDoc::TopLevel.new 'file.rb' c = tl.add_class RDoc::NormalClass, 'C' c.record_location tl - c.comment = 'C' + c.add_comment 'C', tl m = RDoc::AnyMethod.new nil, 'm' m.record_location tl diff --git a/test/rdoc/test_rdoc_text.rb b/test/rdoc/test_rdoc_text.rb index 96635aaa8e..e11c995e59 100644 --- a/test/rdoc/test_rdoc_text.rb +++ b/test/rdoc/test_rdoc_text.rb @@ -240,6 +240,23 @@ The comments associated with assert_equal expected, strip_stars(text) end + def test_strip_stars_document_method + text = <<-TEXT +/* + * Document-method: Zlib::GzipFile#mtime= + * + * A comment + */ + TEXT + + expected = <<-EXPECTED + + A comment + EXPECTED + + assert_equal expected, strip_stars(text) + end + def test_strip_stars_encoding skip "Encoding not implemented" unless Object.const_defined? :Encoding diff --git a/test/rdoc/test_rdoc_top_level.rb b/test/rdoc/test_rdoc_top_level.rb index 89f64247f9..6c1bc43e7a 100644 --- a/test/rdoc/test_rdoc_top_level.rb +++ b/test/rdoc/test_rdoc_top_level.rb @@ -81,6 +81,15 @@ class TestRDocTopLevel < XrefTestCase RDoc::TopLevel.modules.map { |m| m.full_name }.sort end + def test_class_new + tl1 = RDoc::TopLevel.new 'file.rb' + tl2 = RDoc::TopLevel.new 'file.rb' + tl3 = RDoc::TopLevel.new 'other.rb' + + assert_same tl1, tl2 + refute_same tl1, tl3 + end + def test_class_reset RDoc::TopLevel.reset @@ -93,6 +102,24 @@ class TestRDocTopLevel < XrefTestCase assert_equal 'top_level.rb', @top_level.base_name end + def test_eql_eh + top_level2 = RDoc::TopLevel.new 'path/top_level.rb' + other_level = RDoc::TopLevel.new 'path/other_level.rb' + + assert_operator @top_level, :eql?, top_level2 + + refute_operator other_level, :eql?, @top_level + end + + def test_equals2 + top_level2 = RDoc::TopLevel.new 'path/top_level.rb' + other_level = RDoc::TopLevel.new 'path/other_level.rb' + + assert_equal @top_level, top_level2 + + refute_equal other_level, @top_level + end + def test_find_class_or_module assert_equal @c1, @xref_data.find_class_or_module('C1') assert_equal @c2_c3, @xref_data.find_class_or_module('C2::C3') @@ -104,6 +131,14 @@ class TestRDocTopLevel < XrefTestCase assert_equal 'path/top_level.rb', @top_level.full_name end + def test_hash + tl2 = RDoc::TopLevel.new 'path/top_level.rb' + tl3 = RDoc::TopLevel.new 'other/top_level.rb' + + assert_equal @top_level.hash, tl2.hash + refute_equal @top_level.hash, tl3.hash + end + def test_http_url assert_equal 'prefix/path/top_level_rb.html', @top_level.http_url('prefix') end -- cgit v1.2.3