deep
", "# -- 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
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), "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
inner
inner
deep
", "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
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( "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
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( "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), "text
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, "