@@ -80,3 +80,36 @@ test_that("can change ordered status of output", {
80
80
expect_equal(is.ordered(lvls_reorder(f2 , 1 : 3 , ordered = FALSE )), FALSE )
81
81
expect_equal(is.ordered(lvls_reorder(f2 , 1 : 3 , ordered = TRUE )), TRUE )
82
82
})
83
+
84
+ # refactor ------------------------------------------------------------
85
+
86
+ test_that(" preserves attributes" , {
87
+ f1 <- factor (letters [1 : 3 ])
88
+ attr(f1 , " foo" ) <- " bar"
89
+
90
+ f2 <- refactor(f1 , letters [1 : 4 ])
91
+
92
+ expect_equal(attr(f1 , " foo" ), attr(f2 , " foo" ))
93
+ })
94
+
95
+ test_that(" preserves s3 subclasses" , {
96
+ f1 <- factor (letters [1 : 3 ])
97
+ class(f1 ) <- c(" foo" , class(f1 ))
98
+
99
+ f2 <- refactor(f1 , letters [1 : 4 ])
100
+
101
+ expect_equal(class(f1 ), class(f2 ))
102
+ })
103
+
104
+ test_that(" preserves s3 subclasses when toggling ordered" , {
105
+ f1 <- factor (letters [1 : 3 ])
106
+ class(f1 ) <- c(" foo" , class(f1 ))
107
+
108
+ f2 <- refactor(f1 , letters [1 : 4 ], ordered = TRUE )
109
+
110
+ expect_equal(class(f2 ), c(" foo" , " ordered" , " factor" ))
111
+
112
+ f3 <- refactor(f2 , letters [1 : 3 ], ordered = FALSE )
113
+
114
+ expect_equal(class(f3 ), c(" foo" , " factor" ))
115
+ })
0 commit comments