use super::*; use ntest::test_case; #[test_case("$2+2$", "

2+2

\n")] #[test_case( "$\\alpha$$\\beta$", "

\\alpha\\beta

\n" )] #[test_case("$2+2$$2+2$", "

2+22+2

\n")] #[test_case("$22 and $2+2$", "

$22 and 2+2

\n")] #[test_case("$a!$", "

a!

\n")] #[test_case("$x$", "

x

\n")] #[test_case("$1+2\\$$", "

1+2\\$

\n")] #[test_case("$1+\\$2$", "

1+\\$2

\n")] #[test_case("$1+\\%2$", "

1+\\%2

\n")] #[test_case( "$22+1$ and $22 + a^2$", "

22+1 and 22 + a^2

\n" )] #[test_case( "$2+2$ $22 and dollars$22 $2+2$", "

2+2 $22 and dollars$22 2+2

\n" )] #[test_case( "$1/2$ <b>test</b>", "

1/2 <b>test</b>

\n" )] fn math_dollars_inline(markdown: &str, html: &str) { let result = html .replace("", "") .replace("", ""); html_opts!([extension.math_dollars], markdown, &result); } #[test_case("$$2+2$$", "

2+2

\n")] #[test_case("$$ 2+2 $$", "

2+2

\n")] #[test_case("$22 and $$2+2$$", "

$22 and 2+2

\n")] #[test_case("$$a!$$", "

a!

\n")] #[test_case("$$x$$", "

x

\n")] #[test_case("$$20,000 and $$30,000", "

20,000 and 30,000

\n")] #[test_case("test $$\n2+2\n$$", "

test \n2+2\n

\n")] #[test_case( "$$22+1$$ and $$22 + a^2$$", "

22+1 and 22 + a^2

\n" )] #[test_case( "$$2+2$$ $22 and dollars$22 $$2+2$$", "

2+2 $22 and dollars$22 2+2

\n" )] #[test_case( "dollars$22 and $$a^2 + b^2 = c^2$$", "

dollars$22 and a^2 + b^2 = c^2

\n" )] fn math_dollars_inline_display(markdown: &str, html: &str) { let result = html .replace("", "") .replace("", ""); html_opts!([extension.math_dollars], markdown, &result); } #[test_case("$$\n2+2\n4+4\n$$", "

\n2+2\n4+4\n

\n")] fn math_dollars_block(markdown: &str, html: &str) { let result = html .replace("", "") .replace("", ""); html_opts!([extension.math_dollars], markdown, &result); } #[test_case("\\(2+2\\)", "

2+2

\n")] #[test_case( "Calc \\(x^2\\) and \\(y^2\\)", "

Calc x^2 and y^2

\n" )] #[test_case("\\(\\alpha + \\beta\\)", "

\\alpha + \\beta

\n")] fn math_latex_inline(markdown: &str, html: &str) { let result = html .replace("", "") .replace("", ""); html_opts!([extension.math_latex], markdown, &result); } #[test_case("\\[2+2\\]", "

2+2

\n")] #[test_case("\\[\n2+2\n\\]", "

\n2+2\n

\n")] fn math_latex_display(markdown: &str, html: &str) { let result = html .replace("", "") .replace("", ""); html_opts!([extension.math_latex], markdown, &result); } #[test_case("`\\(2+2\\)`", "

\\(2+2\\)

\n")] #[test_case( "```text\n\\[2+2\\]\n```", "
\\[2+2\\]\n
\n" )] #[test_case("\\(2+2", "

(2+2

\n")] #[test_case("\\[2+2", "

[2+2

\n")] #[test_case("\\(x\\]", "

(x]

\n")] #[test_case("\\[x\\)", "

[x)

\n")] #[test_case("\\(\\)", "

()

\n")] #[test_case("\\[\\]", "

[]

\n")] fn math_latex_unrecognized_syntax(markdown: &str, html: &str) { html_opts!([extension.math_latex], markdown, html); } #[test_case("$`2+2`$", "

2+2

\n")] #[test_case("$22 and $`2+2`$", "

$22 and 2+2

\n")] #[test_case("$`1+\\$2`$", "

1+\\$2

\n")] #[test_case( "$`22+1`$ and $`22 + a^2`$", "

22+1 and 22 + a^2

\n" )] #[test_case( "$`2+2`$ $22 and dollars$22 $`2+2`$", "

2+2 $22 and dollars$22 2+2

\n" )] fn math_code_inline(markdown: &str, html: &str) { let result = html .replace("", "") .replace("", ""); html_opts!([extension.math_code], markdown, &result); } #[test_case("```math\n2+2\n4+4\n```", "
2+2\n4+4\n
\n")] fn math_code_block(markdown: &str, html: &str) { let result = html .replace( "", "", ) .replace("", ""); html_opts!([extension.math_dollars], markdown, &result); } #[test_case("`2+2`", "

2+2

\n")] #[test_case("test `2+2`$ test", "

test 2+2$ test

\n")] #[test_case("$20,000 and $30,000", "

$20,000 and $30,000

\n")] #[test_case("$20,000 in $USD", "

$20,000 in $USD

\n")] #[test_case("$ a^2 $", "

$ a^2 $

\n")] #[test_case("$\n$", "

$\n$

\n")] #[test_case("$$$", "

$$$

\n")] #[test_case("`$1+2$`", "

$1+2$

\n")] #[test_case("`$$1+2$$`", "

$$1+2$$

\n")] #[test_case("`$\\$1+2$$`", "

$\\$1+2$$

\n")] #[test_case("test $`2+2` test", "

test $2+2 test

\n")] fn math_unrecognized_syntax(markdown: &str, html: &str) { html_opts!( [extension.math_dollars, extension.math_code], markdown, html ); } #[test_case("$`$", "

$`$

\n")] fn math_unrecognized_syntax_non_roundtrip(markdown: &str, html: &str) { html_opts!( [ extension.math_dollars, extension.math_code, render.sourcepos ], markdown, html, no_roundtrip ); } #[test] fn sourcepos() { assert_ast_match!( [extension.math_dollars, extension.math_code], "$x^2$ and $$y^2$$ and $`z^2`$\n" "\n" "$$\n" "a^2\n" "$$\n" "\n" "```math\n" "b^2\n" "```\n", (document (1:1-9:3) [ (paragraph (1:1-1:29) [ (math (1:1-1:5) "x^2") (text (1:6-1:10) " and ") (math (1:11-1:17) "y^2") (text (1:18-1:22) " and ") (math (1:23-1:29) "z^2") ]) (paragraph (3:1-5:2) [ (math (3:1-5:2) "\na^2\n") ]) (code_block (7:1-9:3) info:"math" "b^2\n") ]) ); } #[test] fn math_latex_sourcepos() { assert_ast_match!( [extension.math_latex], "\\(x^2\\) and \\[y^2\\]\n" "\n" "\\[\n" "a^2\n" "\\]\n", (document (1:1-5:2) [ (paragraph (1:1-1:19) [ (math (1:1-1:7) "x^2") (text (1:8-1:12) " and ") (math (1:13-1:19) "y^2") ]) (paragraph (3:1-5:2) [ (math (3:1-5:2) "\na^2\n") ]) ]) ); }