Skip to content

Commit

Permalink
Make object format less fragile
Browse files Browse the repository at this point in the history
Matrices inherit from arrays in R-devel.
  • Loading branch information
hadley committed Nov 22, 2019
1 parent 2cd424b commit c709c97
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 30 deletions.
4 changes: 4 additions & 0 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
This is a resubmission that fixes a failure on R-devel.

---

## Test environments

* local: darwin15.6.0-3.6.0
Expand Down
37 changes: 7 additions & 30 deletions tests/testthat/test-object-format.R
Original file line number Diff line number Diff line change
@@ -1,32 +1,9 @@
test_that("format has nice defaults for bare vectors", {
expect_equal(
call_to_format(x <- list(a = 1, b = 2)),
"An object of class \\code{list} of length 2."
)
})

test_that("format defaults for S3 objects", {
expect_equal(
call_to_format(x <- ordered(letters[1:5])),
"An object of class \\code{ordered} (inherits from \\code{factor}) of length 5."
)
})

test_that("format has nice defaults for matrices and arrays", {
expect_equal(
call_to_format(x <- diag(10)),
"An object of class \\code{matrix} with 10 rows and 10 columns."
)

expect_equal(
call_to_format(x <- array(1:27, dim = c(3, 3, 3))),
"An object of class \\code{array} of dimension 3 x 3 x 3."
)
})

test_that("format has nice defaults for data frames", {
expect_equal(
call_to_format(x <- data.frame(a = 1, b = 2)),
"An object of class \\code{data.frame} with 1 rows and 2 columns."
)
verify_output(test_path("test-object-format.txt"), {
call_to_format(x <- list(a = 1, b = 2))
call_to_format(x <- ordered(letters[1:5]))
call_to_format(x <- diag(10))
call_to_format(x <- array(1:27, dim = c(3, 3, 3)))
call_to_format(x <- data.frame(a = 1, b = 2))
})
})
15 changes: 15 additions & 0 deletions tests/testthat/test-object-format.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
> call_to_format(x <- list(a = 1, b = 2))
[1] "An object of class \\code{list} of length 2."

> call_to_format(x <- ordered(letters[1:5]))
[1] "An object of class \\code{ordered} (inherits from \\code{factor}) of length 5."

> call_to_format(x <- diag(10))
[1] "An object of class \\code{matrix} with 10 rows and 10 columns."

> call_to_format(x <- array(1:27, dim = c(3, 3, 3)))
[1] "An object of class \\code{array} of dimension 3 x 3 x 3."

> call_to_format(x <- data.frame(a = 1, b = 2))
[1] "An object of class \\code{data.frame} with 1 rows and 2 columns."

0 comments on commit c709c97

Please sign in to comment.