Skip to content

Commit 967a647

Browse files
committed
add tests
1 parent c84a16a commit 967a647

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

tests/testthat/_snaps/coord-.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,11 @@
3434
Error:
3535
! `1:3` must be a vector of length 2, not length 3.
3636

37+
# adding default coords works correctly
38+
39+
Code
40+
test <- test + coord_cartesian(xlim = c(-2, 2))
41+
Message
42+
Coordinate system already present.
43+
i Adding new coordinate system, which will replace the existing one.
44+

tests/testthat/test-coord-.R

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,31 @@ test_that("coord expand takes a vector", {
108108

109109
})
110110

111+
test_that("adding default coords works correctly", {
112+
113+
base <- ggplot() + coord_cartesian(default = TRUE, xlim = c(0, 1))
114+
115+
# default + user = user
116+
expect_no_message(
117+
test <- base + coord_cartesian(xlim = c(-1, 1))
118+
)
119+
expect_equal(test@coordinates$limits$x, c(-1, 1))
120+
121+
# user1 + user2 = user2 + message
122+
expect_snapshot(
123+
test <- test + coord_cartesian(xlim = c(-2, 2))
124+
)
125+
expect_equal(test@coordinates$limits$x, c(-2, 2))
126+
127+
# user + default = user
128+
expect_no_message(
129+
test <- test + coord_cartesian(xlim = c(-3, 3), default = TRUE)
130+
)
131+
expect_equal(test@coordinates$limits$x, c(-2, 2))
132+
133+
# default1 + default2 = default2 (silent)
134+
expect_no_message(
135+
test <- base + coord_cartesian(xlim = c(-4, 4), default = TRUE)
136+
)
137+
expect_equal(test@coordinates$limits$x, c(-4, 4))
138+
})

0 commit comments

Comments
 (0)