Skip to content

Commit

Permalink
Add compare_proxy method and convert to testthat 3e
Browse files Browse the repository at this point in the history
Fixes #212
  • Loading branch information
jimhester committed Oct 6, 2021
1 parent 630ba1a commit 274130c
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 13 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ BugReports: https://github.com/tidyverse/glue/issues
VignetteBuilder: knitr
ByteCompile: true
Config/Needs/website: tidyverse/tidytemplate
Config/testthat/edition: 3
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# glue (development version)

* `compare_proxy.glue()` method defined so glue objects can be compared to strings in testthat 3e without errors (#212)
* Unterminated comments in glue expression now throw an error (#227, @gaborcsardi)
* Unterminated quotes in glue expressions now throw an error (#226, @gaborcsardi)
* `print.glue()` no longer prints an empty newline for 0 length inputs (#214)
Expand Down
6 changes: 6 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,9 @@ compare.glue <- function(x, y, ...) {
}
NextMethod("compare")
}

## @export
compare_proxy.glue <- function(x, path = "x") {
class(x) <- NULL
NextMethod("compare_proxy")
}
1 change: 1 addition & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# nocov start
.onLoad <- function(...) {
register_s3_method("testthat", "compare", "glue")
register_s3_method("waldo", "compare_proxy", "glue")

# Register on package load because vctrs depends on glue and will
# not be fully loaded when glue is loaded
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-collapse.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("glue_collapse")

test_that("glue_collapse works like paste(glue_collapse=)", {
# Always return 0 length outputs for 0 length inputs.
#expect_identical(paste(glue_collapse = "", character(0)), glue_collapse(character(0)))
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-color.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("color")

skip_if_not_installed("crayon")
library(crayon)

Expand Down
8 changes: 5 additions & 3 deletions tests/testthat/test-glue.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("glue")

test_that("inputs are concatenated, interpolated variables recycled", {
expect_equal(glue("test", "a", "string", "{1:2}"), c("testastring1", "testastring2"))
})
Expand Down Expand Up @@ -505,7 +503,7 @@ test_that("throws informative error if interpolating a function", {

# some crayon functions are OK, make sure this still works
if (require("crayon")) {
expect_is(glue("{red}red{reset}"), "glue")
expect_s3_class(glue("{red}red{reset}"), "glue")
}
})

Expand All @@ -531,3 +529,7 @@ test_that("unterminated comment", {
test_that("empty glue produces no output", {
expect_equal(capture.output(print(glue())), character())
})

test_that("glue objects can be compared to regular strings", {
expect_equal(capture.output(print(glue())), character())
})
2 changes: 0 additions & 2 deletions tests/testthat/test-quoting.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("quoting")

test_that("single_quote works", {
expect_identical(single_quote(character()), character())
expect_identical(single_quote(NA), NA_character_)
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-sql.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("sql")

skip_if_not_installed("DBI")
skip_if_not_installed("RSQLite")

Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-trim.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("trim")

test_that("trim works", {
expect_identical("", trim(""))
expect_identical(character(), trim(character()))
Expand Down

0 comments on commit 274130c

Please sign in to comment.