Skip to content

Commit

Permalink
Tidy up these tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jennybc committed Sep 21, 2023
1 parent 07feee2 commit 02f5571
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
4 changes: 2 additions & 2 deletions tests/testthat/_snaps/glue.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# + method requires character vectors
# `+` method requires character vectors

Code
as_glue("a") + 1
Expand All @@ -9,7 +9,7 @@
Error <simpleError>
LHS must be a character vector.

# `+` method returns length-0 for a length-0 input
# `+` method errors for inputs of incompatible size

Code
as_glue(letters[1:2]) + letters[1:3]
Expand Down
28 changes: 16 additions & 12 deletions tests/testthat/test-glue.R
Original file line number Diff line number Diff line change
Expand Up @@ -507,30 +507,34 @@ test_that("throws informative error if interpolating a function", {
}
})

test_that("+ method for glue works", {
expect_identical(glue("foo") + "bar", as_glue("foobar"))
expect_identical(glue("x = ") + "{x}", as_glue("x = {x}"))
test_that("`+` method for glue works", {
expect_identical(glue("foo") + "bar", "foobar")
expect_identical("foo" + glue("bar"), "foobar")
})

x <- c("a", "b", "c")
expect_identical("(" + as_glue(x) + ")", paste0("(", x, ")"))
test_that("`+` method requires character vectors", {
expect_snapshot(error = TRUE, {
as_glue("a") + 1
1 + as_glue("a")
})
})

test_that("`+` method does not interpolate twice", {
expect_identical(glue("{x}", x = "{wut}") + "y", as_glue("{wut}y"))
expect_identical(glue("{x}", x = "{wut}") + "y", "{wut}y")
})

test_that("`+` method returns length-0 for a length-0 input", {
expect_identical(as_glue("hello") + character(), character())
})

test_that("+ method requires character vectors", {
expect_snapshot(error = TRUE, {
as_glue("a") + 1
1 + as_glue("a")
})
test_that("`+` recycles", {
x <- c("a", "b", "c")
expect_identical("(" + as_glue(x) + ")", paste0("(", x, ")"))
y <- as.character(1:3)
expect_identical(as_glue(x) + y, c("a1", "b2", "c3"))
})

test_that("`+` method returns length-0 for a length-0 input", {
test_that("`+` method errors for inputs of incompatible size", {
expect_snapshot(error = TRUE, {
as_glue(letters[1:2]) + letters[1:3]
})
Expand Down

0 comments on commit 02f5571

Please sign in to comment.