Skip to content

Commit 3ab74d2

Browse files
committed
add tests
1 parent d2f86ad commit 3ab74d2

File tree

3 files changed

+92
-0
lines changed

3 files changed

+92
-0
lines changed
Lines changed: 27 additions & 0 deletions
Loading
Lines changed: 24 additions & 0 deletions
Loading

tests/testthat/test-theme.R

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,47 @@ test_that("margin_part() mechanics work as expected", {
675675

676676
# Visual tests ------------------------------------------------------------
677677

678+
test_that("element_polygon() can render a grob", {
679+
680+
t <- theme_gray() + theme(polygon = element_polygon(fill = "orchid"))
681+
e <- calc_element("polygon", t)
682+
g <- element_grob(
683+
e,
684+
x = c(0, 0.5, 1, 0.5, 0.15, 0.85, 0.85, 0.15),
685+
y = c(0.5, 0, 0.5, 1, 0.15, 0.15, 0.85, 0.85),
686+
id = c(1, 1, 1, 1, 2, 2, 2, 2),
687+
colour = c("orange", "limegreen")
688+
)
689+
690+
expect_s3_class(g, "pathgrob")
691+
expect_equal(g$gp$fill, "orchid")
692+
693+
expect_doppelganger(
694+
"polygon elements",
695+
function() {grid.newpage(); grid.draw(g)}
696+
)
697+
})
698+
699+
test_that("element_point() can render a grob", {
700+
701+
t <- theme_gray() + theme(point = element_point(shape = 21, size = 5))
702+
e <- calc_element("point", t)
703+
g <- element_grob(
704+
e,
705+
x = seq(0.1, 0.9, length.out = 5),
706+
y = seq(0.9, 0.1, length.out = 5),
707+
fill = c("orange", "limegreen", "orchid", "turquoise", "grey")
708+
)
709+
710+
expect_s3_class(g, "points")
711+
expect_equal(g$pch, 21)
712+
713+
expect_doppelganger(
714+
"point elements",
715+
function() {grid.newpage(); grid.draw(g)}
716+
)
717+
})
718+
678719
test_that("aspect ratio is honored", {
679720
df <- cbind(data_frame(x = 1:8, y = 1:8, f = gl(2,4)), expand.grid(f1 = 1:2, f2 = 1:2, rep = 1:2))
680721
p <- ggplot(df, aes(x, y)) +

0 commit comments

Comments
 (0)