# -- trailing commas in tags$*() -------------------------------------------- test_that("trailing comma after single child in tags$*()", { node <- tags$p( "hello", ) expect_s3_class(node, "hypertext.tag") expect_equal(node$children, list("hello")) expect_equal(render(node), "

hello

") }) test_that("trailing comma after multiple children in tags$*()", { node <- tags$p( tags$span("a"), tags$span("b"), ) expect_length(node$children, 2L) expect_equal( render(node), "

ab

" ) }) test_that("trailing comma after single attribute in tags$*()", { node <- tags$div( class = "container", ) expect_equal(node$attrs$class, "container") expect_length(node$children, 0L) expect_equal(render(node), '
') }) test_that("trailing comma after children when attributes present", { node <- tags$div( class = "wrapper", tags$p("content"), ) expect_equal(node$attrs$class, "wrapper") expect_length(node$children, 1L) expect_equal( render(node), '

content

' ) }) test_that("trailing comma in void tag", { node <- tags$input( type = "text", name = "field", ) expect_equal(node$tag_type, "void") expect_equal( render(node), '' ) }) # -- trailing commas in tag_list() ------------------------------------------ test_that("trailing comma in tag_list() with single element", { tl <- tag_list( tags$p("one"), ) expect_s3_class(tl, "hypertext.tag.list") expect_length(tl, 1L) expect_equal(render(tl), "

one

") }) test_that("trailing comma in tag_list() with multiple elements", { tl <- tag_list( tags$h1("title"), tags$p("body"), ) expect_length(tl, 2L) expect_equal(render(tl), "

title

body

") }) test_that("trailing comma in tag_list() with mixed tags and text", { tl <- tag_list( "hello ", tags$strong("world"), ) expect_length(tl, 2L) expect_equal(render(tl), "hello world") }) # -- nested tags with trailing commas --------------------------------------- test_that("trailing comma in both outer and inner nested tags", { node <- tags$div( tags$p( tags$span("inner"), ), ) expect_equal( render(node), "

inner

" ) }) test_that("trailing comma only in outer tag", { node <- tags$div( tags$p(tags$span("inner")), ) expect_equal( render(node), "

inner

" ) }) test_that("trailing comma only in inner tag", { node <- tags$div( tags$p( tags$span("inner"), ) ) expect_equal( render(node), "

inner

" ) }) test_that("deeply nested tags with trailing commas at every level", { node <- tags$div( tags$section( tags$article( tags$p( tags$span("deep"), ), ), ), ) expect_equal( render(node), paste0( "
", "

deep

", "
" ) ) }) # -- trailing commas referencing outer scope variables ---------------------- test_that("trailing comma after variable indexing", { x <- c("alpha", "beta", "gamma") node <- tags$p( x[1], ) expect_equal(node$children, list("alpha")) expect_equal(render(node), "

alpha

") }) test_that("trailing comma after multiple variable references", { x <- c("hello", "world") node <- tag_list( tags$div( tags$p( x[1], " ", ), tags$p( x[2], ), ), ) expect_equal(render(node), "

hello

world

") }) test_that("trailing comma after lapply referencing outer variable", { items <- c("a", "b", "c") node <- tags$ul( lapply( X = items, FUN = function(x) { tags$li( paste("item:", x), ) } ), ) expect_length(node$children, 3L) expect_equal( render(node), "" ) }) test_that("tag_list with lapply and trailing comma", { items <- c("a", "b", "c") tl <- tag_list( tags$h3("a page"), lapply(items, tags$p), ) expect_length(tl, 2L) expect_equal( render(tl), "

a page

a

b

c

" ) }) test_that("nested tags referencing outer variable with trailing commas", { x <- c("a", "b", "c") node <- tag_list( tags$h3("heading"), tags$p(x[1], ), lapply(x, tags$span), ) expect_length(node, 3L) expect_equal( render(node), paste0( "

heading

", "

a

", "abc" ) ) }) test_that("trailing comma with variable used as attribute value", { cls <- "highlight" node <- tags$div( class = cls, tags$p("text"), ) expect_equal(node$attrs$class, "highlight") expect_equal( render(node), '

text

' ) }) test_that("trailing comma with computed expression as child", { vals <- 1:3 node <- tags$p( paste(vals, collapse = ", "), ) expect_equal(render(node), "

1, 2, 3

") }) test_that("trailing comma after variable in nested tag inside tag_list", { title <- "My Page" items <- c("first", "second") tl <- tag_list( tags$h1(title, ), tags$ul( lapply(items, function(item) { tags$li(item, ) }), ), ) expect_equal( render(tl), paste0( "

My Page

", "" ) ) }) # -- trailing commas with NULL handling ------------------------------------- test_that("trailing comma with NULL child", { node <- tags$p( "text", NULL, ) expect_equal(node$children, list("text")) expect_equal(render(node), "

text

") }) test_that("trailing comma in tag_list with NULL element", { tl <- tag_list( tags$p("a"), NULL, ) expect_length(tl, 1L) expect_equal(render(tl), "

a

") }) test_that("trailing comma with only NULL in tags$*()", { node <- tags$div( NULL, ) expect_equal(node$children, list()) expect_equal(render(node), "
") }) # -- trailing commas with raw_html ----------------------------------------- test_that("trailing comma after raw_html child", { node <- tags$div( raw_html("raw"), ) expect_equal(render(node), "
raw
") }) test_that("trailing comma in tag_list with raw_html", { tl <- tag_list( tags$p("text"), raw_html("
"), ) expect_equal(render(tl), "

text


") }) # -- trailing commas with boolean and special attributes -------------------- test_that("trailing comma after boolean attribute", { node <- tags$input( type = "checkbox", checked = TRUE, ) html <- render(node) expect_match(html, "checked") expect_match(html, 'type="checkbox"') }) test_that("trailing comma with FALSE and NULL attributes", { node <- tags$div( hidden = FALSE, data = NULL, ) expect_equal(render(node), "
") }) # -- trailing commas with numeric children ---------------------------------- test_that("trailing comma after numeric child", { node <- tags$span( 42, ) expect_equal(render(node), "42") }) test_that("trailing comma with mixed numeric and text", { node <- tags$p( "Score: ", 100, ) expect_equal(render(node), "

Score: 100

") }) # -- trailing commas in realistic page structure ---------------------------- test_that("realistic page with trailing commas throughout", { items <- c("Home", "About", "Contact") page <- tags$html( tags$head( tags$title("My Site"), tags$meta(charset = "utf-8", ), ), tags$body( tags$nav( class = "main-nav", tags$ul( lapply(items, function(item) { tags$li( tags$a(href = "#", item, ), ) }), ), ), tags$main( tags$h1("Welcome", ), tags$p("Hello world", ), ), ), ) html <- render(page) expect_match(html, "^") expect_match(html, "$") expect_match(html, "My Site") expect_match(html, '') expect_match(html, '