Skip to content

Commit

Permalink
Test for absence/presence of guide differently (#89)
Browse files Browse the repository at this point in the history
* test for absence/presence of guide differently

* narrate the conditional logic
  • Loading branch information
teunbrand authored Jan 19, 2024
1 parent 54c8670 commit 648001c
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions tests/testthat/test_scale_cyclical.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ test_that("basic tests", {
expect_equal(d$colour, rep(c("#F00000", "#0000F0"), 13))

# make sure there is no legend being generated
expect_equal("guide-box" %in% ggplotGrob(p)$layout$name, FALSE)
# in ggplot2 >= 3.5.0 legend structure in gtable changed
if ("get_guide_data" %in% getNamespaceExports("ggplot2")) {
expect_null(get_guide_data(p, "colour"))
} else {
expect_equal("guide-box" %in% ggplotGrob(p)$layout$name, FALSE)
}

# once again, different aesthetic, different cyclical pattern, now with legend
p <- ggplot(df, aes(x, y, label=letters, color=factor(x))) + geom_text() +
Expand All @@ -23,7 +28,12 @@ test_that("basic tests", {
expect_equal(d$colour[order(d$x)], rep(c("#F00000", "#0000F0", "#F0F000"), 9)[1:26])

# make sure there is a legend
expect_equal("guide-box" %in% ggplotGrob(p)$layout$name, TRUE)
# in ggplot2 >= 3.5.0 legend structure in gtable changed
if ("get_guide_data" %in% getNamespaceExports("ggplot2")) {
expect_s3_class(get_guide_data(p, "colour"), "data.frame")
} else {
expect_equal("guide-box" %in% ggplotGrob(p)$layout$name, TRUE)
}

# test that breaks must match labels
expect_error(
Expand Down

0 comments on commit 648001c

Please sign in to comment.