Skip to content

Commit f3a4f5b

Browse files
committed
add test
1 parent cd30442 commit f3a4f5b

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tests/testthat/test-labels.R

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,29 @@ test_that("position axis label hierarchy works as intended", {
199199
)
200200
})
201201

202+
test_that("labels can be derived using functions", {
203+
204+
p <- ggplot(mtcars, aes(disp, mpg, colour = drat, shape = factor(cyl))) +
205+
geom_point() +
206+
labs(
207+
y = to_upper_ascii,
208+
shape = function(x) gsub("factor", "foo", x)
209+
) +
210+
scale_shape_discrete(
211+
name = to_upper_ascii,
212+
guide = guide_legend(title = function(x) paste0(x, "!!!"))
213+
) +
214+
scale_x_continuous(name = to_upper_ascii) +
215+
guides(colour = guide_colourbar(title = to_upper_ascii))
216+
217+
labs <- get_labs(p)
218+
expect_equal(labs$shape, "FOO(CYL)!!!")
219+
expect_equal(labs$colour, "DRAT")
220+
expect_equal(labs$x, "DISP")
221+
expect_equal(labs$y, "MPG")
222+
223+
})
224+
202225
test_that("moving guide positions lets titles follow", {
203226
df <- data_frame(foo = c(1e1, 1e5), bar = c(0, 100))
204227

0 commit comments

Comments
 (0)