Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 3 additions & 16 deletions lib/rdoc/ri/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -907,22 +907,9 @@ def display_page_list store, pages = store.cache[:pages], search = nil
# will be expanded to Zlib::DataError.

def expand_class klass
klass.split('::').inject '' do |expanded, klass_part|
expanded << '::' unless expanded.empty?
short = expanded << klass_part

subset = classes.keys.select do |klass_name|
klass_name =~ /^#{expanded}[^:]*$/
end

abbrevs = Abbrev.abbrev subset

expanded = abbrevs[short]

raise NotFoundError, short unless expanded

expanded.dup
end
ary = classes.keys.grep(Regexp.new("\\A#{klass.gsub(/(?=::|\z)/, '[^:]*')}\\z"))
raise NotFoundError, klass if ary.length != 1
ary.first
end

##
Expand Down
18 changes: 18 additions & 0 deletions test/test_rdoc_ri_driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,24 @@ def test_expand_class
end
end

def test_expand_class_2
@store1 = RDoc::RI::Store.new @home_ri, :home

@top_level = @store1.add_file 'file.rb'

@cFoo = @top_level.add_class RDoc::NormalClass, 'Foo'
@mFox = @top_level.add_module RDoc::NormalModule, 'Fox'
@cFoo_Bar = @cFoo.add_class RDoc::NormalClass, 'Bar'
@store1.save

@driver.stores = [@store1]
assert_raises RDoc::RI::Driver::NotFoundError do
@driver.expand_class 'F'
end
assert_equal 'Foo::Bar', @driver.expand_class('F::Bar')
assert_equal 'Foo::Bar', @driver.expand_class('F::B')
end

def test_expand_name
util_store

Expand Down