# -- render.hypertext.tag --------------------------------------------------- test_that("render produces correct HTML for simple element", { node <- tags$div("hello") expect_equal(render(node), "
hello
") }) test_that("render produces correct HTML for element with attributes", { node <- tags$p(class = "lead", "text") expect_equal(render(node), '

text

') }) test_that("render handles empty element", { node <- tags$div() expect_equal(render(node), "
") }) test_that("render handles void elements as self-closing", { node <- tags$br() expect_equal(render(node), "
") }) test_that("render handles void element with attributes", { node <- tags$input(type = "text", name = "user") expect_equal(render(node), '') }) test_that("render handles nested elements", { node <- tags$div(tags$p("inner")) expect_equal(render(node), "

inner

") }) test_that("render handles deeply nested elements", { node <- tags$div(tags$ul(tags$li("item"))) expect_equal(render(node), "
") }) test_that("render handles multiple children", { node <- tags$div(tags$p("first"), tags$p("second")) expect_equal(render(node), "

first

second

") }) test_that("render handles mixed text and tag children", { node <- tags$p("Hello ", tags$strong("world"), "!") expect_equal(render(node), "

Hello world!

") }) test_that("render escapes text children", { node <- tags$p("") expect_equal( render(node), "

<script>alert('xss')</script>

" ) }) test_that("render escapes attribute values", { node <- tags$div(title = 'say "hi"') expect_equal(render(node), '
') }) test_that("render handles boolean attributes", { node <- tags$input(type = "checkbox", checked = TRUE) expect_equal(render(node), '') }) test_that("render handles NA as boolean attribute", { node <- tags$input(disabled = NA) expect_equal(render(node), "") }) test_that("render drops FALSE attributes", { node <- tags$input(type = "text", disabled = FALSE) expect_equal(render(node), '') }) test_that("render drops NULL attributes", { node <- tags$div(id = "x", class = NULL) expect_equal(render(node), '
') }) test_that("render collapses multi-value class attribute", { node <- tags$div(class = c("a", "b", "c")) expect_equal(render(node), '
') }) # -- render.default -------------------------------------------------------- test_that("render.default escapes text", { expect_equal(render("aa

b

") }) test_that("render.list handles mixed tags and text", { nodes <- list("hello ", tags$strong("world")) expect_equal(render(nodes), "hello world") }) test_that("render.list handles empty list", { expect_equal(render(list()), "") }) test_that("render.list handles single element", { nodes <- list(tags$div("one")) expect_equal(render(nodes), "
one
") })