From 7d8cce920e74dfe5a24f52fb738035ff7a0390cc Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Wed, 15 Jun 2022 12:05:36 +0200 Subject: Add tests for character escape --- tests/character_escape.rs | 91 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 tests/character_escape.rs (limited to 'tests/character_escape.rs') diff --git a/tests/character_escape.rs b/tests/character_escape.rs new file mode 100644 index 0000000..5fdc445 --- /dev/null +++ b/tests/character_escape.rs @@ -0,0 +1,91 @@ +extern crate micromark; +use micromark::{micromark, micromark_with_options, CompileOptions}; + +const DANGER: &CompileOptions = &CompileOptions { + allow_dangerous_html: true, + allow_dangerous_protocol: true, +}; + +#[test] +fn character_escape() { + assert_eq!( + micromark( + "\\!\\\"\\#\\$\\%\\&\\'\\(\\)\\*\\+\\,\\-\\.\\/\\:\\;\\<\\=\\>\\?\\@\\[\\\\\\]\\^\\_\\`\\{\\|\\}\\~" + ), + "

!"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~

", + "should support escaped ascii punctuation" + ); + + assert_eq!( + micromark("\\→\\A\\a\\ \\3\\φ\\«"), + "

\\→\\A\\a\\ \\3\\φ\\«

", + "should not support other characters after a backslash" + ); + + assert_eq!( + micromark( + "\\*not emphasized*\n\\
not a tag\n\\[not a link](/foo)\n\\`not code`\n1\\. not a list\n\\* not a list\n\\# not a heading\n\\[foo]: /url \"not a reference\"\n\\ö not a character entity" + ), + "

*not emphasized*\n<br/> not a tag\n[not a link](/foo)\n`not code`\n1. not a list\n* not a list\n# not a heading\n[foo]: /url "not a reference"\n&ouml; not a character entity

", + "should escape other constructs" + ); + + // To do: hard break. + // assert_eq!( + // micromark("foo\\\nbar"), + // "

foo
\nbar

", + // "should escape a line break" + // ); + + // To do: code (text). + // assert_eq!( + // micromark("`` \\[\\` ``"), + // "

\\[\\`

", + // "should not escape in text code" + // ); + + assert_eq!( + micromark(" \\[\\]"), + "
\\[\\]\n
", + "should not escape in indented code" + ); + + assert_eq!( + micromark(""), + "

http://example.com?find=\\*

", + "should not escape in autolink" + ); + + assert_eq!( + micromark_with_options("", DANGER), + "", + "should not escape in flow html" + ); + + // To do: link (reference). + // assert_eq!( + // micromark("[foo](/bar\\* \"ti\\*tle\")"), + // "

foo

", + // "should escape in resource and title" + // ); + + // To do: definition. + // assert_eq!( + // micromark("[foo]: /bar\\* \"ti\\*tle\"\n\n[foo]"), + // "

foo

", + // "should escape in definition resource and title" + // ); + + assert_eq!( + micromark("``` foo\\+bar\nfoo\n```"), + "
foo\n
", + "should escape in fenced code info" + ); + + // // To do: extensions + // assert_eq!( + // micromark("\\> a", {extensions: [{disable: {null: ["characterEscape"]}}]}), + // "

\\> a

", + // "should support turning off character escapes" + // ); +} -- cgit