Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
teunbrand committed Sep 17, 2024
1 parent e5664f6 commit 8740d3a
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/testthat/test-geom-hline-vline-abline.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,25 @@ test_that("curved lines in map projections", {
)
})

test_that("geom_abline is clipped to x/y ranges", {

df <- data.frame(slope = c(-0.2, -1, -5, 5, 1, 0.2))

p <- ggplot(df) +
geom_abline(aes(slope = slope, intercept = 0)) +
scale_x_continuous(limits = c(-1, 1), expand = FALSE) +
scale_y_continuous(limits = c(-1, 1), expand = FALSE) +
coord_cartesian(clip = "off")

data <- layer_grob(p)[[1]]

x <- c(as.numeric(data$x0), as.numeric(data$x1))
expect_true(all(x >= 0 & x <= 1))

y <- c(as.numeric(data$y0), as.numeric(data$y1))
expect_true(all(y >= 0 & y <= 1))
})

# Warning tests ------------------------------------------------------------

test_that("warnings are thrown when parameters cause mapping and data to be ignored", {
Expand Down

0 comments on commit 8740d3a

Please sign in to comment.