[前][次][番号順一覧][スレッド一覧]

ruby-changes:66685

From: Ulysse <ko1@a...>
Date: Mon, 5 Jul 2021 18:35:33 +0900 (JST)
Subject: [ruby-changes:66685] ec9a9af375 (master): [ruby/rdoc] Fix chained inclusion ancestors_of

https://git.ruby-lang.org/ruby.git/commit/?id=ec9a9af375

From ec9a9af3754671cd066eb9827c4207b36a5f9dba Mon Sep 17 00:00:00 2001
From: Ulysse Buonomo <buonomo.ulysse@g...>
Date: Sun, 27 Jun 2021 00:33:34 +0200
Subject: [ruby/rdoc] Fix chained inclusion ancestors_of

Fixes #814

Signed-off-by: Ulysse Buonomo <buonomo.ulysse@g...>

https://github.com/ruby/rdoc/commit/b45f747216
---
 lib/rdoc/ri/driver.rb            |  8 ++++----
 test/rdoc/test_rdoc_ri_driver.rb | 24 ++++++++++++++++++++++++
 2 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/lib/rdoc/ri/driver.rb b/lib/rdoc/ri/driver.rb
index 0408cbb..7549a39 100644
--- a/lib/rdoc/ri/driver.rb
+++ b/lib/rdoc/ri/driver.rb
@@ -616,11 +616,11 @@ or the PAGER environment variable. https://github.com/ruby/ruby/blob/trunk/lib/rdoc/ri/driver.rb#L616
 
       stores = classes[current]
 
-      break unless stores and not stores.empty?
+      next unless stores and not stores.empty?
 
-      klasses = stores.map do |store|
-        store.ancestors[current]
-      end.flatten.uniq
+      klasses = stores.flat_map do |store|
+        store.ancestors[current] || []
+      end.uniq
 
       klasses = klasses - seen
 
diff --git a/test/rdoc/test_rdoc_ri_driver.rb b/test/rdoc/test_rdoc_ri_driver.rb
index f79d17b..87e4ebd 100644
--- a/test/rdoc/test_rdoc_ri_driver.rb
+++ b/test/rdoc/test_rdoc_ri_driver.rb
@@ -421,6 +421,30 @@ class TestRDocRIDriver < RDoc::TestCase https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_ri_driver.rb#L421
     assert_equal %w[X Mixin Object Foo], @driver.ancestors_of('Foo::Bar')
   end
 
+  def test_ancestors_of_chained_inclusion
+    # Store represents something like:
+    #
+    #   module X
+    #   end
+    #
+    #   module Y
+    #     include X
+    #   end
+    #
+    #   class Z
+    #     include Y
+    #   end
+    #
+    # Y is not chosen randomly, it has to be after Object in the alphabet
+    # to reproduce https://github.com/ruby/rdoc/issues/814.
+    store = RDoc::RI::Store.new @home_ri
+    store.cache[:ancestors] = { "Z" => ["Object", "Y"], "Y" => ["X"] }
+    store.cache[:modules] = %W[X Y Z]
+    @driver.stores = [store]
+
+    assert_equal %w[X Y Object], @driver.ancestors_of('Z')
+  end
+
   def test_classes
     util_multi_store
 
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]