Skip to content

Commit 238553f

Browse files
committed
add tests
1 parent 654e247 commit 238553f

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

tests/testthat/test-coord-polar.R

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,22 @@ test_that("bounding box calculations are sensible", {
155155
)
156156
})
157157

158+
test_that("when both x and y are AsIs, they are not transformed", {
159+
160+
p <- ggplot() +
161+
annotate("text", x = I(0.75), y = I(0.25), label = "foo") +
162+
scale_x_continuous(limits = c(0, 10)) +
163+
scale_y_continuous(limits = c(0, 10))
164+
165+
grob <- get_layer_grob(p + coord_polar())[[1]]
166+
location <- c(as.numeric(grob$x), as.numeric(grob$y))
167+
expect_equal(location, c(0.75, 0.25))
168+
169+
grob <- get_layer_grob(p + coord_radial())[[1]]
170+
location <- c(as.numeric(grob$x), as.numeric(grob$y))
171+
expect_equal(location, c(0.75, 0.25))
172+
173+
})
158174

159175
# Visual tests ------------------------------------------------------------
160176

tests/testthat/test-coord_sf.R

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,22 @@ test_that("sf_transform_xy() works", {
314314

315315
})
316316

317+
test_that("when both x and y are AsIs, they are not transformed", {
318+
319+
skip_if_not_installed("sf")
320+
321+
p <- ggplot() +
322+
annotate("text", x = I(0.75), y = I(0.25), label = "foo") +
323+
scale_x_continuous(limits = c(-180, 180)) +
324+
scale_y_continuous(limits = c(-80, 80)) +
325+
coord_sf(default_crs = 4326, crs = 3857)
326+
327+
grob <- get_layer_grob(p)[[1]]
328+
location <- c(as.numeric(grob$x), as.numeric(grob$y))
329+
expect_equal(location, c(0.75, 0.25))
330+
331+
})
332+
317333
test_that("coord_sf() can use function breaks and n.breaks", {
318334

319335
polygon <- sf::st_sfc(

0 commit comments

Comments
 (0)