test_that("output is a single character string", { result <- generate_comment_box("Hello", print_box = FALSE) expect_type(result, "character") expect_length(result, 1) }) test_that("box width matches requested width", { result <- generate_comment_box("Hello", width = 80, print_box = FALSE) lines <- strsplit(result, "\n")[[1]] expect_true(all(nchar(lines) == 80)) }) test_that("box width works with custom values", { for (w in c(20, 40, 60, 100)) { result <- generate_comment_box("Test", width = w, print_box = FALSE) lines <- strsplit(result, "\n")[[1]] expect_true(all(nchar(lines) == w), label = paste("width =", w)) } }) test_that("box always has 5 lines minimum (border, empty, text, empty, border)", { result <- generate_comment_box("Hello", print_box = FALSE) lines <- strsplit(result, "\n")[[1]] expect_gte(length(lines), 5) }) test_that("first and last lines are full '#' borders", { result <- generate_comment_box("Hello", width = 80, print_box = FALSE) lines <- strsplit(result, "\n")[[1]] border <- paste(rep("#", 80), collapse = "") expect_equal(lines[1], border) expect_equal(lines[length(lines)], border) }) test_that("all alignments produce correct width", { for (align in c("left", "center", "right")) { result <- generate_comment_box("Test alignment", align = align, width = 80, print_box = FALSE) lines <- strsplit(result, "\n")[[1]] expect_true(all(nchar(lines) == 80), label = paste("align =", align)) } }) test_that("invalid alignment throws an error", { expect_error( generate_comment_box("Hello", align = "justify", print_box = FALSE), "Invalid alignment" ) }) test_that("long words are split and do not overflow the box", { long_word <- paste(rep("a", 200), collapse = "") result <- generate_comment_box(long_word, width = 80, print_box = FALSE) lines <- strsplit(result, "\n")[[1]] expect_true(all(nchar(lines) == 80)) }) test_that("multi-word comment wraps correctly within width", { comment <- paste(rep("word", 30), collapse = " ") result <- generate_comment_box(comment, width = 80, print_box = FALSE) lines <- strsplit(result, "\n")[[1]] expect_true(all(nchar(lines) == 80)) }) test_that("print_box = TRUE returns invisibly and prints", { expect_output( result <- generate_comment_box("Hello", print_box = TRUE), regexp = "#{80}" ) expect_type(result, "character") })