Skip to content

Commit

Permalink
Merge pull request #145 from teunbrand/main
Browse files Browse the repository at this point in the history
Update tests for incoming ggplot2 version
  • Loading branch information
EmilHvitfeldt authored Jan 18, 2024
2 parents 3d78902 + bc9b869 commit 32af13b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 30 deletions.
37 changes: 28 additions & 9 deletions tests/testthat/test-ggplot2_scales_binned.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@ test_that("scale_*_paletteer_binned correctly assigns colors", {
ggplot2::geom_raster() +
scale_fill_paletteer_binned("scico::berlin")

expect_equal(ggplot2::layer_data(p1)$colour, c("#65A6E1", "#183E4F", "#CC7D72"))
expect_equal(ggplot2::layer_data(p2)$colour, c("#65A6E1", "#183E4F", "#CC7D72"))
expect_equal(ggplot2::layer_data(p3)$fill, c("#65A6E1", "#183E4F", "#CC7D72"))
colours <- if (utils::packageVersion("ggplot2") < "3.5.0") {
c("#65A6E1", "#183E4F", "#CC7D72")
} else {
c("#519FD2", "#13313E", "#BB6C60")
}

expect_equal(ggplot2::layer_data(p1)$colour, colours)
expect_equal(ggplot2::layer_data(p2)$colour, colours)
expect_equal(ggplot2::layer_data(p3)$fill, colours)
})

test_that("scale_*_paletteer_binned correctly used direction", {
Expand Down Expand Up @@ -49,12 +55,25 @@ test_that("scale_*_paletteer_binned correctly used direction", {
ggplot2::geom_raster() +
scale_fill_paletteer_binned("scico::berlin", direction = -1)

expect_equal(ggplot2::layer_data(p1)$colour, c("#65A6E1", "#183E4F", "#CC7D72"))
expect_equal(ggplot2::layer_data(p2)$colour, c("#65A6E1", "#183E4F", "#CC7D72"))
expect_equal(ggplot2::layer_data(p3)$fill, c("#65A6E1", "#183E4F", "#CC7D72"))
expect_equal(ggplot2::layer_data(p4)$colour, c("#CC7D72", "#4B1501", "#65A6E1"))
expect_equal(ggplot2::layer_data(p5)$colour, c("#CC7D72", "#4B1501", "#65A6E1"))
expect_equal(ggplot2::layer_data(p6)$fill, c("#CC7D72", "#4B1501", "#65A6E1"))
colours <- if (utils::packageVersion("ggplot2") < "3.5.0") {
c("#65A6E1", "#183E4F", "#CC7D72")
} else {
c("#519FD2", "#13313E", "#BB6C60")
}

expect_equal(ggplot2::layer_data(p1)$colour, colours)
expect_equal(ggplot2::layer_data(p2)$colour, colours)
expect_equal(ggplot2::layer_data(p3)$fill, colours)

colours <- if (utils::packageVersion("ggplot2") < "3.5.0") {
c("#CC7D72", "#4B1501", "#65A6E1")
} else {
c("#BB6C60", "#3F1200", "#519FD2")
}

expect_equal(ggplot2::layer_data(p4)$colour, colours)
expect_equal(ggplot2::layer_data(p5)$colour, colours)
expect_equal(ggplot2::layer_data(p6)$fill, colours)
})

test_that("scale_*_paletteer_binned works with quoted palettes", {
Expand Down
38 changes: 17 additions & 21 deletions tests/testthat/test-ggplot2_scales_discrete.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,31 +78,27 @@ test_that("scale_*_paletteer_d correctly used direction", {

test_that("scale_*_paletteer_d works with quoted palettes", {
testthat::skip_if_not_installed("ggplot2")
expect_equal(
ggplot2::ggplot(df, ggplot2::aes(x, y, colour = color)) +
ggplot2::geom_point() +
scale_colour_paletteer_d(`"nord::lumina"`),
ggplot2::ggplot(df, ggplot2::aes(x, y, colour = color)) +
ggplot2::geom_point() +
scale_colour_paletteer_d("nord::lumina")

expect_equal_scales <- function(x, y, ...) {
x <- as.list(x)
y <- as.list(y)
x$call <- y$call <- NULL # the calls are different between quoted/unquoted
expect_equal(x, y, ...)
}

expect_equal_scales(
scale_colour_paletteer_d(`"nord::lumina"`),
scale_colour_paletteer_d("nord::lumina")
)

expect_equal(
ggplot2::ggplot(df, ggplot2::aes(x, y, color = color)) +
ggplot2::geom_point() +
scale_color_paletteer_d(palette = `"nord::lumina"`),
ggplot2::ggplot(df, ggplot2::aes(x, y, color = color)) +
ggplot2::geom_point() +
scale_color_paletteer_d("nord::lumina")
expect_equal_scales(
scale_color_paletteer_d(palette = `"nord::lumina"`),
scale_color_paletteer_d("nord::lumina")
)

expect_equal(
ggplot2::ggplot(df, ggplot2::aes(x, y, fill = color)) +
ggplot2::geom_raster() +
scale_fill_paletteer_d(`"nord::lumina"`),
ggplot2::ggplot(df, ggplot2::aes(x, y, fill = color)) +
ggplot2::geom_raster() +
scale_fill_paletteer_d("nord::lumina")
expect_equal_scales(
scale_fill_paletteer_d(`"nord::lumina"`),
scale_fill_paletteer_d("nord::lumina")
)
})

Expand Down

0 comments on commit 32af13b

Please sign in to comment.