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