Skip to content

Commit 8740d3a

Browse files
committed
add test
1 parent e5664f6 commit 8740d3a

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

tests/testthat/test-geom-hline-vline-abline.R

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,25 @@ test_that("curved lines in map projections", {
4343
)
4444
})
4545

46+
test_that("geom_abline is clipped to x/y ranges", {
47+
48+
df <- data.frame(slope = c(-0.2, -1, -5, 5, 1, 0.2))
49+
50+
p <- ggplot(df) +
51+
geom_abline(aes(slope = slope, intercept = 0)) +
52+
scale_x_continuous(limits = c(-1, 1), expand = FALSE) +
53+
scale_y_continuous(limits = c(-1, 1), expand = FALSE) +
54+
coord_cartesian(clip = "off")
55+
56+
data <- layer_grob(p)[[1]]
57+
58+
x <- c(as.numeric(data$x0), as.numeric(data$x1))
59+
expect_true(all(x >= 0 & x <= 1))
60+
61+
y <- c(as.numeric(data$y0), as.numeric(data$y1))
62+
expect_true(all(y >= 0 & y <= 1))
63+
})
64+
4665
# Warning tests ------------------------------------------------------------
4766

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

0 commit comments

Comments
 (0)