Skip to content

Commit 32af13b

Browse files
Merge pull request #145 from teunbrand/main
Update tests for incoming ggplot2 version
2 parents 3d78902 + bc9b869 commit 32af13b

File tree

2 files changed

+45
-30
lines changed

2 files changed

+45
-30
lines changed

tests/testthat/test-ggplot2_scales_binned.R

+28-9
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,15 @@ test_that("scale_*_paletteer_binned correctly assigns colors", {
1818
ggplot2::geom_raster() +
1919
scale_fill_paletteer_binned("scico::berlin")
2020

21-
expect_equal(ggplot2::layer_data(p1)$colour, c("#65A6E1", "#183E4F", "#CC7D72"))
22-
expect_equal(ggplot2::layer_data(p2)$colour, c("#65A6E1", "#183E4F", "#CC7D72"))
23-
expect_equal(ggplot2::layer_data(p3)$fill, c("#65A6E1", "#183E4F", "#CC7D72"))
21+
colours <- if (utils::packageVersion("ggplot2") < "3.5.0") {
22+
c("#65A6E1", "#183E4F", "#CC7D72")
23+
} else {
24+
c("#519FD2", "#13313E", "#BB6C60")
25+
}
26+
27+
expect_equal(ggplot2::layer_data(p1)$colour, colours)
28+
expect_equal(ggplot2::layer_data(p2)$colour, colours)
29+
expect_equal(ggplot2::layer_data(p3)$fill, colours)
2430
})
2531

2632
test_that("scale_*_paletteer_binned correctly used direction", {
@@ -49,12 +55,25 @@ test_that("scale_*_paletteer_binned correctly used direction", {
4955
ggplot2::geom_raster() +
5056
scale_fill_paletteer_binned("scico::berlin", direction = -1)
5157

52-
expect_equal(ggplot2::layer_data(p1)$colour, c("#65A6E1", "#183E4F", "#CC7D72"))
53-
expect_equal(ggplot2::layer_data(p2)$colour, c("#65A6E1", "#183E4F", "#CC7D72"))
54-
expect_equal(ggplot2::layer_data(p3)$fill, c("#65A6E1", "#183E4F", "#CC7D72"))
55-
expect_equal(ggplot2::layer_data(p4)$colour, c("#CC7D72", "#4B1501", "#65A6E1"))
56-
expect_equal(ggplot2::layer_data(p5)$colour, c("#CC7D72", "#4B1501", "#65A6E1"))
57-
expect_equal(ggplot2::layer_data(p6)$fill, c("#CC7D72", "#4B1501", "#65A6E1"))
58+
colours <- if (utils::packageVersion("ggplot2") < "3.5.0") {
59+
c("#65A6E1", "#183E4F", "#CC7D72")
60+
} else {
61+
c("#519FD2", "#13313E", "#BB6C60")
62+
}
63+
64+
expect_equal(ggplot2::layer_data(p1)$colour, colours)
65+
expect_equal(ggplot2::layer_data(p2)$colour, colours)
66+
expect_equal(ggplot2::layer_data(p3)$fill, colours)
67+
68+
colours <- if (utils::packageVersion("ggplot2") < "3.5.0") {
69+
c("#CC7D72", "#4B1501", "#65A6E1")
70+
} else {
71+
c("#BB6C60", "#3F1200", "#519FD2")
72+
}
73+
74+
expect_equal(ggplot2::layer_data(p4)$colour, colours)
75+
expect_equal(ggplot2::layer_data(p5)$colour, colours)
76+
expect_equal(ggplot2::layer_data(p6)$fill, colours)
5877
})
5978

6079
test_that("scale_*_paletteer_binned works with quoted palettes", {

tests/testthat/test-ggplot2_scales_discrete.R

+17-21
Original file line numberDiff line numberDiff line change
@@ -78,31 +78,27 @@ test_that("scale_*_paletteer_d correctly used direction", {
7878

7979
test_that("scale_*_paletteer_d works with quoted palettes", {
8080
testthat::skip_if_not_installed("ggplot2")
81-
expect_equal(
82-
ggplot2::ggplot(df, ggplot2::aes(x, y, colour = color)) +
83-
ggplot2::geom_point() +
84-
scale_colour_paletteer_d(`"nord::lumina"`),
85-
ggplot2::ggplot(df, ggplot2::aes(x, y, colour = color)) +
86-
ggplot2::geom_point() +
87-
scale_colour_paletteer_d("nord::lumina")
81+
82+
expect_equal_scales <- function(x, y, ...) {
83+
x <- as.list(x)
84+
y <- as.list(y)
85+
x$call <- y$call <- NULL # the calls are different between quoted/unquoted
86+
expect_equal(x, y, ...)
87+
}
88+
89+
expect_equal_scales(
90+
scale_colour_paletteer_d(`"nord::lumina"`),
91+
scale_colour_paletteer_d("nord::lumina")
8892
)
8993

90-
expect_equal(
91-
ggplot2::ggplot(df, ggplot2::aes(x, y, color = color)) +
92-
ggplot2::geom_point() +
93-
scale_color_paletteer_d(palette = `"nord::lumina"`),
94-
ggplot2::ggplot(df, ggplot2::aes(x, y, color = color)) +
95-
ggplot2::geom_point() +
96-
scale_color_paletteer_d("nord::lumina")
94+
expect_equal_scales(
95+
scale_color_paletteer_d(palette = `"nord::lumina"`),
96+
scale_color_paletteer_d("nord::lumina")
9797
)
9898

99-
expect_equal(
100-
ggplot2::ggplot(df, ggplot2::aes(x, y, fill = color)) +
101-
ggplot2::geom_raster() +
102-
scale_fill_paletteer_d(`"nord::lumina"`),
103-
ggplot2::ggplot(df, ggplot2::aes(x, y, fill = color)) +
104-
ggplot2::geom_raster() +
105-
scale_fill_paletteer_d("nord::lumina")
99+
expect_equal_scales(
100+
scale_fill_paletteer_d(`"nord::lumina"`),
101+
scale_fill_paletteer_d("nord::lumina")
106102
)
107103
})
108104

0 commit comments

Comments
 (0)