Skip to content

Commit 6da58b7

Browse files
committed
add test
1 parent 08f9d8e commit 6da58b7

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tests/testthat/test-labels.R

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,31 @@ test_that("moving guide positions lets titles follow", {
267267
)
268268
})
269269

270+
test_that("label dictionaries work", {
271+
272+
p <- ggplot(mtcars, aes(disp, mpg, shape = factor(cyl), size = drat)) +
273+
geom_point() +
274+
labs(dict = c(
275+
disp = "Displacement",
276+
mpg = "Miles per gallon",
277+
`factor(cyl)` = "Number of cylinders",
278+
drat = "Rear axle ratio"
279+
))
280+
p <- ggplot_build(p)
281+
282+
x <- p$layout$resolve_label(p$layout$panel_scales_x[[1]], p$plot$labels)
283+
expect_equal(x$primary, "Displacement")
284+
285+
y <- p$layout$resolve_label(p$layout$panel_scales_y[[1]], p$plot$labels)
286+
expect_equal(y$primary, "Miles per gallon")
287+
288+
shape <- p$plot$guides$get_params("shape")$title
289+
expect_equal(shape, "Number of cylinders")
290+
291+
size <- p$plot$guides$get_params("size")$title
292+
expect_equal(size, "Rear axle ratio")
293+
})
294+
270295
# Visual tests ------------------------------------------------------------
271296

272297
test_that("tags are drawn correctly", {

0 commit comments

Comments
 (0)