| 1 |
test_that("check_math_argument()", { |
| 2 |
# valid value |
| 3 |
expect_null(check_math_argument(NULL)) |
| 4 |
expect_identical(check_math_argument("katex"), list(engine = "katex", url = NULL)) |
| 5 |
expect_identical(check_math_argument(list("katex")), list(engine = "katex", url = NULL)) |
| 6 |
expect_identical(check_math_argument(list(engine = "katex")), list(engine = "katex", url = NULL)) |
| 7 |
expect_identical(check_math_argument(list(engine = "katex", url = "CDN")), list(engine = "katex", url = "CDN")) |
| 8 |
# invalid value |
| 9 |
expect_error(check_math_argument(list(wrong = "katex")), "'math' can be the") # wrong name |
| 10 |
expect_error(check_math_argument(FALSE), "'math' can be the") # logical |
| 11 |
expect_error(check_math_argument(TRUE), "'math' can be the") |
| 12 |
expect_error(check_math_argument(list(engine = FALSE)), "'math' can be the") |
| 13 |
}) |
| 14 |
|
| 15 |
test_that("mathjax_to_math() brings backward compatibility", { |
| 16 |
expect_null(mathjax_to_math(NULL, "default")) |
| 17 |
expect_null(mathjax_to_math(FALSE, "default")) |
| 18 |
expect_identical(mathjax_to_math(TRUE, "katex"), "katex") |
| 19 |
expect_identical(mathjax_to_math("default", "webtex"), "webtex") |
| 20 |
expect_identical(mathjax_to_math("local", "webtex"), list(engine = "mathjax", url = "local")) |
| 21 |
expect_identical(mathjax_to_math("CDN", "webtex"), list(engine = "mathjax", url = "CDN")) |
| 22 |
}) |
| 23 |
|
| 24 |
test_that("add_math_support() builds correct Pandoc arguments", { |
| 25 |
test_add_math_support <- function(math, template = NULL, files_dir = NULL, output_dir = NULL) { |
| 26 |
add_math_support(math, template, files_dir, output_dir) |
| 27 |
} |
| 28 |
expect_null(test_add_math_support(math = NULL)) |
| 29 |
expect_identical( |
| 30 |
test_add_math_support(list(engine = "default")), |
| 31 |
test_add_math_support(list(engine = "mathjax")) |
| 32 |
) |
| 33 |
expect_error(test_add_math_support(list(engine = "dummy")), "`math_method='dummy'`") |
| 34 |
|
| 35 |
expect_identical( |
| 36 |
test_add_math_support(list(engine = "gladtex")), |
| 37 |
list(args = pandoc_math_args("gladtex")) |
| 38 |
) |
| 39 |
|
| 40 |
expect_identical( |
| 41 |
test_add_math_support(list(engine = "mathjax"), template = "default"), |
| 42 |
list( |
| 43 |
args = c(pandoc_math_args("mathjax"), pandoc_variable_arg("mathjax-url", default_mathjax())), |
| 44 |
extra_dependencies = NULL |
| 45 |
) |
| 46 |
) |
| 47 |
expect_identical( |
| 48 |
test_add_math_support(list(engine = "katex"), template = "default"), |
| 49 |
list( |
| 50 |
args = pandoc_math_args("katex"), |
| 51 |
extra_dependencies = list(html_dependency_katex()) |
| 52 |
) |
| 53 |
) |
| 54 |
}) |
| 55 |
|
| 56 |
test_that("html_dependency_katex() supports custom url", { |
| 57 |
expect_identical(html_dependency_katex("cdn/[email protected]")$version, "2.1.2") |
| 58 |
expect_identical(html_dependency_katex("cdn/[email protected]")$src$href, "cdn/[email protected]") |
| 59 |
expect_identical(html_dependency_katex("cdn/katex")$version, "99.99.99") |
| 60 |
expect_identical(html_dependency_katex("cdn/katex")$src$href, "cdn/katex") |
| 61 |
}) |
| 62 |
|
| 63 |
test_that("Local mathjax does not work with self_contained", { |
| 64 |
expect_error(validate_self_contained(list(engine = "mathjax", url = "local")), |
| 65 |
"isn't compatible") |
| 66 |
}) |