From 022306c7985186b6b2346d45d87cf4dc9db579f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Thu, 3 Oct 2024 14:51:21 +0200 Subject: [PATCH] test: add test for `markdown_text()`'s handling of ANSI characters --- tests/testthat/_snaps/markdown.md | 9 +++++++++ tests/testthat/test-markdown.R | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/tests/testthat/_snaps/markdown.md b/tests/testthat/_snaps/markdown.md index c373c1bb0..bb0f83f14 100644 --- a/tests/testthat/_snaps/markdown.md +++ b/tests/testthat/_snaps/markdown.md @@ -19,3 +19,12 @@ Error in `config_math_rendering_()`: ! In _pkgdown.yml, template.math-rendering must be one of mathml, mathjax, and katex, not math. +# preserves ANSI characters + + Code + markdown_text(pkg, sprintf("prefer %s", cli::col_blue("a"))) + Output + {html_document} + + [1]

prefer \u2029[34ma\u2029[39m

+ diff --git a/tests/testthat/test-markdown.R b/tests/testthat/test-markdown.R index 224df1536..46d81f1ed 100644 --- a/tests/testthat/test-markdown.R +++ b/tests/testthat/test-markdown.R @@ -63,3 +63,11 @@ test_that("validates math yaml", { config_math_rendering_(`math-rendering` = "math") }) }) + +test_that("preserves ANSI characters", { + withr::local_options(cli.num_colors = 256) + pkg <- local_pkgdown_site() + expect_snapshot( + markdown_text(pkg, sprintf("prefer %s", cli::col_blue("a"))) + ) +})