Skip to content

Commit fe00b5c

Browse files
authored
update sf label tests (#3378, fixes #3365)
1 parent e2bdf85 commit fe00b5c

File tree

1 file changed

+33
-17
lines changed

1 file changed

+33
-17
lines changed

tests/testthat/test-coord_sf.R

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ test_that("graticule lines can be removed via theme", {
3232
expect_doppelganger("no panel grid", plot)
3333
})
3434

35-
test_that("axis labels can be set manually", {
35+
test_that("axis labels are correct for manual breaks", {
3636
skip_if_not_installed("sf")
3737

3838
plot <- ggplot(sf::st_polygon(list(matrix(1e3*c(1, 2, 3, 1, 1, 3, 2, 1), ncol = 2)))) +
@@ -53,6 +53,13 @@ test_that("axis labels can be set manually", {
5353
graticule[graticule$type == "N", ]$degree_label,
5454
c("1000", "1500", "2000")
5555
)
56+
})
57+
58+
test_that("axis labels can be set manually", {
59+
skip_if_not_installed("sf")
60+
61+
plot <- ggplot(sf::st_polygon(list(matrix(1e3*c(1, 2, 3, 1, 1, 3, 2, 1), ncol = 2)))) +
62+
geom_sf()
5663

5764
# character labels
5865
b <- ggplot_build(
@@ -75,9 +82,14 @@ test_that("axis labels can be set manually", {
7582
graticule[graticule$type == "N", ]$degree_label,
7683
c("D", "E", "F")
7784
)
85+
})
86+
87+
test_that("factors are treated like character labels and are not parsed", {
88+
skip_if_not_installed("sf")
89+
90+
plot <- ggplot(sf::st_polygon(list(matrix(1e3*c(1, 2, 3, 1, 1, 3, 2, 1), ncol = 2)))) +
91+
geom_sf()
7892

79-
# factors are treated like character labels
80-
# and are not parsed
8193
b <- ggplot_build(
8294
plot +
8395
scale_x_continuous(
@@ -98,9 +110,14 @@ test_that("axis labels can be set manually", {
98110
graticule[graticule$type == "N", ]$degree_label,
99111
c("1 * degree * N", "1.5 * degree * N", "2 * degree * N")
100112
)
113+
})
101114

115+
test_that("expressions can be mixed with character labels", {
116+
skip_if_not_installed("sf")
117+
118+
plot <- ggplot(sf::st_polygon(list(matrix(1e3*c(1, 2, 3, 1, 1, 3, 2, 1), ncol = 2)))) +
119+
geom_sf()
102120

103-
# expressions mixed with character labels
104121
b <- ggplot_build(
105122
plot +
106123
scale_x_continuous(
@@ -147,33 +164,32 @@ test_that("axis labels can be set manually", {
147164
graticule[graticule$type == "E", ]$degree_label,
148165
parsed
149166
)
167+
})
168+
169+
test_that("degree labels are automatically parsed", {
170+
skip_if_not_installed("sf")
150171

151-
# autoparsing of degree labels
152172
data <- sf::st_sfc(
153173
sf::st_polygon(list(matrix(1e1*c(1, 2, 3, 1, 1, 3, 2, 1), ncol = 2))),
154174
crs = 4326 # basic long-lat crs
155175
)
156-
157176
plot <- ggplot(data) + geom_sf()
158-
159177
b <- ggplot_build(
160178
plot +
161179
scale_x_continuous(breaks = c(10, 20, 30)) +
162180
scale_y_continuous(breaks = c(10, 15, 20))
163181
)
182+
164183
graticule <- b$layout$panel_params[[1]]$graticule
165-
parsed <- vector("list", 3)
166-
parsed[1:3] <- parse(text = c("10*degree*E", "20*degree*E", "30*degree*E"))
167-
expect_identical(
168-
graticule[graticule$type == "E", ]$degree_label,
169-
parsed
184+
expect_setequal(
185+
graticule[graticule$type == "N", ]$degree,
186+
c(10, 15, 20)
170187
)
171-
parsed[1:3] <- parse(text = c("10*degree*N", "15*degree*N", "20*degree*N"))
172-
expect_identical(
173-
graticule[graticule$type == "N", ]$degree_label,
174-
parsed
188+
expect_setequal(
189+
graticule[graticule$type == "E", ]$degree,
190+
c(10, 20, 30)
175191
)
176-
192+
expect_true(all(vapply(graticule$degree_label, is.language, logical(1))))
177193
})
178194

179195
test_that("Inf is squished to range", {

0 commit comments

Comments
 (0)