@@ -1500,4 +1500,140 @@ 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
+ incmod_private_attr = @incmod . add_attribute ( RDoc ::Attr . new ( nil , "incmod_private_attr" , "RW" , "" ) )
1529
+ incmod_private_attr . visibility = :private
1530
+
1531
+ extmod_tl = @store . add_file ( "extmod.rb" )
1532
+ @extmod = extmod_tl . add_module ( RDoc ::NormalModule , "Extmod" )
1533
+
1534
+ extmod_method = @extmod . add_method ( RDoc ::AnyMethod . new ( nil , "extmod_method_without_a_section" ) )
1535
+ extmod_method = @extmod . add_method ( RDoc ::AnyMethod . new ( nil , "extmod_method" ) )
1536
+ extmod_method . section = @extmod . add_section ( "Extmod method section" )
1537
+
1538
+ extmod_attr = @extmod . add_attribute ( RDoc ::Attr . new ( nil , "extmod_attr_without_a_section" , "RW" , "" , true ) )
1539
+ extmod_attr = @extmod . add_attribute ( RDoc ::Attr . new ( nil , "extmod_attr" , "RW" , "" , true ) )
1540
+ extmod_attr . section = @extmod . add_section ( "Extmod attr section" )
1541
+
1542
+ extmod_private_method = @extmod . add_method ( RDoc ::AnyMethod . new ( nil , "extmod_private_method" ) )
1543
+ extmod_private_method . visibility = :private
1544
+
1545
+ extmod_private_attr = @extmod . add_attribute ( RDoc ::Attr . new ( nil , "extmod_private_attr" , "RW" , "" , true ) )
1546
+ extmod_private_attr . visibility = :private
1547
+
1548
+ @klass . add_include ( RDoc ::Include . new ( "Incmod" , nil ) )
1549
+ @klass . add_extend ( RDoc ::Include . new ( "Extmod" , nil ) )
1550
+
1551
+ @klass . add_include ( RDoc ::Include . new ( "ExternalInclude" , nil ) )
1552
+ @klass . add_extend ( RDoc ::Include . new ( "ExternalExtend" , nil ) )
1553
+ end
1554
+
1555
+ def test_embed_mixin_when_false_does_not_embed_anything
1556
+ assert_false ( @klass . options . embed_mixins )
1557
+ @klass . complete ( :protected )
1558
+
1559
+ refute_includes ( @klass . constants . map ( &:name ) , "INCMOD_CONST" )
1560
+ refute_includes ( @klass . method_list . map ( &:name ) , "incmod_method" )
1561
+ refute_includes ( @klass . method_list . map ( &:name ) , "extmod_method" )
1562
+ refute_includes ( @klass . attributes . map ( &:name ) , "incmod_attr" )
1563
+ refute_includes ( @klass . attributes . map ( &:name ) , "extmod_attr" )
1564
+ end
1565
+
1566
+ def test_embed_mixin_when_true_embeds_methods_and_constants
1567
+ @klass . options . embed_mixins = true
1568
+ @klass . complete ( :protected )
1569
+
1570
+ # assert on presence and identity of methods and constants
1571
+ constant = @klass . constants . find { |c | c . name == "INCMOD_CONST" }
1572
+ assert ( constant , "constant from included mixin should be present" )
1573
+ assert_equal ( @incmod , constant . mixin_from )
1574
+
1575
+ instance_method = @klass . method_list . find { |m | m . name == "incmod_method" }
1576
+ assert ( instance_method , "instance method from included mixin should be present" )
1577
+ refute ( instance_method . singleton )
1578
+ assert_equal ( @incmod , instance_method . mixin_from )
1579
+
1580
+ instance_attr = @klass . attributes . find { |a | a . name == "incmod_attr" }
1581
+ assert ( instance_attr , "instance attr from included mixin should be present" )
1582
+ refute ( instance_attr . singleton )
1583
+ assert_equal ( @incmod , instance_attr . mixin_from )
1584
+
1585
+ refute ( @klass . method_list . find { |m | m . name == "incmod_private_method" } )
1586
+ refute ( @klass . attributes . find { |m | m . name == "incmod_private_attr" } )
1587
+
1588
+ class_method = @klass . method_list . find { |m | m . name == "extmod_method" }
1589
+ assert ( class_method , "class method from extended mixin should be present" )
1590
+ assert ( class_method . singleton )
1591
+ assert_equal ( @extmod , class_method . mixin_from )
1592
+
1593
+ class_attr = @klass . attributes . find { |a | a . name == "extmod_attr" }
1594
+ assert ( class_attr , "class attr from extended mixin should be present" )
1595
+ assert ( class_attr . singleton )
1596
+ assert_equal ( @extmod , class_attr . mixin_from )
1597
+
1598
+ refute ( @klass . method_list . find { |m | m . name == "extmod_private_method" } )
1599
+ refute ( @klass . attributes . find { |m | m . name == "extmod_private_attr" } )
1600
+
1601
+ # assert that sections are also imported
1602
+ constant_section = @klass . sections . find { |s | s . title == "Incmod const section" }
1603
+ assert ( constant_section , "constant from included mixin should have a section" )
1604
+ assert_equal ( constant_section , constant . section )
1605
+
1606
+ instance_method_section = @klass . sections . find { |s | s . title == "Incmod method section" }
1607
+ assert ( instance_method_section , "instance method from included mixin should have a section" )
1608
+ assert_equal ( instance_method_section , instance_method . section )
1609
+
1610
+ instance_attr_section = @klass . sections . find { |s | s . title == "Incmod attr section" }
1611
+ assert ( instance_attr_section , "instance attr from included mixin should have a section" )
1612
+ assert_equal ( instance_attr_section , instance_attr . section )
1613
+
1614
+ class_method_section = @klass . sections . find { |s | s . title == "Extmod method section" }
1615
+ assert ( class_method_section , "class method from extended mixin should have a section" )
1616
+ assert_equal ( class_method_section , class_method . section )
1617
+
1618
+ class_attr_section = @klass . sections . find { |s | s . title == "Extmod attr section" }
1619
+ assert ( class_attr_section , "class attr from extended mixin should have a section" )
1620
+ assert_equal ( class_attr_section , class_attr . section )
1621
+
1622
+ # and check that code objects without a section still have no section
1623
+ constant = @klass . constants . find { |c | c . name == "INCMOD_CONST_WITHOUT_A_SECTION" }
1624
+ assert_nil ( constant . section . title )
1625
+
1626
+ instance_method = @klass . method_list . find { |c | c . name == "incmod_method_without_a_section" }
1627
+ assert_nil ( instance_method . section . title )
1628
+
1629
+ instance_attr = @klass . attributes . find { |c | c . name == "incmod_attr_without_a_section" }
1630
+ assert_nil ( instance_attr . section . title )
1631
+
1632
+ class_method = @klass . method_list . find { |c | c . name == "extmod_method_without_a_section" }
1633
+ assert_nil ( class_method . section . title )
1634
+
1635
+ class_attr = @klass . attributes . find { |c | c . name == "extmod_attr_without_a_section" }
1636
+ assert_nil ( class_attr . section . title )
1637
+ end
1638
+ end
1503
1639
end
0 commit comments