Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Melkiades committed Oct 6, 2023
1 parent c5bac8b commit bdac5b7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
8 changes: 8 additions & 0 deletions man/tostring.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 20 additions & 15 deletions tests/testthat/test-printing.R
Original file line number Diff line number Diff line change
Expand Up @@ -414,9 +414,10 @@ test_that("Cell and column label wrapping works in printing", {
expected <- c(" Incredib",
" ly long ",
" column ",
" name to ",
" be ")
expect_identical(splitted_res[1:5], expected)
" name ",
" to be ",
" wrapped ")
expect_identical(splitted_res[1:6], expected)

# String replacement of NAs wider than expected works with cell wrapping
expected <- c("Mean A very ",
Expand Down Expand Up @@ -487,9 +488,11 @@ test_that("row label indentation is kept even if there are newline characters",

# Matrix form and toString
mf_a <- matrix_form(tbl_a, TRUE, FALSE)
expect_error(res_a <- toString(mf_a, widths = c(15, 12, 12)),
regexp = "Inserted width\\(s\\) for column\\(s\\) 1 is\\(are\\) not wide enough for the desired indentation.")
res_a <- toString(mf_a, widths = c(16, 12, 12))
expect_error(
res_a <- toString(mf_a, widths = c(15, 12, 12)),
regexp = "Inserted width for row label column is not wide enough"
)
expect_silent(res_a <- toString(mf_a, widths = c(17, 12, 12)))
# 2 is the indentation of summarize_row_groups
# 1 is the standard indentation
# 1 + 1 + 4 is the standard nesting indentation (twice) + 4 manual indentation (indentation_mod)
Expand Down Expand Up @@ -532,14 +535,16 @@ test_that("row label indentation is kept even if there are newline characters",
main_title(tbl_b) <- "Summary of \nTime and \nTreatment"
subtitles(tbl_b) <- paste("Number: ", 1:3)
main_footer(tbl_b) <- "NE: Not Estimable"

# These errors happen but they should not -> to fix matrix_form (in the second case)
mf_b <- matrix_form(tbl_b, indent_rownames = TRUE, expand_newlines = FALSE)
expect_error(
toString(mf_b, widths = c(17, 12, 12)),
"Found newline characters"
)
mf_b <- matrix_form(tbl_b, indent_rownames = TRUE, expand_newlines = TRUE)
res_b <- toString(mf_b, widths = c(16, 12, 12))
res_b <- strsplit(res_b, "\n")[[1]]

# Taking out the splitted col names and the trailing 0s lets check it is the same none-the-less
res_a <- res_a[-10]
res_b <- res_b[-c(10, 11)]
expect_identical(res_a[1:10], res_b[1:10]) # First part
expect_identical(res_a[10:27], res_b[10:27]) # Center part
expect_identical(res_a[seq(28, length(res_a))], res_b[seq(41, length(res_b))]) # Final part
expect_error(
toString(mf_b, widths = c(17, 12, 12)),
"The sum of the expected nrows header and nrows of content"
)
})

0 comments on commit bdac5b7

Please sign in to comment.