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