Permalink
Browse files

Fixed dumping previously loaded Constant which is an alias

  • Loading branch information...
1 parent ff071bb commit 226bc982e1c1e92555d681243534a88992eb8852 @drbrain drbrain committed Nov 27, 2012
Showing with 33 additions and 7 deletions.
  1. +12 −5 lib/rdoc/constant.rb
  2. +21 −2 test/test_rdoc_constant.rb
View
@@ -79,7 +79,9 @@ def full_name
def is_alias_for
case @is_alias_for
when String then
- @is_alias_for = @store.find_class_or_module @is_alias_for
+ found = @store.find_class_or_module @is_alias_for
+ @is_alias_for = found if found
+ @is_alias_for
else
@is_alias_for
end
@@ -96,16 +98,21 @@ def inspect # :nodoc:
# Dumps this Constant for use by ri. See also #marshal_load
def marshal_dump
+ alias_name = case found = is_alias_for
+ when RDoc::CodeObject then found.full_name
+ else found
+ end
+
[ MARSHAL_VERSION,
@name,
full_name,
@visibility,
- @is_alias_for ? @is_alias_for.full_name : nil,
+ alias_name,
parse(@comment),
@file.absolute_name,
- @parent_name || @parent.name,
- @parent_class || @parent.class,
- @section_title || section.title,
+ parent.name,
+ parent.class,
+ section.title,
]
end
View
@@ -12,6 +12,23 @@ 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'
@@ -101,11 +118,12 @@ def test_marshal_load_version_0
assert_equal section, loaded.section
end
- def test_marshal_round_trip_section
+ 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
@@ -118,7 +136,8 @@ def test_marshal_round_trip_section
reloaded = Marshal.load Marshal.dump loaded
reloaded.store = @store
- assert_equal section, reloaded.section
+ assert_equal section, reloaded.section
+ assert_equal 'Unknown', reloaded.is_alias_for
end
def test_path

0 comments on commit 226bc98

Please sign in to comment.