Skip to content

Commit

Permalink
Fixed dumping previously loaded Constant which is an alias
Browse files Browse the repository at this point in the history
  • Loading branch information
drbrain committed Nov 27, 2012
1 parent ff071bb commit 226bc98
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
17 changes: 12 additions & 5 deletions lib/rdoc/constant.rb
Expand Up @@ -79,7 +79,9 @@ def full_name
def is_alias_for def is_alias_for
case @is_alias_for case @is_alias_for
when String then 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 else
@is_alias_for @is_alias_for
end end
Expand All @@ -96,16 +98,21 @@ def inspect # :nodoc:
# Dumps this Constant for use by ri. See also #marshal_load # Dumps this Constant for use by ri. See also #marshal_load


def marshal_dump def marshal_dump
alias_name = case found = is_alias_for
when RDoc::CodeObject then found.full_name
else found
end

[ MARSHAL_VERSION, [ MARSHAL_VERSION,
@name, @name,
full_name, full_name,
@visibility, @visibility,
@is_alias_for ? @is_alias_for.full_name : nil, alias_name,
parse(@comment), parse(@comment),
@file.absolute_name, @file.absolute_name,
@parent_name || @parent.name, parent.name,
@parent_class || @parent.class, parent.class,
@section_title || section.title, section.title,
] ]
end end


Expand Down
23 changes: 21 additions & 2 deletions test/test_rdoc_constant.rb
Expand Up @@ -12,6 +12,23 @@ def test_full_name
assert_equal 'C1::CONST', @const.full_name assert_equal 'C1::CONST', @const.full_name
end 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 def test_marshal_dump
top_level = @store.add_file 'file.rb' top_level = @store.add_file 'file.rb'


Expand Down Expand Up @@ -101,11 +118,12 @@ def test_marshal_load_version_0
assert_equal section, loaded.section assert_equal section, loaded.section
end end


def test_marshal_round_trip_section def test_marshal_round_trip
top_level = @store.add_file 'file.rb' top_level = @store.add_file 'file.rb'


c = RDoc::Constant.new 'CONST', nil, 'this is a comment' c = RDoc::Constant.new 'CONST', nil, 'this is a comment'
c.record_location top_level c.record_location top_level
c.is_alias_for = 'Unknown'


cm = top_level.add_class RDoc::NormalClass, 'Klass' cm = top_level.add_class RDoc::NormalClass, 'Klass'
cm.add_constant c cm.add_constant c
Expand All @@ -118,7 +136,8 @@ def test_marshal_round_trip_section
reloaded = Marshal.load Marshal.dump loaded reloaded = Marshal.load Marshal.dump loaded
reloaded.store = @store reloaded.store = @store


assert_equal section, reloaded.section assert_equal section, reloaded.section
assert_equal 'Unknown', reloaded.is_alias_for
end end


def test_path def test_path
Expand Down

0 comments on commit 226bc98

Please sign in to comment.