Skip to content

Commit 163ea1c

Browse files
committed
add test
1 parent 0c06945 commit 163ea1c

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

tests/testthat/_snaps/ggsave.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@
5151
! Dimensions exceed 50 inches (`height` and `width` are specified in pixels).
5252
i If you're sure you want a plot that big, use `limitsize = FALSE`.
5353

54+
# derives dimensions from plot
55+
56+
Code
57+
plot_dim(width = derive(), height = derive(), plot = theme())
58+
Condition
59+
Error:
60+
! Cannot derive size of plot when `plot` is a <theme> object.
61+
5462
# unknown device triggers error
5563

5664
`device` must be a string, function or `NULL`, not the number 1.

tests/testthat/test-ggsave.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,20 @@ test_that("scale multiplies height & width", {
121121
expect_equal(plot_dim(10, 10, scale = 1), c(10, 10))
122122
expect_equal(plot_dim(5, 5, scale = 2), c(10, 10))
123123
})
124+
125+
test_that("derives dimensions from plot", {
126+
127+
plot <- gtable(widths = unit(1, "null"), heights = unit(1, "in"))
128+
dim <- suppressMessages(plot_dim(width = derive(), height = derive(), plot = plot))
129+
expect_equal(unname(dim), c(7, 1))
130+
131+
plot <- gtable(widths = unit(12.7, "cm"), heights = unit(1, "null"))
132+
dim <- suppressMessages(plot_dim(width = derive(), height = derive(), plot = plot))
133+
expect_equal(unname(dim), c(5, 7))
134+
135+
# Cannot derive from non-plot objects
136+
expect_snapshot(plot_dim(width = derive(), height = derive(), plot = theme()), error = TRUE)
137+
124138
})
125139

126140
# plot_dev ---------------------------------------------------------------------

0 commit comments

Comments
 (0)