From a4935731210d93a7142d5288287a5afe27353119 Mon Sep 17 00:00:00 2001 From: Max Guppy Date: Wed, 5 Jul 2023 11:14:42 +1000 Subject: [PATCH] Add snapshot tests for classed highlighting --- components/markdown/tests/codeblocks.rs | 95 ++++++++++++++----- ...ks__can_add_line_numbers_with_classes.snap | 10 ++ ...odeblocks__can_highlight_with_classes.snap | 10 ++ 3 files changed, 91 insertions(+), 24 deletions(-) create mode 100644 components/markdown/tests/snapshots/codeblocks__can_add_line_numbers_with_classes.snap create mode 100644 components/markdown/tests/snapshots/codeblocks__can_highlight_with_classes.snap diff --git a/components/markdown/tests/codeblocks.rs b/components/markdown/tests/codeblocks.rs index 4b27d29663..baaeb3a31c 100644 --- a/components/markdown/tests/codeblocks.rs +++ b/components/markdown/tests/codeblocks.rs @@ -2,9 +2,24 @@ use config::Config; mod common; -fn render_codeblock(content: &str, highlight_code: bool) -> String { +enum HighlightMode { + None, + Inlined, + Classed, +} + +fn render_codeblock(content: &str, highlight_mode: HighlightMode) -> String { let mut config = Config::default_for_test(); - config.markdown.highlight_code = highlight_code; + match highlight_mode { + HighlightMode::None => {} + HighlightMode::Inlined => { + config.markdown.highlight_code = true; + } + HighlightMode::Classed => { + config.markdown.highlight_code = true; + config.markdown.highlight_theme = "css".to_owned(); + } + } common::render_with_config(content, config).unwrap().body } @@ -17,7 +32,7 @@ foo bar ``` "#, - false, + HighlightMode::None, ); insta::assert_snapshot!(body); } @@ -33,7 +48,7 @@ baz bat ``` "#, - true, + HighlightMode::Inlined, ); insta::assert_snapshot!(body); } @@ -49,7 +64,7 @@ bar baz ``` "#, - true, + HighlightMode::Inlined, ); insta::assert_snapshot!(body); } @@ -65,7 +80,7 @@ bar baz ``` "#, - true, + HighlightMode::Inlined, ); insta::assert_snapshot!(body); } @@ -81,7 +96,7 @@ bar baz ``` "#, - true, + HighlightMode::Inlined, ); insta::assert_snapshot!(body); } @@ -97,7 +112,7 @@ bar baz ``` "#, - true, + HighlightMode::Inlined, ); let body2 = render_codeblock( r#" @@ -108,7 +123,7 @@ bar baz ``` "#, - true, + HighlightMode::Inlined, ); assert_eq!(body, body2); } @@ -124,7 +139,7 @@ bar baz ``` "#, - true, + HighlightMode::Inlined, ); insta::assert_snapshot!(body); } @@ -140,7 +155,7 @@ bar baz ``` "#, - true, + HighlightMode::Inlined, ); insta::assert_snapshot!(body); } @@ -156,7 +171,7 @@ bar baz ``` "#, - true, + HighlightMode::Inlined, ); insta::assert_snapshot!(body); } @@ -172,7 +187,7 @@ bar baz ``` "#, - true, + HighlightMode::Inlined, ); insta::assert_snapshot!(body); } @@ -188,7 +203,7 @@ bar baz ``` "#, - true, + HighlightMode::Inlined, ); insta::assert_snapshot!(body); } @@ -204,7 +219,7 @@ bar baz ``` "#, - true, + HighlightMode::Inlined, ); insta::assert_snapshot!(body); } @@ -220,7 +235,23 @@ bar baz ``` "#, - true, + HighlightMode::Inlined, + ); + insta::assert_snapshot!(body); +} + +#[test] +fn can_highlight_with_classes() { + let body = render_codeblock( + r#" +```html,hl_lines=3-4 +
+With a line break in the middle of the tag +
+``` + "#, + HighlightMode::Classed, ); insta::assert_snapshot!(body); } @@ -234,14 +265,14 @@ foo bar ``` "#, - true, + HighlightMode::Inlined, ); insta::assert_snapshot!(body); } #[test] fn can_add_line_numbers_windows_eol() { - let body = render_codeblock("```linenos\r\nfoo\r\nbar\r\n```\r\n", true); + let body = render_codeblock("```linenos\r\nfoo\r\nbar\r\n```\r\n", HighlightMode::Inlined); insta::assert_snapshot!(body); } @@ -254,7 +285,7 @@ foo bar ``` "#, - true, + HighlightMode::Inlined, ); insta::assert_snapshot!(body); } @@ -268,7 +299,23 @@ foo bar ``` "#, - true, + HighlightMode::Inlined, + ); + insta::assert_snapshot!(body); +} + +#[test] +fn can_add_line_numbers_with_classes() { + let body = render_codeblock( + r#" +```html,linenos +
+With a line break in the middle of the tag +
+``` + "#, + HighlightMode::Classed, ); insta::assert_snapshot!(body); } @@ -283,7 +330,7 @@ fn can_render_shortcode_in_codeblock() { ``` "#, - true, + HighlightMode::Inlined, ); insta::assert_snapshot!(body); } @@ -300,7 +347,7 @@ text2 text3 ``` "#, - true, + HighlightMode::Inlined, ); insta::assert_snapshot!(body); } @@ -323,7 +370,7 @@ A quote ``` "#, - true, + HighlightMode::Inlined, ); insta::assert_snapshot!(body); } @@ -337,7 +384,7 @@ foo bar ``` "#, - true, + HighlightMode::Inlined, ); insta::assert_snapshot!(body); } diff --git a/components/markdown/tests/snapshots/codeblocks__can_add_line_numbers_with_classes.snap b/components/markdown/tests/snapshots/codeblocks__can_add_line_numbers_with_classes.snap new file mode 100644 index 0000000000..a463888415 --- /dev/null +++ b/components/markdown/tests/snapshots/codeblocks__can_add_line_numbers_with_classes.snap @@ -0,0 +1,10 @@ +--- +source: components/markdown/tests/codeblocks.rs +expression: body +--- +
1<div id="custom-attr"> +
2<a href="javascript:void(0);" +
3>With a line break in the middle of the tag</a> +
4</div> +
+ diff --git a/components/markdown/tests/snapshots/codeblocks__can_highlight_with_classes.snap b/components/markdown/tests/snapshots/codeblocks__can_highlight_with_classes.snap new file mode 100644 index 0000000000..7b269ae2db --- /dev/null +++ b/components/markdown/tests/snapshots/codeblocks__can_highlight_with_classes.snap @@ -0,0 +1,10 @@ +--- +source: components/markdown/tests/codeblocks.rs +expression: body +--- +
<div id="custom-attr">
+<a href="javascript:void(0);"
+>With a line break in the middle of the tag</a>
+</div>
+
+