mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
97ac172d58
commit
b7528b5edb
58 changed files with 2637 additions and 277 deletions
|
@ -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 = {
|
||||
:class_methods => cmethods,
|
||||
:instance_methods => imethods,
|
||||
:ancestors => ancestors,
|
||||
:attributes => attrs,
|
||||
:class_methods => cmethods,
|
||||
:encoding => nil,
|
||||
:instance_methods => imethods,
|
||||
: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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue