Skip to content

Commit

Permalink
[tests] add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JanMarvin committed Nov 12, 2023
1 parent 0e66669 commit bab97ce
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/testthat/test-class-workbook.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,22 @@ test_that("wb_set_col_widths", {

})

test_that("option maxWidth works", {

op <- options("openxlsx2.maxWidth" = 6)
on.exit(options(op), add = TRUE)

wb <- wb_workbook()$add_worksheet()$add_data(x = data.frame(
x = paste0(letters, collapse = ""),
y = paste0(letters, collapse = "")
))$set_col_widths(cols = 1:2, widths = "auto")

exp <- "<col min=\"1\" max=\"2\" bestFit=\"1\" customWidth=\"1\" hidden=\"false\" width=\"6\"/>"
got <- wb$worksheets[[1]]$cols_attr
expect_equal(exp, got)

})


# order -------------------------------------------------------------------

Expand Down
21 changes: 21 additions & 0 deletions tests/testthat/test-writing_posixct.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,24 @@ test_that("Writing mixed EDT/EST Posixct with write_data & write_datatable", {
expect_equal(exp, got)

})

test_that("numfmt escaping works", {

op <- options(
"openxlsx2.datetimeFormat" = "yyyy\\/mm\\/dd",
"openxlsx2.dateFormat" = "mm/dd/yyyy"
)
on.exit(options(op), add = TRUE)

test_data <- data.frame(
datetime_col = as.POSIXct("2023-12-31 00:00:00"),
date_col = as.Date("2023-12-31")
)
wb <- wb_workbook()$add_worksheet()$add_data(x = test_data)

exp <- c("<numFmt numFmtId=\"165\" formatCode=\"mm\\/dd\\/yyyy\"/>",
"<numFmt numFmtId=\"166\" formatCode=\"yyyy\\/mm\\/dd\"/>")
got <- wb$styles_mgr$styles$numFmts
expect_equal(exp, got)

})

0 comments on commit bab97ce

Please sign in to comment.