swh:1:snp:bdc19e867479541d0f4994ceaa711217d0dc28ed
Tip revision: 74b598025322cd572dcd58326f0c5fb465f503ab authored by Hadley Wickham on 23 June 2022, 13:00:02 UTC
version 2.0.5
version 2.0.5
Tip revision: 74b5980
test-highlight.R
test_that("highlight_examples captures depencies", {
withr::defer(unlink(test_path("Rplot001.png")))
dummy_dep <- htmltools::htmlDependency("dummy", "1.0.0", "dummy.js")
widget <- htmlwidgets::createWidget("test", list(), dependencies = dummy_dep)
out <- highlight_examples("widget", env = environment())
# htmlwidgets always get dependency on htmlwidgets.js
expect_equal(attr(out, "dependencies")[-1], list(dummy_dep))
})
test_that("highlight_text & highlight_examples include sourceCode div", {
withr::defer(unlink(test_path("Rplot001.png")))
html <- xml2::read_html(highlight_examples("a + a", "x"))
expect_equal(xpath_attr(html, "./body/div", "class"), "sourceCode")
html <- xml2::read_html(highlight_text("a + a"))
expect_equal(xpath_attr(html, "./body/div", "class"), "sourceCode")
})
test_that("pre() can produce needed range of outputs", {
expect_snapshot({
cat(pre("x"))
cat(pre("x", r_code = TRUE))
})
})
test_that("tweak_highlight_other() renders generic code blocks for roxygen2 >= 7.2.0", {
div <- xml2::read_html('<div class="sourceCode"><pre><code>1+1\n</code></pre></div>') %>%
xml2::xml_find_first("//div")
tweak_highlight_other(div)
expect_equal(
xml2::xml_text(xml2::xml_find_first(div, "pre/code")),
"1+1"
)
})