Skip to content

Commit

Permalink
Tests for newline allowance
Browse files Browse the repository at this point in the history
  • Loading branch information
Melkiades committed Oct 13, 2023
1 parent e3dfa6f commit 26327c6
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions tests/testthat/test-printing.R
Original file line number Diff line number Diff line change
Expand Up @@ -543,3 +543,52 @@ test_that("row label indentation is kept even if there are newline characters",
"Found newline characters"
)
})

test_that("Support for newline characters in all the parts", {
DM_trick <- DM %>%
mutate(ARM2 = sample(c("TWO\nwords\n", "A wo\n\nrd"), replace = TRUE, nrow(DM))) # last \n is eaten up
levels(DM_trick$SEX)[3] <- "U\nN\nD\n"
tbl <- basic_table() %>%
split_rows_by("SEX", split_label = "m\nannaggia\nsda\n", label_pos = "visible") %>% # last \n bug
split_cols_by("ARM2", split_label = "sda") %>%
analyze("BMRKR1", na_str = "asd\nasd") %>% # \n error
build_table(DM_trick)

top_left(tbl) <- c("a", "b\nd\n\n", "c\n\n") # last \n is eaten up, if in the middle error
main_title(tbl) <- "why not \nalso here\n"
# matrix_form(tbl)
# to_string_matrix2(tbl, hsep = "-", with_spaces = TRUE, print_txt_to_copy = TRUE)
out <- strsplit(toString(tbl, hsep = "-"), "\\n")[[1]]
expected <- c(
"why not ",
"also here",
"",
"",
"---------------------------------",
"a ",
"b ",
"d ",
" ",
" A wo ",
"c TWO ",
" rd words",
"---------------------------------",
"m ",
"annaggia ",
"sda ",
" F ",
" Mean 5.95 6.13 ",
" M ",
" Mean 5.82 5.46 ",
" U ",
" N ",
" D ",
" ",
" Mean asd asd ",
" asd asd ",
" UNDIFFERENTIATED ",
" Mean asd asd ",
" asd asd "
)
expect_identical(out, expected)
})

0 comments on commit 26327c6

Please sign in to comment.