1
1
# frozen_string_literal: true
2
2
require_relative 'helper'
3
3
4
- class TestRDocRIDriver < RDoc ::TestCase
4
+ class RDocRIDriverTest < RDoc ::TestCase
5
5
6
6
def setup
7
7
super
@@ -243,6 +243,29 @@ def test_add_method
243
243
assert_equal expected , out
244
244
end
245
245
246
+ def test_add_method_with_rdoc_ref_link
247
+ util_store
248
+
249
+ out = doc
250
+
251
+ @driver . add_method out , 'Foo::Bar#blah_with_rdoc_ref'
252
+
253
+ expected =
254
+ doc (
255
+ head ( 1 , 'Foo::Bar#blah_with_rdoc_ref' ) ,
256
+ blank_line ,
257
+ para ( "(from #{ @rdoc_home } )" ) ,
258
+ head ( 3 , 'Implementation from Bar' ) ,
259
+ rule ( 1 ) ,
260
+ verb ( "blah(5) => 5\n " , "See also {Doc}[rdoc-ref:README.rdoc]\n " ) ,
261
+ rule ( 1 ) ,
262
+ blank_line ,
263
+ blank_line
264
+ )
265
+
266
+ assert_equal expected , out
267
+ end
268
+
246
269
def test_add_method_that_is_alias_for_original
247
270
util_store
248
271
@@ -598,7 +621,7 @@ def test_display_class
598
621
assert_match %r%^= Attributes:% , out
599
622
assert_match %r%^ attr_accessor attr% , out
600
623
601
- assert_equal 1 , out . scan ( /^-{50,}$/ ) . length , out
624
+ assert_equal 2 , out . scan ( /^-{50,}$/ ) . length , out
602
625
603
626
refute_match %r%Foo::Bar#blah% , out
604
627
end
@@ -622,9 +645,29 @@ def test_display_class_all
622
645
assert_match %r%^= Attributes:% , out
623
646
assert_match %r%^ attr_accessor attr% , out
624
647
625
- assert_equal 6 , out . scan ( /^-{50,}$/ ) . length , out
648
+ assert_equal 9 , out . scan ( /^-{50,}$/ ) . length , out
626
649
627
650
assert_match %r%Foo::Bar#blah% , out
651
+ assert_match %r%Foo::Bar#blah_with_rdoc_ref% , out
652
+ # From Foo::Bar and Foo::Bar#blah_with_rdoc_ref
653
+ assert_equal 2 , out . scan ( /rdoc-ref:README.rdoc/ ) . length
654
+ # But README.rdoc should only be displayed once
655
+ assert_equal 1 , out . scan ( /Expanded from README.rdoc/ ) . length
656
+ end
657
+
658
+ def test_rdoc_refs_expansion_can_be_disabled
659
+ util_store
660
+
661
+ @driver . instance_variable_set :@expand_rdoc_refs , false
662
+
663
+ out , = capture_output do
664
+ @driver . display_class 'Foo::Bar'
665
+ end
666
+
667
+ # From Foo::Bar
668
+ assert_equal 1 , out . scan ( /rdoc-ref:README.rdoc/ ) . length
669
+ # But README.rdoc should not be expanded
670
+ assert_empty out . scan ( /Expanded from README.rdoc/ )
628
671
end
629
672
630
673
def test_display_class_ambiguous
@@ -766,6 +809,7 @@ def test_display_name_not_found_method
766
809
Foo::Bar#b not found, maybe you meant:
767
810
768
811
Foo::Bar#blah
812
+ Foo::Bar#blah_with_rdoc_ref
769
813
Foo::Bar#bother
770
814
EXPECTED
771
815
@@ -1141,6 +1185,7 @@ def test_list_methods_matching
1141
1185
assert_equal %w[
1142
1186
Foo::Bar#attr
1143
1187
Foo::Bar#blah
1188
+ Foo::Bar#blah_with_rdoc_ref
1144
1189
Foo::Bar#bother
1145
1190
Foo::Bar::new
1146
1191
] ,
@@ -1516,11 +1561,17 @@ def util_store
1516
1561
@cFooInc . record_location @top_level
1517
1562
1518
1563
@cFoo_Bar = @cFoo . add_class RDoc ::NormalClass , 'Bar'
1564
+ @cFoo_Bar . add_comment "See also {Doc}[rdoc-ref:README.rdoc]" , @top_level
1565
+ @cFoo_Bar . record_location @top_level
1519
1566
1520
1567
@blah = @cFoo_Bar . add_method RDoc ::AnyMethod . new ( nil , 'blah' )
1521
1568
@blah . call_seq = "blah(5) => 5\n blah(6) => 6\n "
1522
1569
@blah . record_location @top_level
1523
1570
1571
+ @blah_with_rdoc_ref = @cFoo_Bar . add_method RDoc ::AnyMethod . new ( nil , 'blah_with_rdoc_ref' )
1572
+ @blah_with_rdoc_ref . call_seq = "blah(5) => 5\n See also {Doc}[rdoc-ref:README.rdoc]"
1573
+ @blah_with_rdoc_ref . record_location @top_level
1574
+
1524
1575
@bother = @cFoo_Bar . add_method RDoc ::AnyMethod . new ( nil , 'bother' )
1525
1576
@bother . block_params = "stuff"
1526
1577
@bother . params = "(things)"
0 commit comments