Skip to content

Commit ff4ab2a

Browse files
committed
Improve testing
1 parent 8b987c1 commit ff4ab2a

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

R/objects.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ new_tab_list <- function(x) {
2222
x_null <- vapply(X = x, FUN = is.null, FUN.VALUE = TRUE)
2323
x_df <- vapply(X = x, FUN = inherits, "data.frame", FUN.VALUE = TRUE)
2424
if (!all(x_null | x_df)) {
25-
stop("the contents of 'x' must be NULL or a 'data.frame'-like object")
25+
stop("The contents of 'x' must be NULL or a 'data.frame'-like object")
2626
}
2727
vctrs::new_vctr(x, class = "tab_list")
2828
}

tests/testthat/test-knit_print.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,8 @@ test_that("knit_print.tab_tibble (and implicitly knit_print.tab_list and print_t
1010
knit_print(d_tab),
1111
regexp = "Cars with 8 cylinders"
1212
)
13+
expect_output(
14+
suppressWarnings(knit_print(d_tab, tab_prefix = "foo")),
15+
regexp = "foo"
16+
)
1317
})

tests/testthat/test-objects.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ test_that("new_tab_tibble", {
88
test_that("new_tab_list", {
99
new_tl <- new_tab_list(list(data.frame(a = 1)))
1010
expect_s3_class(new_tl, "tab_list")
11+
12+
expect_error(
13+
new_tab_list("A"),
14+
regexp = "`x` must be a list"
15+
)
16+
expect_error(
17+
new_tab_list(list("A")),
18+
regexp = "The contents of 'x' must be NULL or a 'data.frame'-like object"
19+
)
1120
})
1221

1322
test_that("vctrs methods", {
@@ -22,4 +31,9 @@ test_that("vctrs methods", {
2231
print(d_tab),
2332
regexp = "Cars with 8 cylinders"
2433
)
34+
expect_output(
35+
print(d_tab$table),
36+
"mpg"
37+
)
38+
expect_equal(vctrs::vec_ptype_abbr(d_tab$table), "tab_list")
2539
})

0 commit comments

Comments
 (0)