swh:1:snp:bdc19e867479541d0f4994ceaa711217d0dc28ed
Tip revision: 1ad2332a4119217014f512bdf05025fa6f2bb72f authored by Hadley Wickham on 09 April 2020, 13:00:02 UTC
version 1.5.1
version 1.5.1
Tip revision: 1ad2332
test-rd-example.R
# run_examples() -----------------------------------------------------------
test_that("warns if unparseable", {
expect_warning(
run_examples("1 + \\dontrun{2 + }"),
"Failed to parse"
)
})
# as_example() ------------------------------------------------------------
test_that("inline tags are stripped", {
expect_equal(rd2ex("\\donttest{1}"), "1")
expect_equal(rd2ex("\\dontshow{1}"), "1")
expect_equal(rd2ex("\\testonly{1}"), "1")
expect_equal(rd2ex("\\dontrun{1}"), "if (FALSE) 1")
expect_equal(rd2ex("\\dontrun{1}", run_dont_run = TRUE), "1")
})
test_that("blocks get fillers to preserve spacine", {
expect_equal(rd2ex("\\donttest{\n 1\n}"), c("# \\donttest{", " 1", "# }"))
expect_equal(rd2ex("\\dontrun{\n 1\n}"), c("if (FALSE) {", " 1", "}"))
})
test_that("handles nested tags", {
expect_equal(
rd2ex("if(TRUE {\n \\dontrun{\n 1 + 2\n }\n}"),
c(
"if(TRUE {",
" if (FALSE) {",
" 1 + 2",
" }",
"}"
)
)
})
test_that("translate dots and ldots to ...", {
expect_equal(rd2ex("\\ldots"), "...")
expect_equal(rd2ex("\\dots"), "...")
})
test_that("ignores out", {
expect_equal(rd2ex("\\out{1 + 2}"), "1 + 2")
})
test_that("extracts conditions from if", {
expect_equal(rd2ex("\\if{html}{1 + 2}"), "1 + 2")
expect_equal(rd2ex("\\if{latex}{1 + 2}"), "")
expect_equal(rd2ex("\\ifelse{html}{1 + 2}{3 + 4}"), "1 + 2")
expect_equal(rd2ex("\\ifelse{latex}{1 + 2}{3 + 4}"), "3 + 4")
})