| 1 |
# obj_sum ---------------------------------------------------------------- |
| 2 |
|
| 3 |
test_that("forwards to vec_ptype_abbr() for S4", { |
| 4 |
x <- methods::setClass("A") |
| 5 |
expect_equal(obj_sum(x), vec_ptype_abbr(x)) |
| 6 |
}) |
| 7 |
|
| 8 |
test_that("forwards to vec_ptype_abbr() for S3", { |
| 9 |
x <- structure(list(), class = c("a", "b", "c")) |
| 10 |
expect_equal(obj_sum(x), vec_ptype_abbr(x)) |
| 11 |
}) |
| 12 |
|
| 13 |
test_that("NULL handled specially", { |
| 14 |
expect_equal(obj_sum(NULL), "NULL") |
| 15 |
}) |
| 16 |
|
| 17 |
test_that("data frames and common data vectors have size summary", { |
| 18 |
local_override_size_sum() |
| 19 |
|
| 20 |
expect_obj_sum_is_ptype <- function(x) { |
| 21 |
obj_sum <- obj_sum(x) |
| 22 |
attr(obj_sum, "short") <- NULL |
| 23 |
|
| 24 |
ptype <- vec_ptype_abbr(x, suffix_shape = FALSE) |
| 25 |
|
| 26 |
expect_equal(obj_sum, !!paste_with_space_if_needed(ptype, size_sum(x))) |
| 27 |
} |
| 28 |
|
| 29 |
expect_obj_sum_is_ptype(mtcars) |
| 30 |
expect_obj_sum_is_ptype(factor(1:3)) |
| 31 |
expect_obj_sum_is_ptype(ordered(1:3)) |
| 32 |
expect_obj_sum_is_ptype(Sys.Date() + 1:3) |
| 33 |
expect_obj_sum_is_ptype(Sys.time() + 1:3) |
| 34 |
expect_obj_sum_is_ptype(Sys.time() - Sys.time() + 1:3) |
| 35 |
expect_obj_sum_is_ptype(as.POSIXlt(Sys.time() + 1:3)) |
| 36 |
expect_obj_sum_is_ptype(list(1, 2:3)) |
| 37 |
expect_obj_sum_is_ptype(matrix(1:10, ncol = 2)) |
| 38 |
expect_obj_sum_is_ptype(Titanic) |
| 39 |
expect_obj_sum_is_ptype(as_override_size_sum(1:3)) |
| 40 |
}) |
| 41 |
|
| 42 |
test_that("object summary has short version", { |
| 43 |
local_override_size_sum() |
| 44 |
|
| 45 |
expect_obj_sum_short_is_ptype <- function(x, suffix = "") { |
| 46 |
obj_sum <- attr(obj_sum(x), "short") |
| 47 |
|
| 48 |
ptype <- vec_ptype_abbr(x, suffix_shape = FALSE) |
| 49 |
|
| 50 |
expect_equal(obj_sum, !!paste0(ptype, suffix)) |
| 51 |
} |
| 52 |
|
| 53 |
expect_obj_sum_short_is_ptype(mtcars) |
| 54 |
expect_obj_sum_short_is_ptype(factor(1:3)) |
| 55 |
expect_obj_sum_short_is_ptype(ordered(1:3)) |
| 56 |
expect_obj_sum_short_is_ptype(Sys.Date() + 1:3) |
| 57 |
expect_obj_sum_short_is_ptype(Sys.time() + 1:3) |
| 58 |
expect_obj_sum_short_is_ptype(Sys.time() - Sys.time() + 1:3) |
| 59 |
expect_obj_sum_short_is_ptype(as.POSIXlt(Sys.time() + 1:3)) |
| 60 |
expect_obj_sum_short_is_ptype(list(1, 2:3)) |
| 61 |
expect_obj_sum_short_is_ptype(matrix(1:10, ncol = 2), paste0("[", symbol$ellipsis, "]")) |
| 62 |
expect_obj_sum_short_is_ptype(Titanic, paste0("[", symbol$ellipsis, "]")) |
| 63 |
expect_obj_sum_short_is_ptype(as_override_size_sum(1:3)) |
| 64 |
}) |
| 65 |
|
| 66 |
|
| 67 |
# type_sum ---------------------------------------------------------------- |
| 68 |
|
| 69 |
test_that("less common objects get abbreviations", { |
| 70 |
expect_equal(type_sum(environment()), "env") |
| 71 |
expect_equal(type_sum(environment), "fn") |
| 72 |
expect_equal(type_sum(list), "fn") |
| 73 |
expect_equal(type_sum(quote(foo)), "sym") |
| 74 |
expect_equal(type_sum(expr()), "missing") |
| 75 |
}) |