@@ -19,6 +19,43 @@ test_that("type argument is checked for proper input", {
19
19
)
20
20
})
21
21
22
+ test_that(" palette with accepts_native_output returns native colours" , {
23
+ sc <- scale_fill_continuous()
24
+ sc $ palette <- structure(
25
+ function (x , color_fmt = " character" ) {
26
+ if (color_fmt == " character" ) {
27
+ rep(" red" , length(x ))
28
+ } else {
29
+ rep(- 16776961L , length(x ))
30
+ }
31
+ },
32
+ accepts_native_output = TRUE
33
+ )
34
+ x <- 0.5
35
+ nat <- sc $ map(x , limits = c(0 , 1 ), scale_params = list (color_fmt = " native" ))
36
+ expect_equal(nat , - 16776961L )
37
+ chr <- sc $ map(x , limits = c(0 , 1 ), scale_params = list (color_fmt = " character" ))
38
+ expect_equal(chr , " red" )
39
+ chr2 <- sc $ map(x , limits = c(0 , 1 ))
40
+ expect_equal(chr , chr2 )
41
+ })
42
+
43
+ test_that(" palette without accepts_native_output returns native colours as well" , {
44
+ sc <- scale_fill_continuous()
45
+ sc $ palette <- function (x ) {
46
+ rep(" red" , length(x ))
47
+ }
48
+ x <- 0.5
49
+ nat <- sc $ map(x , limits = c(0 , 1 ), scale_params = list (color_fmt = " native" ))
50
+ expect_equal(nat , - 16776961L )
51
+ chr <- sc $ map(x , limits = c(0 , 1 ), scale_params = list (color_fmt = " character" ))
52
+ expect_equal(chr , " red" )
53
+ chr2 <- sc $ map(x , limits = c(0 , 1 ))
54
+ expect_equal(chr , chr2 )
55
+ })
56
+
57
+
58
+
22
59
test_that(" palette with may_return_NA=FALSE works as expected" , {
23
60
sc <- scale_fill_continuous()
24
61
# A palette that may return NAs, will have NAs replaced by the scale's na.value
0 commit comments