Skip to content

Commit

Permalink
Merge pull request #400 from nurse/support-expand-class-even-if-its-a…
Browse files Browse the repository at this point in the history
…ncestor-is-short

Improve expand class name
  • Loading branch information
Zachary Scott committed Mar 25, 2016
2 parents e1ac8f8 + f9ffe66 commit df7f8db
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
19 changes: 3 additions & 16 deletions lib/rdoc/ri/driver.rb
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
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

0 comments on commit df7f8db

Please sign in to comment.