diff options
Diffstat (limited to '')
-rw-r--r-- | tests/gfm_strikethrough.rs | 387 |
1 files changed, 387 insertions, 0 deletions
diff --git a/tests/gfm_strikethrough.rs b/tests/gfm_strikethrough.rs new file mode 100644 index 0000000..f39be07 --- /dev/null +++ b/tests/gfm_strikethrough.rs @@ -0,0 +1,387 @@ +extern crate micromark; +use micromark::{micromark, micromark_with_options, Constructs, Options}; +use pretty_assertions::assert_eq; + +#[test] +fn gfm_strikethrough() { + let gfm = Options { + constructs: Constructs::gfm(), + ..Options::default() + }; + + assert_eq!( + micromark("a ~b~ c"), + "<p>a ~b~ c</p>", + "should ignore strikethrough by default" + ); + + assert_eq!( + micromark_with_options("a ~b~", &gfm), + "<p>a <del>b</del></p>", + "should support strikethrough w/ one tilde" + ); + + assert_eq!( + micromark_with_options("a ~~b~~", &gfm), + "<p>a <del>b</del></p>", + "should support strikethrough w/ two tildes" + ); + + assert_eq!( + micromark_with_options("a ~~~b~~~", &gfm), + "<p>a ~~~b~~~</p>", + "should not support strikethrough w/ three tildes" + ); + + assert_eq!( + micromark_with_options("a \\~~~b~~ c", &gfm), + "<p>a ~<del>b</del> c</p>", + "should support strikethrough after an escaped tilde" + ); + + assert_eq!( + micromark_with_options("a ~~b ~~c~~ d~~ e", &gfm), + "<p>a <del>b <del>c</del> d</del> e</p>", + "should support nested strikethrough" + ); + + assert_eq!( + micromark_with_options("a ~-1~ b", &gfm), + "<p>a <del>-1</del> b</p>", + "should open if preceded by whitespace and followed by punctuation" + ); + + assert_eq!( + micromark_with_options("a ~b.~ c", &gfm), + "<p>a <del>b.</del> c</p>", + "should close if preceded by punctuation and followed by whitespace" + ); + + assert_eq!( + micromark_with_options("~b.~.", &gfm), + "<p><del>b.</del>.</p>", + "should close if preceded and followed by punctuation" + ); + + assert_eq!( + micromark_with_options( + r###" +# Balanced + +a ~one~ b + +a ~~two~~ b + +a ~~~three~~~ b + +a ~~~~four~~~~ b + +# Unbalanced + +a ~one/two~~ b + +a ~one/three~~~ b + +a ~one/four~~~~ b + +*** + +a ~~two/one~ b + +a ~~two/three~~~ b + +a ~~two/four~~~~ b + +*** + +a ~~~three/one~ b + +a ~~~three/two~~ b + +a ~~~three/four~~~~ b + +*** + +a ~~~~four/one~ b + +a ~~~~four/two~~ b + +a ~~~~four/three~~~ b + +## Multiple + +a ~one b one~ c one~ d + +a ~one b two~~ c one~ d + +a ~one b one~ c two~~ d + +a ~~two b two~~ c two~~ d + +a ~~two b one~ c two~~ d + +a ~~two b two~~ c one~ d +"###, + &gfm + ), + r###"<h1>Balanced</h1> +<p>a <del>one</del> b</p> +<p>a <del>two</del> b</p> +<p>a ~~~three~~~ b</p> +<p>a ~~~~four~~~~ b</p> +<h1>Unbalanced</h1> +<p>a ~one/two~~ b</p> +<p>a ~one/three~~~ b</p> +<p>a ~one/four~~~~ b</p> +<hr /> +<p>a ~~two/one~ b</p> +<p>a ~~two/three~~~ b</p> +<p>a ~~two/four~~~~ b</p> +<hr /> +<p>a ~~~three/one~ b</p> +<p>a ~~~three/two~~ b</p> +<p>a ~~~three/four~~~~ b</p> +<hr /> +<p>a ~~~~four/one~ b</p> +<p>a ~~~~four/two~~ b</p> +<p>a ~~~~four/three~~~ b</p> +<h2>Multiple</h2> +<p>a <del>one b one</del> c one~ d</p> +<p>a <del>one b two~~ c one</del> d</p> +<p>a <del>one b one</del> c two~~ d</p> +<p>a <del>two b two</del> c two~~ d</p> +<p>a <del>two b one~ c two</del> d</p> +<p>a <del>two b two</del> c one~ d</p> +"###, + "should handle balance like GitHub" + ); + + assert_eq!( + micromark_with_options( + r###" +# Flank + +a oneRight~ b oneRight~ c oneRight~ d + +a oneRight~ b oneRight~ c ~oneLeft d + +a oneRight~ b ~oneLeft c oneRight~ d + +a ~oneLeft b oneRight~ c oneRight~ d + +a ~oneLeft b oneRight~ c ~oneLeft d + +a ~oneLeft b ~oneLeft c oneRight~ d + +a ~oneLeft b ~oneLeft c ~oneLeft d + +*** + +a twoRight~~ b twoRight~~ c twoRight~~ d + +a twoRight~~ b twoRight~~ c ~~twoLeft d + +a twoRight~~ b ~~twoLeft c twoRight~~ d + +a ~~twoLeft b twoRight~~ c twoRight~~ d + +a ~~twoLeft b twoRight~~ c ~~twoLeft d + +a ~~twoLeft b ~~twoLeft c twoRight~~ d + +a ~~twoLeft b ~~twoLeft c ~~twoLeft d +"###, + &gfm + ), + r###"<h1>Flank</h1> +<p>a oneRight~ b oneRight~ c oneRight~ d</p> +<p>a oneRight~ b oneRight~ c ~oneLeft d</p> +<p>a oneRight~ b <del>oneLeft c oneRight</del> d</p> +<p>a <del>oneLeft b oneRight</del> c oneRight~ d</p> +<p>a <del>oneLeft b oneRight</del> c ~oneLeft d</p> +<p>a ~oneLeft b <del>oneLeft c oneRight</del> d</p> +<p>a ~oneLeft b ~oneLeft c ~oneLeft d</p> +<hr /> +<p>a twoRight~~ b twoRight~~ c twoRight~~ d</p> +<p>a twoRight~~ b twoRight~~ c ~~twoLeft d</p> +<p>a twoRight~~ b <del>twoLeft c twoRight</del> d</p> +<p>a <del>twoLeft b twoRight</del> c twoRight~~ d</p> +<p>a <del>twoLeft b twoRight</del> c ~~twoLeft d</p> +<p>a ~~twoLeft b <del>twoLeft c twoRight</del> d</p> +<p>a ~~twoLeft b ~~twoLeft c ~~twoLeft d</p> +"###, + "should handle flanking like GitHub" + ); + + assert_eq!( + micromark_with_options( + r###" +# Interlpay + +## Interleave with attention + +a ~~two *emphasis* two~~ b + +a ~~two **strong** two~~ b + +a *marker ~~two marker* two~~ b + +a ~~two *marker two~~ marker* b + +## Interleave with links + +a ~~two [resource](#) two~~ b + +a ~~two [reference][#] two~~ b + +a [label start ~~two label end](#) two~~ b + +a ~~two [label start two~~ label end](#) b + +a ~~two [label start ~one one~ label end](#) two~~ b + +a ~one [label start ~~two two~~ label end](#) one~ b + +a ~one [label start ~one one~ label end](#) one~ b + +a ~~two [label start ~~two two~~ label end](#) two~~ b + +[#]: # + +## Interleave with code (text) + +a ~~two `code` two~~ b + +a ~~two `code two~~` b + +a `code start ~~two code end` two~~ b + +a ~~two `code start two~~ code end` b + +a ~~two `code start ~one one~ code end` two~~ b + +a ~one `code start ~~two two~~ code end` one~ b + +a ~one `code start ~one one~ code end` one~ b + +a ~~two `code start ~~two two~~ code end` two~~ b + +## Emphasis/strong/strikethrough interplay + +a ***~~xxx~~*** zzz + +b ***xxx***zzz + +c **xxx**zzz + +d *xxx*zzz + +e ***~~xxx~~***yyy + +f **~~xxx~~**yyy + +g *~~xxx~~*yyy + +h ***~~xxx~~*** zzz + +i **~~xxx~~** zzz + +j *~~xxx~~* zzz + +k ~~~**xxx**~~~ zzz + +l ~~~xxx~~~zzz + +m ~~xxx~~zzz + +n ~xxx~zzz + +o ~~~**xxx**~~~yyy + +p ~~**xxx**~~yyy + +r ~**xxx**~yyy + +s ~~~**xxx**~~~ zzz + +t ~~**xxx**~~ zzz + +u ~**xxx**~ zzz +"###, + &gfm + ), + r###"<h1>Interlpay</h1> +<h2>Interleave with attention</h2> +<p>a <del>two <em>emphasis</em> two</del> b</p> +<p>a <del>two <strong>strong</strong> two</del> b</p> +<p>a <em>marker ~~two marker</em> two~~ b</p> +<p>a <del>two *marker two</del> marker* b</p> +<h2>Interleave with links</h2> +<p>a <del>two <a href="#">resource</a> two</del> b</p> +<p>a <del>two <a href="#">reference</a> two</del> b</p> +<p>a <a href="#">label start ~~two label end</a> two~~ b</p> +<p>a ~~two <a href="#">label start two~~ label end</a> b</p> +<p>a <del>two <a href="#">label start <del>one one</del> label end</a> two</del> b</p> +<p>a <del>one <a href="#">label start <del>two two</del> label end</a> one</del> b</p> +<p>a <del>one <a href="#">label start <del>one one</del> label end</a> one</del> b</p> +<p>a <del>two <a href="#">label start <del>two two</del> label end</a> two</del> b</p> +<h2>Interleave with code (text)</h2> +<p>a <del>two <code>code</code> two</del> b</p> +<p>a ~~two <code>code two~~</code> b</p> +<p>a <code>code start ~~two code end</code> two~~ b</p> +<p>a ~~two <code>code start two~~ code end</code> b</p> +<p>a <del>two <code>code start ~one one~ code end</code> two</del> b</p> +<p>a <del>one <code>code start ~~two two~~ code end</code> one</del> b</p> +<p>a <del>one <code>code start ~one one~ code end</code> one</del> b</p> +<p>a <del>two <code>code start ~~two two~~ code end</code> two</del> b</p> +<h2>Emphasis/strong/strikethrough interplay</h2> +<p>a <em><strong><del>xxx</del></strong></em> zzz</p> +<p>b <em><strong>xxx</strong></em>zzz</p> +<p>c <strong>xxx</strong>zzz</p> +<p>d <em>xxx</em>zzz</p> +<p>e <em><strong><del>xxx</del></strong></em>yyy</p> +<p>f <strong><del>xxx</del></strong>yyy</p> +<p>g <em><del>xxx</del></em>yyy</p> +<p>h <em><strong><del>xxx</del></strong></em> zzz</p> +<p>i <strong><del>xxx</del></strong> zzz</p> +<p>j <em><del>xxx</del></em> zzz</p> +<p>k ~~~<strong>xxx</strong>~~~ zzz</p> +<p>l ~~~xxx~~~zzz</p> +<p>m <del>xxx</del>zzz</p> +<p>n <del>xxx</del>zzz</p> +<p>o ~~~<strong>xxx</strong>~~~yyy</p> +<p>p ~~<strong>xxx</strong>~~yyy</p> +<p>r ~<strong>xxx</strong>~yyy</p> +<p>s ~~~<strong>xxx</strong>~~~ zzz</p> +<p>t <del><strong>xxx</strong></del> zzz</p> +<p>u <del><strong>xxx</strong></del> zzz</p> +"###, + "should handle interplay like GitHub" + ); + + assert_eq!( + micromark_with_options( + "a ~b~ ~~c~~ d", + &Options { + constructs: Constructs::gfm(), + gfm_strikethrough_single_tilde: false, + ..Options::default() + } + ), + "<p>a ~b~ <del>c</del> d</p>", + "should not support strikethrough w/ one tilde if `singleTilde: false`" + ); + + assert_eq!( + micromark_with_options( + "a ~b~ ~~c~~ d", + &Options { + constructs: Constructs::gfm(), + gfm_strikethrough_single_tilde: true, + ..Options::default() + } + ), + "<p>a <del>b</del> <del>c</del> d</p>", + "should support strikethrough w/ one tilde if `singleTilde: true`" + ); +} |