Skip to content

Commit 34dee47

Browse files
committed
add more tests to confirm that automatic choice can be overridden manually.
1 parent 60ed8db commit 34dee47

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

tests/testthat/test-geom-sf.R

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,30 @@ test_that("geom_sf() determines the legend type automatically", {
2626
geometry = sf::st_sfc(sf::st_multipolygon(list(list(p1,p2), list(p3,p4), list(p5)))),
2727
v = "a")
2828

29-
fun_geom_sf <- function(sf) {
30-
p <- ggplot() + geom_sf(aes(colour = v), data = sf, show.legend = TRUE)
29+
fun_geom_sf <- function(sf, show.legend) {
30+
p <- ggplot() + geom_sf(aes(colour = v), data = sf, show.legend = show.legend)
3131
ggplot_build(p)
3232
}
3333

34-
expect_identical(fun_geom_sf(mp)$plot$layers[[1]]$show.legend, TRUE)
35-
expect_identical(fun_geom_sf(mp)$plot$layers[[1]]$geom_params$legend, "point")
34+
# test the automatic choice
35+
expect_identical(fun_geom_sf(mp, TRUE)$plot$layers[[1]]$show.legend, TRUE)
36+
expect_identical(fun_geom_sf(mp, TRUE)$plot$layers[[1]]$geom_params$legend, "point")
3637

37-
expect_identical(fun_geom_sf(mls)$plot$layers[[1]]$show.legend, TRUE)
38-
expect_identical(fun_geom_sf(mls)$plot$layers[[1]]$geom_params$legend, "line")
38+
expect_identical(fun_geom_sf(mls, TRUE)$plot$layers[[1]]$show.legend, TRUE)
39+
expect_identical(fun_geom_sf(mls, TRUE)$plot$layers[[1]]$geom_params$legend, "line")
3940

40-
expect_identical(fun_geom_sf(mpol)$plot$layers[[1]]$show.legend, TRUE)
41-
expect_identical(fun_geom_sf(mpol)$plot$layers[[1]]$geom_params$legend, "polygon")
41+
expect_identical(fun_geom_sf(mpol, TRUE)$plot$layers[[1]]$show.legend, TRUE)
42+
expect_identical(fun_geom_sf(mpol, TRUE)$plot$layers[[1]]$geom_params$legend, "polygon")
43+
44+
# test that automatic choice can be overridden manually
45+
expect_identical(fun_geom_sf(mp, "point")$plot$layers[[1]]$show.legend, TRUE)
46+
expect_identical(fun_geom_sf(mp, "point")$plot$layers[[1]]$geom_params$legend, "point")
47+
48+
expect_identical(fun_geom_sf(mls, "point")$plot$layers[[1]]$show.legend, TRUE)
49+
expect_identical(fun_geom_sf(mls, "point")$plot$layers[[1]]$geom_params$legend, "point")
50+
51+
expect_identical(fun_geom_sf(mpol, "point")$plot$layers[[1]]$show.legend, TRUE)
52+
expect_identical(fun_geom_sf(mpol, "point")$plot$layers[[1]]$geom_params$legend, "point")
4253
})
4354

4455
test_that("geom_sf() removes rows containing missing aes", {

0 commit comments

Comments
 (0)