summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorStan Lo <[email protected]>2024-12-10 01:20:58 +0800
committergit <[email protected]>2024-12-09 17:21:01 +0000
commit93f8de777f690b5cb98b7974fa5e0a232eafbb4b (patch)
tree0cdbe182365558902c34647b47e2f1017d6ac7f3 /test
parent7341a4fc07ec8f12ff25538d39383ecf68a5f852 (diff)
[ruby/rdoc] Expand rdoc-ref targets at the end of ri output
(https://github.com/ruby/rdoc/pull/1141) There have been several document refactors in ruby/ruby that extract individual methods/classes' documentation into separate files, like ruby/ruby#6567 Because RI is not capable of rendering those references, RI users are left with dramatically fewer documentation on those methods/classes. This commit adds a new option `--expand-ref` (default: true) to expand all the rdoc-ref targets at the end of the output. https://github.com/ruby/rdoc/commit/9e2b28c6e3
Diffstat (limited to 'test')
-rw-r--r--test/rdoc/test_rdoc_ri_driver.rb57
1 files changed, 54 insertions, 3 deletions
diff --git a/test/rdoc/test_rdoc_ri_driver.rb b/test/rdoc/test_rdoc_ri_driver.rb
index 3263e6173e..37372391cf 100644
--- a/test/rdoc/test_rdoc_ri_driver.rb
+++ b/test/rdoc/test_rdoc_ri_driver.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
require_relative 'helper'
-class TestRDocRIDriver < RDoc::TestCase
+class RDocRIDriverTest < RDoc::TestCase
def setup
super
@@ -243,6 +243,29 @@ class TestRDocRIDriver < RDoc::TestCase
assert_equal expected, out
end
+ def test_add_method_with_rdoc_ref_link
+ util_store
+
+ out = doc
+
+ @driver.add_method out, 'Foo::Bar#blah_with_rdoc_ref'
+
+ expected =
+ doc(
+ head(1, 'Foo::Bar#blah_with_rdoc_ref'),
+ blank_line,
+ para("(from #{@rdoc_home})"),
+ head(3, 'Implementation from Bar'),
+ rule(1),
+ verb("blah(5) => 5\n", "See also {Doc}[rdoc-ref:README.rdoc]\n"),
+ rule(1),
+ blank_line,
+ blank_line
+ )
+
+ assert_equal expected, out
+ end
+
def test_add_method_that_is_alias_for_original
util_store
@@ -598,7 +621,7 @@ class TestRDocRIDriver < RDoc::TestCase
assert_match %r%^= Attributes:%, out
assert_match %r%^ attr_accessor attr%, out
- assert_equal 1, out.scan(/^-{50,}$/).length, out
+ assert_equal 2, out.scan(/^-{50,}$/).length, out
refute_match %r%Foo::Bar#blah%, out
end
@@ -622,9 +645,29 @@ class TestRDocRIDriver < RDoc::TestCase
assert_match %r%^= Attributes:%, out
assert_match %r%^ attr_accessor attr%, out
- assert_equal 6, out.scan(/^-{50,}$/).length, out
+ assert_equal 9, out.scan(/^-{50,}$/).length, out
assert_match %r%Foo::Bar#blah%, out
+ assert_match %r%Foo::Bar#blah_with_rdoc_ref%, out
+ # From Foo::Bar and Foo::Bar#blah_with_rdoc_ref
+ assert_equal 2, out.scan(/rdoc-ref:README.rdoc/).length
+ # But README.rdoc should only be displayed once
+ assert_equal 1, out.scan(/Expanded from README.rdoc/).length
+ end
+
+ def test_rdoc_refs_expansion_can_be_disabled
+ util_store
+
+ @driver.instance_variable_set :@expand_rdoc_refs, false
+
+ out, = capture_output do
+ @driver.display_class 'Foo::Bar'
+ end
+
+ # From Foo::Bar
+ assert_equal 1, out.scan(/rdoc-ref:README.rdoc/).length
+ # But README.rdoc should not be expanded
+ assert_empty out.scan(/Expanded from README.rdoc/)
end
def test_display_class_ambiguous
@@ -766,6 +809,7 @@ Foo::Baz
Foo::Bar#b not found, maybe you meant:
Foo::Bar#blah
+Foo::Bar#blah_with_rdoc_ref
Foo::Bar#bother
EXPECTED
@@ -1141,6 +1185,7 @@ Foo::Bar#bother
assert_equal %w[
Foo::Bar#attr
Foo::Bar#blah
+ Foo::Bar#blah_with_rdoc_ref
Foo::Bar#bother
Foo::Bar::new
],
@@ -1516,11 +1561,17 @@ Foo::Bar#bother
@cFooInc.record_location @top_level
@cFoo_Bar = @cFoo.add_class RDoc::NormalClass, 'Bar'
+ @cFoo_Bar.add_comment "See also {Doc}[rdoc-ref:README.rdoc]", @top_level
+ @cFoo_Bar.record_location @top_level
@blah = @cFoo_Bar.add_method RDoc::AnyMethod.new(nil, 'blah')
@blah.call_seq = "blah(5) => 5\nblah(6) => 6\n"
@blah.record_location @top_level
+ @blah_with_rdoc_ref = @cFoo_Bar.add_method RDoc::AnyMethod.new(nil, 'blah_with_rdoc_ref')
+ @blah_with_rdoc_ref.call_seq = "blah(5) => 5\nSee also {Doc}[rdoc-ref:README.rdoc]"
+ @blah_with_rdoc_ref.record_location @top_level
+
@bother = @cFoo_Bar.add_method RDoc::AnyMethod.new(nil, 'bother')
@bother.block_params = "stuff"
@bother.params = "(things)"