Skip to content

Commit

Permalink
addition of tests for fixes to pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
Melkiades committed Jan 9, 2024
1 parent 8264698 commit adb28ca
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 21 deletions.
15 changes: 9 additions & 6 deletions R/rlistings.R
Original file line number Diff line number Diff line change
Expand Up @@ -258,21 +258,24 @@ get_keycols <- function(df) {
names(which(sapply(df, is_keycol)))
}

#' @export
#' @inherit formatters::matrix_form
#' @seealso [formatters::matrix_form()]
#' @param indent_rownames logical(1). Silently ignored, as listings do not have row names
#' nor indenting structure.
#' nor indenting structure.
#'
#' @examples
#'
#' lsting <- as_listing(mtcars)
#' mf <- matrix_form(lsting)
#'
#' @return a `MatrixPrintForm` object
#'
#' @note Parameter `expand_newlines` should always be `TRUE` for listings. We keep it for
#' debugging reasons.
#'
#' @export
setMethod(
"matrix_form", "listing_df",
rix_form <- function(obj, indent_rownames = FALSE) {
rix_form <- function(obj, indent_rownames = FALSE, expand_newlines = TRUE) {
## we intentionally silently ignore indent_rownames because listings have
## no rownames, but formatters::vert_pag_indices calls matrix_form(obj, TRUE)
## unconditionally.
Expand Down Expand Up @@ -339,11 +342,11 @@ setMethod(
ncol = ncol(fullmat)
),
row_info = make_row_df(obj),
nlines_header = 1, ## XXX this is probably wrong!!!
nlines_header = 1, # We allow only one level of headers and nl expansion happens after
nrow_header = 1,
has_topleft = FALSE,
has_rowlabs = FALSE,
expand_newlines = TRUE,
expand_newlines = expand_newlines,
main_title = main_title(obj),
subtitles = subtitles(obj),
page_titles = page_titles(obj),
Expand Down
12 changes: 10 additions & 2 deletions man/matrix_form-listing_df-method.Rd

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

28 changes: 28 additions & 0 deletions tests/testthat/_snaps/paginate_listing.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,31 @@
AB12345-BRA-1-id-65 25 MEDIUM

# pagination repeats keycols in other pages

Code
cat(toString(mf_pages[[3]]))
Output
a b
——————
1 17
18
19
20
21
22

---

Code
cat(toString(mf_pages[[3]]))
Output
a b
——————
17
18
19
20
21
22

42 changes: 29 additions & 13 deletions tests/testthat/_snaps/print.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,33 @@
Code
res
Output
[1] " "
[2] " "
[3] " Unique Description a "
[4] " Subject Of "
[5] " Identifier Planned Arm n "
[6] "------------------------------------------------------"
[7] "AB12345-CHN-11-id-220 - 10.2627340069523"
[8] " asd "
[9] "AB12345-CHN-15-id-262 ARM #: 3 4.05546277230382"
[10] " AB12345-RUS-3-id-378 - 2.80323956920649"
[11] " asd "
[12] " aaatrial ARM #: 1 14.424933692778 "
[13] " trial "
[1] "main_title: argh"
[2] "asr"
[3] "subtitle: argh"
[4] "asr"
[5] "sada"
[6] ""
[7] "------------------------------------------------------"
[8] " "
[9] " "
[10] " Unique Description a "
[11] " Subject Of "
[12] " Identifier Planned Arm n "
[13] "------------------------------------------------------"
[14] "AB12345-CHN-11-id-220 - 10.2627340069523"
[15] " asd "
[16] "AB12345-CHN-15-id-262 ARM #: 3 4.05546277230382"
[17] " AB12345-RUS-3-id-378 - 2.80323956920649"
[18] " asd "
[19] " aaatrial ARM #: 1 14.424933692778 "
[20] " trial "
[21] "------------------------------------------------------"
[22] ""
[23] "main_footer: argh"
[24] "asr"
[25] "sada"
[26] ""
[27] "prov_footer: argh"
[28] "asr"
[29] "sada"

19 changes: 19 additions & 0 deletions tests/testthat/test-paginate_listing.R
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,25 @@ testthat::test_that("pagination repeats keycols in other pages", {
"AB12345-BRA-1-id-42",
paginate_to_mpfs(lsting, lpp = 33, cpp = 550)[[2]]$strings
)[2])

# Simplified test
mf_pages <- as_listing(tibble("a" = rep("1", 25), "b" = seq(25)), key_cols = "a") %>%
paginate_to_mpfs(lpp = 10)

expect_snapshot(cat(toString(mf_pages[[3]])))

# Warning from empty key col
mf_pages <- suppressWarnings(
expect_warning(
as_listing(tibble("a" = rep("", 25), "b" = seq(25)), key_cols = "a") %>%
paginate_to_mpfs(lpp = 10)
)

Check warning on line 207 in tests/testthat/test-paginate_listing.R

View workflow job for this annotation

GitHub Actions / SuperLinter 🦸‍♀️ / Lint R code 🧶

file=tests/testthat/test-paginate_listing.R,line=207,col=6,[indentation_linter] Indentation should be 4 spaces but is 6 spaces.
)

expect_snapshot(
cat(toString(mf_pages[[3]]))
)

})

testthat::test_that("defunct is defunct", {
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-print.R
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ testthat::test_that("listings support newline characters", {
ARM = fmt_config(format = sprintf_format("ARM #: %s"), na_str = "-\nasd\n", align = "left")
)
)
main_footer(lsting) <- c("main_footer: argh\nasr", "sada\n")
prov_footer(lsting) <- c("prov_footer: argh\nasr", "sada\n")
main_title(lsting) <- "main_title: argh\nasr"
subtitles(lsting) <- c("subtitle: argh\nasr", "sada\n")

res <- strsplit(toString(matrix_form(lsting), hsep = "-"), "\\n")[[1]]
testthat::expect_snapshot(res)
Expand Down

0 comments on commit adb28ca

Please sign in to comment.