Skip to content

Commit bde66d4

Browse files
committed
Improve testing
1 parent 9a2d0fb commit bde66d4

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

R/objects.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ vec_ptype_abbr.tab_list <- function(x, ...) {
3333

3434
#' @export
3535
format.tab_list <- function(x, ...) {
36-
rep("A tab_list object", length(x))
36+
sprintf("A %s object", vapply(X = x, FUN = \(x) class(x)[1], FUN.VALUE = ""))
3737
}
3838

3939
#' @export

tests/testthat/test-knit_print.R

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
test_that("knit_print.tab_tibble (and implicitly knit_print.tab_list and print_tablist_pander)", {
2+
d_tab <-
3+
mtcars |>
4+
tidyr::nest(table = !"cyl") |>
5+
dplyr::mutate(
6+
caption = glue::glue("Cars with {cyl} cylinders")
7+
) |>
8+
new_tab_tibble()
9+
expect_output(
10+
knit_print(d_tab),
11+
regexp = "Cars with 8 cylinders"
12+
)
13+
})

tests/testthat/test-objects.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,17 @@ test_that("new_tab_list", {
99
new_tl <- new_tab_list(list(data.frame(a = 1)))
1010
expect_s3_class(new_tl, "tab_list")
1111
})
12+
13+
test_that("vctrs methods", {
14+
d_tab <-
15+
mtcars |>
16+
tidyr::nest(table = !"cyl") |>
17+
dplyr::mutate(
18+
caption = glue::glue("Cars with {cyl} cylinders")
19+
) |>
20+
new_tab_tibble()
21+
expect_output(
22+
print(d_tab),
23+
regexp = "Cars with 8 cylinders"
24+
)
25+
}

0 commit comments

Comments
 (0)