Skip to content

Commit

Permalink
adds tests for tableName in buildWorkbook()
Browse files Browse the repository at this point in the history
resolves #187
  • Loading branch information
jmbarbone committed May 29, 2021
1 parent ee9565c commit 82c4bc0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/writeDataTable.R
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ writeDataTable <- function(
assert_true_false(bandedCols)

if (is.null(tableName)) {
tableName <- paste0("Table", as.character(length(wb$tables) + 3L))
tableName <- sprintf("Table%i", length(wb$tables) + 3L)
} else {
tableName <- wb$validate_table_name(tableName)
}
Expand Down
18 changes: 18 additions & 0 deletions tests/testthat/test-build_workbook.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
test_that("buildWorkbook() accepts tableName [187]", {
x <- data.frame(a = 1, b = 2)

# default name
wb <- buildWorkbook(x, asTable = TRUE)
expect_equal(attr(wb$tables, "tableName"), "Table3")

# define 1/2 table name
wb <- buildWorkbook(x, asTable = TRUE, tableName = "table_x")
expect_equal(attr(wb$tables, "tableName"), "table_x")

# define 2/2 table names
wb <- buildWorkbook(list(x, x), asTable = TRUE, tableName = c("table_x", "table_y"))
expect_equal(attr(wb$tables, "tableName"), c("table_x", "table_y"))

# try to define 1/2 table names
expect_error(buildWorkbook(list(x, x), asTable = TRUE, tableName = "table_x"))
})

0 comments on commit 82c4bc0

Please sign in to comment.