Skip to content

Commit abd56a1

Browse files
committed
distribute test-guides.R
1 parent bd8c5d3 commit abd56a1

File tree

5 files changed

+761
-750
lines changed

5 files changed

+761
-750
lines changed

tests/testthat/test-guide-.R

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
skip_on_cran()
2+
3+
test_that("plotting does not induce state changes in guides", {
4+
5+
guides <- guides(
6+
x = guide_axis(title = "X-axis"),
7+
colour = guide_colourbar(title = "Colourbar"),
8+
shape = guide_legend(title = "Legend"),
9+
size = guide_bins(title = "Bins")
10+
)
11+
12+
p <- ggplot(mpg, aes(displ, hwy, colour = cty, shape = factor(cyl),
13+
size = cyl)) +
14+
geom_point() +
15+
guides
16+
17+
snapshot <- serialize(as.list(p$guides), NULL)
18+
19+
grob <- ggplotGrob(p)
20+
21+
expect_identical(as.list(p$guides), unserialize(snapshot))
22+
})
23+
24+
test_that("adding guides doesn't change plot state", {
25+
26+
p1 <- ggplot(mtcars, aes(disp, mpg))
27+
28+
expect_length(p1$guides$guides, 0)
29+
30+
p2 <- p1 + guides(y = guide_axis(angle = 45))
31+
32+
expect_length(p1$guides$guides, 0)
33+
expect_length(p2$guides$guides, 1)
34+
35+
p3 <- p2 + guides(y = guide_axis(angle = 90))
36+
37+
expect_length(p3$guides$guides, 1)
38+
expect_equal(p3$guides$guides[[1]]$params$angle, 90)
39+
expect_equal(p2$guides$guides[[1]]$params$angle, 45)
40+
})
41+
42+
test_that("dots are checked when making guides", {
43+
expect_snapshot_warning(
44+
new_guide(foo = "bar", super = GuideAxis)
45+
)
46+
expect_snapshot_warning(
47+
guide_legend(foo = "bar")
48+
)
49+
})

0 commit comments

Comments
 (0)