@@ -509,6 +509,50 @@ test_that("Theme validation behaves as expected", {
509
509
expect_snapshot_error(validate_element(" A" , " aspect.ratio" , tree ))
510
510
})
511
511
512
+ test_that(" Element subclasses are inherited" , {
513
+
514
+ # `rich` is subclass of `poor`
515
+ poor <- element_line(colour = " red" , linetype = 3 )
516
+ rich <- element_line(linetype = 2 , linewidth = 2 )
517
+ class(rich ) <- c(" element_rich" , class(rich ))
518
+
519
+ # `poor` should acquire `rich`
520
+ test <- combine_elements(poor , rich )
521
+ expect_s3_class(test , " element_rich" )
522
+ expect_equal(
523
+ test [c(" colour" , " linetype" , " linewidth" )],
524
+ list (colour = " red" , linetype = 3 , linewidth = 2 )
525
+ )
526
+
527
+ # `rich` should stay `rich`
528
+ test <- combine_elements(rich , poor )
529
+ expect_s3_class(test , " element_rich" )
530
+ expect_equal(
531
+ test [c(" colour" , " linetype" , " linewidth" )],
532
+ list (colour = " red" , linetype = 2 , linewidth = 2 )
533
+ )
534
+
535
+ # `sibling` is not strict subclass of `rich`
536
+ sibling <- poor
537
+ class(sibling ) <- c(" element_sibling" , class(sibling ))
538
+
539
+ # `sibling` should stay `sibling`
540
+ test <- combine_elements(sibling , rich )
541
+ expect_s3_class(test , " element_sibling" )
542
+ expect_equal(
543
+ test [c(" colour" , " linetype" , " linewidth" )],
544
+ list (colour = " red" , linetype = 3 , linewidth = 2 )
545
+ )
546
+
547
+ # `rich` should stay `rich`
548
+ test <- combine_elements(rich , sibling )
549
+ expect_s3_class(test , " element_rich" )
550
+ expect_equal(
551
+ test [c(" colour" , " linetype" , " linewidth" )],
552
+ list (colour = " red" , linetype = 2 , linewidth = 2 )
553
+ )
554
+ })
555
+
512
556
test_that(" Minor tick length supports biparental inheritance" , {
513
557
my_theme <- theme_gray() + theme(
514
558
axis.ticks.length = unit(1 , " cm" ),
0 commit comments