@@ -18,11 +18,38 @@ test_that("type argument is checked for proper input", {
18
18
scale_colour_continuous(type = " abc" )
19
19
)
20
20
})
21
-
22
21
test_that(" scale_params mapping_method supports binned" , {
23
22
sc <- scale_fill_continuous()
24
23
x <- seq(0 , 1 , length.out = 10 )
25
24
only_two <- sc $ map(x , limits = c(0 , 1 ), scale_params = list (mapping_method = " binned" , mapping_method_bins = 2 ))
26
25
expect_equal(length(unique(only_two )), 2L )
27
26
})
28
27
28
+ test_that(" palette with may_return_NA=FALSE works as expected" , {
29
+ sc <- scale_fill_continuous()
30
+ # A palette that may return NAs, will have NAs replaced by the scale's na.value
31
+ # by the scale:
32
+ sc $ palette <- structure(
33
+ function (x ) {
34
+ rep(NA_character_ , length(x ))
35
+ },
36
+ may_return_NA = TRUE
37
+ )
38
+ sc $ na.value <- " red"
39
+ nat <- sc $ map(0.5 , limits = c(0 , 1 ))
40
+ expect_equal(nat , " red" )
41
+
42
+ # This palette is lying, because it returns NA even though it says it can't.
43
+ # The scale will not replace the NA values, leading to further errors.
44
+ # You should not do this in production, but it helps to test:
45
+ sc <- scale_fill_continuous()
46
+ sc $ palette <- structure(
47
+ function (x ) {
48
+ rep(NA_character_ , length(x ))
49
+ },
50
+ may_return_NA = FALSE
51
+ )
52
+ sc $ na.value <- " red"
53
+ nat <- sc $ map(0.5 , limits = c(0 , 1 ))
54
+ expect_equal(nat , NA_character_ )
55
+ })
0 commit comments