Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tests for incoming ggplot2 version #145

Merged
merged 2 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading