test_that("check_installed() works", { # returns NULL invisibly if installed local_mocked_bindings(is_installed = function(x) TRUE) expect_invisible(check_installed("somepackage")) expect_null(check_installed("somepackage")) skip_if_not_snapshot_env() # informative error if not installed local_mocked_bindings( is_installed = function(x) FALSE, find_package_candidates = function(...) { c("doudpackage", "datapackage", "findPackage", "FSTpackage", "somspace") } ) expect_snapshot(check_installed("somepackage"), error = TRUE) }) test_that("check_inherits() works", { expect_null(check_inherits("true", "character")) expect_null(check_inherits(as_btw_capture("foo"), "btw_captured")) expect_error(check_inherits(as_btw_docs_package("btw"), "not_this_class")) }) # Tests for remove_base64_images() ----------------------------------------- describe("remove_base64_images()", { it("removes base64 images with alt text", { html <- '
'
result <- remove_base64_images(html)
expect_true(grepl("https://example.com/image.png", result))
expect_false(grepl("\\[Image", result))
})
it("handles multiple images", {
html <- paste0(
'',
'
',
'Just text, no images
' result <- remove_base64_images(html) expect_type(result, "character") expect_true(grepl("Just text, no images", result)) }) it("handles empty alt attributes", { html <- 'Paragraph text
") result <- pandoc_html_simplify(html) expect_type(result, "character") expect_true(any(grepl("# Title", result))) expect_true(any(grepl("Paragraph text", result))) }) it("removes base64 images", { html <- c( "Text after image
" ) result <- pandoc_html_simplify(html) expect_false(any(grepl("data:image", result))) # Pandoc escapes brackets in markdown, so check for the content expect_true(any(grepl("Image", result))) expect_true(any(grepl("chart", result))) }) it("preserves regular images", { html <- c( "
'
)
result <- pandoc_html_simplify(html)
# Regular images might be converted to markdown image syntax
expect_true(any(grepl("example.com/photo.jpg", result)))
})
it("handles tables", {
html <- c(
"| Col1 | Col2 |
|---|---|
| A | B |