@@ -1500,4 +1500,132 @@ def test_update_extends_with_colons
1500
1500
assert_equal [ a , c ] , @c1 . extends
1501
1501
end
1502
1502
1503
+ class TestRDocClassModuleMixins < XrefTestCase
1504
+ def setup
1505
+ super
1506
+
1507
+ klass_tl = @store . add_file ( "klass.rb" )
1508
+ @klass = klass_tl . add_class ( RDoc ::NormalClass , "Klass" )
1509
+
1510
+ incmod_tl = @store . add_file ( "incmod.rb" )
1511
+ @incmod = incmod_tl . add_module ( RDoc ::NormalModule , "Incmod" )
1512
+
1513
+ incmod_const = @incmod . add_constant ( RDoc ::Constant . new ( "INCMOD_CONST_WITHOUT_A_SECTION" , nil , "" ) )
1514
+ incmod_const = @incmod . add_constant ( RDoc ::Constant . new ( "INCMOD_CONST" , nil , "" ) )
1515
+ incmod_const . section = @incmod . add_section ( "Incmod const section" )
1516
+
1517
+ incmod_method = @incmod . add_method ( RDoc ::AnyMethod . new ( nil , "incmod_method_without_a_section" ) )
1518
+ incmod_method = @incmod . add_method ( RDoc ::AnyMethod . new ( nil , "incmod_method" ) )
1519
+ incmod_method . section = @incmod . add_section ( "Incmod method section" )
1520
+
1521
+ incmod_attr = @incmod . add_attribute ( RDoc ::Attr . new ( nil , "incmod_attr_without_a_section" , "RW" , "" ) )
1522
+ incmod_attr = @incmod . add_attribute ( RDoc ::Attr . new ( nil , "incmod_attr" , "RW" , "" ) )
1523
+ incmod_attr . section = @incmod . add_section ( "Incmod attr section" )
1524
+
1525
+ incmod_private_method = @incmod . add_method ( RDoc ::AnyMethod . new ( nil , "incmod_private_method" ) )
1526
+ incmod_private_method . visibility = :private
1527
+
1528
+ extmod_tl = @store . add_file ( "extmod.rb" )
1529
+ @extmod = extmod_tl . add_module ( RDoc ::NormalModule , "Extmod" )
1530
+
1531
+ extmod_method = @extmod . add_method ( RDoc ::AnyMethod . new ( nil , "extmod_method_without_a_section" ) )
1532
+ extmod_method = @extmod . add_method ( RDoc ::AnyMethod . new ( nil , "extmod_method" ) )
1533
+ extmod_method . section = @extmod . add_section ( "Extmod method section" )
1534
+
1535
+ extmod_attr = @extmod . add_attribute ( RDoc ::Attr . new ( nil , "extmod_attr_without_a_section" , "RW" , "" , true ) )
1536
+ extmod_attr = @extmod . add_attribute ( RDoc ::Attr . new ( nil , "extmod_attr" , "RW" , "" , true ) )
1537
+ extmod_attr . section = @extmod . add_section ( "Extmod attr section" )
1538
+
1539
+ extmod_private_method = @extmod . add_method ( RDoc ::AnyMethod . new ( nil , "extmod_private_method" ) )
1540
+ extmod_private_method . visibility = :private
1541
+
1542
+ @klass . add_include ( RDoc ::Include . new ( "Incmod" , nil ) )
1543
+ @klass . add_extend ( RDoc ::Include . new ( "Extmod" , nil ) )
1544
+
1545
+ @klass . add_include ( RDoc ::Include . new ( "ExternalInclude" , nil ) )
1546
+ @klass . add_extend ( RDoc ::Include . new ( "ExternalExtend" , nil ) )
1547
+ end
1548
+
1549
+ def test_embed_mixin_when_false_does_not_embed_anything
1550
+ assert_false ( @klass . options . embed_mixins )
1551
+ @klass . complete ( :protected )
1552
+
1553
+ refute_includes ( @klass . constants . map ( &:name ) , "INCMOD_CONST" )
1554
+ refute_includes ( @klass . method_list . map ( &:name ) , "incmod_method" )
1555
+ refute_includes ( @klass . method_list . map ( &:name ) , "extmod_method" )
1556
+ refute_includes ( @klass . attributes . map ( &:name ) , "incmod_attr" )
1557
+ refute_includes ( @klass . attributes . map ( &:name ) , "extmod_attr" )
1558
+ end
1559
+
1560
+ def test_embed_mixin_when_true_embeds_methods_and_constants
1561
+ @klass . options . embed_mixins = true
1562
+ @klass . complete ( :protected )
1563
+
1564
+ # assert on presence and identity of methods and constants
1565
+ constant = @klass . constants . find { |c | c . name == "INCMOD_CONST" }
1566
+ assert ( constant , "constant from included mixin should be present" )
1567
+ assert_equal ( @incmod , constant . mixin_from )
1568
+
1569
+ instance_method = @klass . method_list . find { |m | m . name == "incmod_method" }
1570
+ assert ( instance_method , "instance method from included mixin should be present" )
1571
+ refute ( instance_method . singleton )
1572
+ assert_equal ( @incmod , instance_method . mixin_from )
1573
+
1574
+ instance_attr = @klass . attributes . find { |a | a . name == "incmod_attr" }
1575
+ assert ( instance_attr , "instance attr from included mixin should be present" )
1576
+ refute ( instance_attr . singleton )
1577
+ assert_equal ( @incmod , instance_attr . mixin_from )
1578
+
1579
+ refute ( @klass . method_list . find { |m | m . name == "incmod_private_method" } )
1580
+
1581
+ class_method = @klass . method_list . find { |m | m . name == "extmod_method" }
1582
+ assert ( class_method , "class method from extended mixin should be present" )
1583
+ assert ( class_method . singleton )
1584
+ assert_equal ( @extmod , class_method . mixin_from )
1585
+
1586
+ class_attr = @klass . attributes . find { |a | a . name == "extmod_attr" }
1587
+ assert ( class_attr , "class attr from extended mixin should be present" )
1588
+ assert ( class_attr . singleton )
1589
+ assert_equal ( @extmod , class_attr . mixin_from )
1590
+
1591
+ refute ( @klass . method_list . find { |m | m . name == "extmod_private_method" } )
1592
+
1593
+ # assert that sections are also imported
1594
+ constant_section = @klass . sections . find { |s | s . title == "Incmod const section" }
1595
+ assert ( constant_section , "constant from included mixin should have a section" )
1596
+ assert_equal ( constant_section , constant . section )
1597
+
1598
+ instance_method_section = @klass . sections . find { |s | s . title == "Incmod method section" }
1599
+ assert ( instance_method_section , "instance method from included mixin should have a section" )
1600
+ assert_equal ( instance_method_section , instance_method . section )
1601
+
1602
+ instance_attr_section = @klass . sections . find { |s | s . title == "Incmod attr section" }
1603
+ assert ( instance_attr_section , "instance attr from included mixin should have a section" )
1604
+ assert_equal ( instance_attr_section , instance_attr . section )
1605
+
1606
+ class_method_section = @klass . sections . find { |s | s . title == "Extmod method section" }
1607
+ assert ( class_method_section , "class method from extended mixin should have a section" )
1608
+ assert_equal ( class_method_section , class_method . section )
1609
+
1610
+ class_attr_section = @klass . sections . find { |s | s . title == "Extmod attr section" }
1611
+ assert ( class_attr_section , "class attr from extended mixin should have a section" )
1612
+ assert_equal ( class_attr_section , class_attr . section )
1613
+
1614
+ # and check that code objects without a section still have no section
1615
+ constant = @klass . constants . find { |c | c . name == "INCMOD_CONST_WITHOUT_A_SECTION" }
1616
+ assert_nil ( constant . section . title )
1617
+
1618
+ instance_method = @klass . method_list . find { |c | c . name == "incmod_method_without_a_section" }
1619
+ assert_nil ( instance_method . section . title )
1620
+
1621
+ instance_attr = @klass . attributes . find { |c | c . name == "incmod_attr_without_a_section" }
1622
+ assert_nil ( instance_attr . section . title )
1623
+
1624
+ class_method = @klass . method_list . find { |c | c . name == "extmod_method_without_a_section" }
1625
+ assert_nil ( class_method . section . title )
1626
+
1627
+ class_attr = @klass . attributes . find { |c | c . name == "extmod_attr_without_a_section" }
1628
+ assert_nil ( class_attr . section . title )
1629
+ end
1630
+ end
1503
1631
end
0 commit comments