Error in `grepl(trigger_pattern, last)`: invalid regular expression '[#\-=]{4,}$', reason 'Invalid character range'

test_that("output is a single character string", {
result <- generate_comment_box("Hello", print_box = FALSE)
test_that("box always has 5 lines minimum (border, empty, text, empty, border)", {
test_that("invalid alignment throws an error", {
generate_comment_box("Hello", align = "justify", print_box = FALSE),
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)
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)
test_that("print_box = TRUE returns invisibly and prints", {
result <- generate_comment_box("Hello", print_box = TRUE),
# ---- section_title = FALSE : comportement d'origine ----
test_that("section_title = FALSE : first and last lines are full '#' borders", {
result <- generate_comment_box("Hello", width = 80,
section_title = FALSE, print_box = FALSE)
border <- paste(rep("#", 80), collapse = "")
test_that("section_title = FALSE : box width matches requested width", {
result <- generate_comment_box("Hello", width = w,
expect_true(all(nchar(lines) == w), label = paste("width =", w))
test_that("section_title = FALSE : all alignments produce correct width", {
for (align in c("left", "center", "right")) {
result <- generate_comment_box("Test alignment", align = align,
expect_true(all(nchar(lines) == 80), label = paste("align =", align))
test_that("section_title = FALSE : border_style is ignored", {
ref    <- generate_comment_box("Hello", width = 80,
styled <- generate_comment_box("Hello", width = 80,
section_title = FALSE, border_style = "soft",
# ---- section_title = TRUE : comportement par style ----
test_that("section_title = TRUE : invalid border_style throws an error", {
border_style = "unknown", print_box = FALSE),
# Paramètres de chaque style : top_char, bottom_char
test_that("section_title = TRUE : all styles produce correct width", {
for (style_name in names(styles_params)) {
result <- generate_comment_box("Test", width = w,
label = paste("style =", style_name, "/ width =", w))
test_that("section_title = TRUE : top border contains comment text", {
result <- generate_comment_box("My Section", width = 80,
expect_true(grepl("My Section", lines[1], fixed = TRUE),
test_that("section_title = TRUE : top border triggers RStudio section (ends with 4+ trigger chars)", {
# Les caractères déclencheurs RStudio sont '#', '-' et '='
label = paste("style =", style_name, ": top_char doit être #, - ou ="))
pattern <- paste0("[", top_char, "]{4,}$")
label = paste("style =", style_name, ": top se termine par 4+", top_char))
test_that("section_title = TRUE : bottom border does NOT end with RStudio trigger chars", {
": bottom ne doit pas déclencher une section RStudio"))
test_that("section_title = TRUE : bottom border uses the correct fill character", {
result   <- generate_comment_box("Hello", width = 80,
# Le bord inférieur est '#' + (width-1) bot_char
expected_bottom <- paste0("#", paste(rep(bot_char, 79), collapse = ""))
test_that("section_title = TRUE : long comment is truncated with '...' in the header", {
long_comment <- paste(rep("a", 200), collapse = "")
result       <- generate_comment_box(long_comment, width = 80, print_box = FALSE)
test_that("section_title = TRUE : all alignments produce correct width (default style)", {