# -- raw_html construction ---------------------------------------------------- test_that("raw_html returns object with correct class", { r <- raw_html("bold") expect_s3_class(r, "hypertext.raw") }) test_that("raw_html preserves the input string", { r <- raw_html("hi") expect_equal(as.character(r), "hi") }) test_that("raw_html concatenates multiple arguments", { r <- raw_html("one", "two") expect_equal(as.character(r), "one two") }) test_that("raw_html with no arguments returns empty string", { r <- raw_html() expect_s3_class(r, "hypertext.raw") expect_equal(as.character(r), "") }) test_that("raw_html coerces non-character input via paste", { expect_equal(as.character(raw_html(42)), "42") expect_equal(as.character(raw_html(TRUE)), "TRUE") }) # -- render.hypertext.raw ---------------------------------------------------- test_that("render does not escape raw_html content", { r <- raw_html("") expect_equal(render(r), "") }) test_that("render preserves special characters in raw_html", { r <- raw_html('a < b & c > d "e" \'f\'') expect_equal(render(r), 'a < b & c > d "e" \'f\'') }) test_that("raw_html works as a child of a tag", { node <- tags$div(raw_html("raw")) expect_equal(render(node), "
raw
") }) test_that("raw_html mixes with text and tag children", { node <- tags$div( "before ", raw_html("raw"), " ", tags$strong("tag"), " after" ) expect_equal( render(node), "
before raw tag after
" ) }) test_that("raw_html works inside tag_list", { tl <- tag_list(raw_html("
"), tags$p("text")) expect_equal(render(tl), "

text

") }) test_that("raw_html renders inside a list", { nodes <- list(raw_html(""), tags$html()) expect_equal(render(nodes), "") }) # -- render with file output ------------------------------------------------- test_that("render writes raw_html to a file and returns invisibly", { tmp <- tempfile(fileext = ".html") on.exit(unlink(tmp), add = TRUE) r <- raw_html("
raw
") result <- withVisible(render(r, file = tmp)) expect_false(result$visible) expect_equal(result$value, "
raw
") expect_equal(readLines(tmp, warn = FALSE), "
raw
") }) test_that("render appends raw_html to a file", { tmp <- tempfile(fileext = ".html") on.exit(unlink(tmp), add = TRUE) render(raw_html("

first

"), file = tmp) render(raw_html("

second

"), file = tmp, write_mode = "append") expect_equal( readLines(tmp, warn = FALSE), "

first

second

" ) }) # -- print method ------------------------------------------------------------ test_that("print.hypertext.raw outputs rendered content", { r <- raw_html("bold") expect_output(print(r), "bold") })