1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/test/rdoc/test_rdoc_constant.rb
drbrain 5864dbc9f1 * lib/rdoc/servlet.rb: Fixed display of site and home documentation.
Fixes rdoc issue #170 by Thomas Leitner.
* test/rdoc/test_rdoc_servlet.rb:  Test for above.

* lib/rdoc/code_object.rb:  Split #initialize_visibility from
  #initialize for reuse when loading a stored object.
  Fixes rdoc issue #171 by Thomas Leitner.

* lib/rdoc/any_method.rb:  Initialize visibility for #display?  For
  rdoc issue #171
* lib/rdoc/attr.rb:  ditto.
* lib/rdoc/class_module.rb:  ditto.
* lib/rdoc/top_level.rb:  ditto.
* test/rdoc/test_rdoc_any_method.rb:  Test for above.
* test/rdoc/test_rdoc_attr.rb:  ditto.
* test/rdoc/test_rdoc_class_module.rb:  ditto.
* test/rdoc/test_rdoc_constant.rb:  ditto.
* test/rdoc/test_rdoc_top_level.rb:  ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38899 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-01-23 01:02:24 +00:00

151 lines
4.1 KiB
Ruby

require File.expand_path '../xref_test_case', __FILE__
class TestRDocConstant < XrefTestCase
def setup
super
@const = @c1.constants.first
end
def test_full_name
assert_equal 'C1::CONST', @const.full_name
end
def test_is_alias_for
top_level = @store.add_file 'file.rb'
c = RDoc::Constant.new 'CONST', nil, 'comment'
top_level.add_constant c
assert_nil c.is_alias_for
c.is_alias_for = 'C1'
assert_equal @c1, c.is_alias_for
c.is_alias_for = 'unknown'
assert_equal 'unknown', c.is_alias_for
end
def test_marshal_dump
top_level = @store.add_file 'file.rb'
c = RDoc::Constant.new 'CONST', nil, 'this is a comment'
c.record_location top_level
aliased = top_level.add_class RDoc::NormalClass, 'Aliased'
c.is_alias_for = aliased
cm = top_level.add_class RDoc::NormalClass, 'Klass'
cm.add_constant c
section = cm.sections.first
loaded = Marshal.load Marshal.dump c
loaded.store = @store
comment = doc(para('this is a comment'))
assert_equal c, loaded
assert_equal aliased, loaded.is_alias_for
assert_equal comment, loaded.comment
assert_equal top_level, loaded.file
assert_equal 'Klass::CONST', loaded.full_name
assert_equal 'CONST', loaded.name
assert_nil loaded.visibility
assert_equal cm, loaded.parent
assert_equal section, loaded.section
end
def test_marshal_load
top_level = @store.add_file 'file.rb'
c = RDoc::Constant.new 'CONST', nil, 'this is a comment'
c.record_location top_level
cm = top_level.add_class RDoc::NormalClass, 'Klass'
cm.add_constant c
section = cm.sections.first
loaded = Marshal.load Marshal.dump c
loaded.store = @store
comment = doc(para('this is a comment'))
assert_equal c, loaded
assert_nil loaded.is_alias_for
assert_equal comment, loaded.comment
assert_equal top_level, loaded.file
assert_equal 'Klass::CONST', loaded.full_name
assert_equal 'CONST', loaded.name
assert_nil loaded.visibility
assert_equal cm, loaded.parent
assert_equal section, loaded.section
assert loaded.display?
end
def test_marshal_load_version_0
top_level = @store.add_file 'file.rb'
aliased = top_level.add_class RDoc::NormalClass, 'Aliased'
cm = top_level.add_class RDoc::NormalClass, 'Klass'
section = cm.sections.first
loaded = Marshal.load "\x04\bU:\x13RDoc::Constant[\x0Fi\x00I" +
"\"\nCONST\x06:\x06ETI\"\x11Klass::CONST\x06" +
";\x06T0I\"\fAliased\x06;\x06To" +
":\eRDoc::Markup::Document\a:\v@parts[\x06o" +
":\x1CRDoc::Markup::Paragraph\x06;\b[\x06I" +
"\"\x16this is a comment\x06;\x06T:\n@file0I" +
"\"\ffile.rb\x06;\x06TI\"\nKlass\x06" +
";\x06Tc\x16RDoc::NormalClass0"
loaded.store = @store
comment = doc(para('this is a comment'))
assert_equal aliased, loaded.is_alias_for
assert_equal comment, loaded.comment
assert_equal top_level, loaded.file
assert_equal 'Klass::CONST', loaded.full_name
assert_equal 'CONST', loaded.name
assert_nil loaded.visibility
assert_equal cm, loaded.parent
assert_equal section, loaded.section
assert loaded.display?
end
def test_marshal_round_trip
top_level = @store.add_file 'file.rb'
c = RDoc::Constant.new 'CONST', nil, 'this is a comment'
c.record_location top_level
c.is_alias_for = 'Unknown'
cm = top_level.add_class RDoc::NormalClass, 'Klass'
cm.add_constant c
section = cm.sections.first
loaded = Marshal.load Marshal.dump c
loaded.store = @store
reloaded = Marshal.load Marshal.dump loaded
reloaded.store = @store
assert_equal section, reloaded.section
assert_equal 'Unknown', reloaded.is_alias_for
end
def test_path
assert_equal 'C1.html#CONST', @const.path
end
end