//! These tests were ported from the original python-textile library. use pretty_assertions::assert_str_eq; const HTML_RESTRICTED_MODE_VALUES: [(&str, &str); 2] = [ // Ensure that there's no double-escaping of links while in the restricted mode (concat!("\"test\":link1\n", "[link1]http://example.com/\n"), "

test

"), ("!http://example.com/.png!\n", "

\"\"

"), ]; fn normalize_newlines(text: &str) -> String { text.trim().replace('\t', "").lines().map(|l| l.trim()).collect() } const HTML_KNOWN_VALUES: [(&str, &str); 52] = [ // ("*Colors*\n* Red\n* Green\n* Blue", // "

Colors

"), // Closely packed links ("[\"1\":https://example.tld][\"2\":https://example.tld][\"3\":https://example.tld]", "

123

"), // Multi-line HTML insert ("
\n\nSoy un *super* robot.\n\n
", "
\n\n

Soy un super robot.

\n\n
"), // Textile within an HTML span ("\"link\":http://example.com", "

link

"), // Textile within a divider block ("
", "
"), // Double quote in links ("\"\"The use of the character \"\"\" in textile\"\":help.html..!", "

“The use of the character “"” in textile”..!

"), // A link with an array in square braces ("^[\"same\":https://github.com/netcarver/?lang=en&q[]]^", "

same

"), // Double escaping within blockquotes ("bq.. Don't suck the **brown stuff(tm)** off of \"2 pence\":http://royalmint.gov.uk coins; it ain't chocolate.\n\np. That's all.", "
\n\t

Don’t suck the brown stuff™ off of 2 pence coins; it ain’t chocolate.

\n
\n\n

That’s all.

"), // HR tags ("
\n\n
\n", "
\n\n
"), // FTP Link aliases ("\"link with ftp alias\":uri-alias\n\n[uri-alias]ftp://foo@bar.net", "

link with ftp alias

"), // Notes with IDs (concat!("Notes can[#test] have ids.\n\n", "note#test(#noteid). \"Proof\":https://example.com/page is here\n\n", "notelist:1.\n"), concat!("

Notes can1 have ids.

\n\n", "
    \n", "\t
  1. 1 Proof is here
  2. \n", "
")), // Using $-links coupled with link aliases ("\"$\":0\n[0]https://textpattern.com/start\n", "

textpattern.com/start

"), // Proper HTML escaping for URLs ("!http://example.com/.png!\n", "

\"\"

"), (concat!("\"test\":link1\n", "[link1]http://example.com/\n"), "

test

"), // Proper HTML encoding within pre and code tags ("
sdada Link @\"code\"@ dadsada
", "
sdada <a href="link">Link</a> \"code\" dadsada
"), // Definition list with a paragraph (concat!("|-(cold) milk :=\n", "Nourishing beverage for baby cows. =:\n", "|"), concat!("\t\n", "\t\t\n", "\t\t\t\n", "\t\t\n\t
\n", "\t
milk
\n", "\t

Nourishing beverage for baby cows.

\n", "
")), // Nested lists of mixed types (concat!("* bullet\n", "*# number\n", "*# number\n", "*#* bullet\n", "*# number\n", "*# number with\n", "a break\n", "* bullet\n", "** okay\n"), concat!("\t")), ("\"a link\":http://example.com/?param1=1¶m2=2", "

a link

"), (concat!("*W skład zestawu wchodzą*:\n\n", "*W skład zestawu wchodzą*: "), concat!("

W skład zestawu wchodzą:

\n\n", "

W skład zestawu wchodzą:

")), // Non-standalone ampersands should not be escaped (concat!("“test”\n\n", "“test”\n\n", " test \n"), concat!("

test

\n\n", "

test

\n\n", "

 test 

")), // A standalone comment block should be left untouched ("An ordinary block\n\n", "

An ordinary block

\n\n"), ("I am crazy about \"Hobix\":hobix\nand \"it\'s\":hobix \"all\":hobix I ever\n\"link to\":hobix!\n\n[hobix]http://hobix.com", concat!("

I am crazy about Hobix
\nand it’s ", "all I ever
\nlink to!

")), ("a -b\na- b\n", "

a -b
\na- b

"), ("bc.. Paragraph 1\n\nParagraph 2\n\nParagraph 3\n", "
Paragraph 1\n\nParagraph 2\n\nParagraph 3
"), ("I spoke.\nAnd none replied.", "

I spoke.
\nAnd none replied.

"), ("I __know__.\nI **really** __know__.", "

I know.
\nI really know.

"), ("I\'m %{color:red}unaware%\nof most soft drinks.", "

I’m unaware
\nof most soft drinks.

"), ("I seriously *{color:red}blushed*\nwhen I _(big)sprouted_ that\ncorn stalk from my\n%[es]cabeza%.", concat!("

I seriously blushed
\nwhen I sprouted", " that
\ncorn stalk from my
\ncabeza.

")), ("
\n\na.gsub!( /\n
", "
\n\na.gsub!( /</, \"\" )\n\n
"), (concat!("
\n\nh3. Sidebar\n\n\"Hobix\":http://hobix.com/\n\"Ruby\":http://ruby-lang.org/\n\n
\n\n", "The main text of the\npage goes here and will\nstay to the left of the\nsidebar."), concat!("
\n\n\t

Sidebar

\n\n", "

Hobix
\n", "Ruby

\n\n
\n\n", "

The main text of the
\n", "page goes here and will
\nstay to the left of the
\nsidebar.

")), ("!http://hobix.com/sample.jpg!", "

\"\"

"), ("!openwindow1.gif(Bunny.)!", "

\"Bunny.\"

"), ("!openwindow1.gif!:http://hobix.com/", "

\"\"

"), ("!>obake.gif!\n\nAnd others sat all round the small\nmachine and paid it to sing to them.", concat!("

\"\"

\n\n\t", "

And others sat all round the small
\nmachine and paid it to sing to them.

")), ("!http://render.mathim.com/A%5EtAx%20%3D%20A%5Et%28Ax%29.!", "

\"\"

"), ("notextile. foo bar baz\n\np. quux\n", " foo bar baz\n\n

quux

"), ("\"foo\":http://google.com/one--two", "

foo

"), // issue 24 colspan ("|\\2. spans two cols |\n| col 1 | col 2 |", "\t\n\t\t\n\t\t\t\n\t\t\n\t\t\n\t\t\t\n\t\t\t\n\t\t\n\t
spans two cols
col 1 col 2
"), // issue 2 escaping ("\"foo ==(bar)==\":#foobar", "

foo (bar)

"), // issue 14 newlines in extended pre blocks ("pre.. Hello\n\nAgain\n\np. normal text", "
Hello\n\nAgain
\n\n

normal text

"), // url with parentheses ("\"python\":http://en.wikipedia.org/wiki/Python_(programming_language)", "

python

"), // table with hyphen styles ("table(linkblog-thumbnail).\n|(linkblog-thumbnail-cell). apple|bear|", "\t\n\t\t\n\t\t\t\n\t\t\t\n\t\t\n\t
applebear
"), // issue 32 empty table cells ("|thing|||otherthing|", "\t\n\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\n\t
thingotherthing
"), // issue 36 link reference names http and https ("\"signup\":signup\n[signup]http://myservice.com/signup", "

signup

"), ("\"signup\":signup\n[signup]https://myservice.com/signup", "

signup

"), // nested formatting ("*_test text_*", "

test text

"), ("_*test text*_", "

test text

"), // quotes in code block ("\"quoted string\"", "

\"quoted string\"

"), ("
some preformatted text
other text", "
some preformatted text
other text"), // at sign and notextile in table ("|@@|@@ @@|\n|*B1*|*B2* *B3*|", "\t\n\t\t\n\t\t\t\n\t\t\t\n\t\t\n\t\t\n\t\t\t\n\t\t\t\n\t\t\n\t
<A1><A2> <A3>
*B1**B2* *B3*
"), // cite attribute ("bq.:http://textism.com/ Text...", "
\n

Text…

\n
"), ("Hello [\"(Mum) & dad\"]", "

Hello [“(Mum) & dad”]

"), ("a -b-", "

a b

"), ]; fn run_fixtures(textile: &rustextile::Textile, fixtures: &[(&str, &str)]) { for (text, expected) in fixtures { let processed = normalize_newlines(&textile.parse(text)); let expected = normalize_newlines(expected); assert_str_eq!(processed, expected, "Input Textile: {:#?}\nFull output: {}", text, processed); } } #[test] fn test_known_restricted_values_html() { let textile = rustextile::Textile::default() .set_html_kind(rustextile::HtmlKind::HTML5) .set_restricted(true); run_fixtures(&textile, &HTML_RESTRICTED_MODE_VALUES); } #[test] fn test_known_values_html() { let textile = rustextile::Textile::default() .set_html_kind(rustextile::HtmlKind::HTML5) .set_uid("UID"); run_fixtures(&textile, &HTML_KNOWN_VALUES); }