library(testthat)
# Mocking the writeClipboard function for testing
#with_mock_writeClipboard <- function(expr) {
# utils::writeClipboard <- function(x) return(x) # Mock writeClipboard to return the value it would copy
# expr
#}
#
## Test cases for ltx_print_tbl function
#test_that("ltx_print_tbl prints with extra lines when print = TRUE", {
# test_input <- "This is a test"
# result <- with_mock_writeClipboard(ltx_print_tbl(test_input, print = TRUE))
# expect_output(cat(c("", "", "", test_input, "", "", ""), sep = "\n")) # Expect the cat function to output formatted correctly
# expect_equal(result, test_input) # Mocked writeClipboard should return the input string
#})
#
#test_that("ltx_print_tbl does not print when print = FALSE", {
# test_input <- "This will not be printed"
# result <- with_mock_writeClipboard(ltx_print_tbl(test_input, print = FALSE))
# expect_silent(ltx_print_tbl(test_input, print = FALSE)) # No output expected when print = FALSE
#})
#
#test_that("ltx_print_tbl handles multiple lines of input", {
# test_input <- c("Line 1", "Line 2", "Line 3")
# result <- with_mock_writeClipboard(ltx_print_tbl(test_input, print = TRUE))
# expected_output <- cat(c("", "", "", test_input, "", "", ""), sep = "\n")
# expect_output(expected_output) # Expect the formatted output with new lines
# expect_equal(result, test_input) # Mocked writeClipboard should return the input as is
#})
#
#test_that("ltx_print_tbl works with numeric input", {
# numeric_input <- 12345
# result <- with_mock_writeClipboard(ltx_print_tbl(numeric_input, print = TRUE))
# expected_output <- cat(c("", "", "", numeric_input, "", "", ""), sep = "\n")
# expect_output(expected_output) # Numeric input should be printed in the same format
# expect_equal(result, numeric_input) # Mocked writeClipboard should return the input value
#})
#
#test_that("ltx_print_tbl works with mixed input", {
# mixed_input <- c("Text", 123, TRUE)
# result <- with_mock_writeClipboard(ltx_print_tbl(mixed_input, print = TRUE))
# expected_output <- cat(c("", "", "", mixed_input, "", "", ""), sep = "\n")
# expect_output(expected_output) # Mixed input types should be handled correctly and formatted
# expect_equal(result, mixed_input) # Mocked writeClipboard should return the input value
#})
#
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.