orgize/tests/parse.rs

86 lines
1.9 KiB
Rust
Raw Normal View History

2019-06-26 18:53:50 +01:00
use orgize::Org;
2019-06-26 22:12:41 +01:00
use pretty_assertions::assert_eq;
2019-04-07 18:40:52 +01:00
2019-06-26 22:12:41 +01:00
macro_rules! test_suite {
2019-04-24 14:54:51 +01:00
($name:ident, $content:expr, $expected:expr) => {
#[test]
fn $name() {
2019-06-26 18:53:50 +01:00
let mut writer = Vec::new();
2019-06-27 06:20:21 +01:00
let org = Org::parse($content);
org.html(&mut writer).unwrap();
2019-06-26 18:53:50 +01:00
let string = String::from_utf8(writer).unwrap();
assert_eq!(string, $expected);
2019-04-24 14:54:51 +01:00
}
};
2019-04-07 18:40:52 +01:00
}
2019-06-26 22:12:41 +01:00
test_suite!(
2019-04-24 14:54:51 +01:00
emphasis,
2019-06-26 22:12:41 +01:00
"*bold*, /italic/,\n_underlined_, =verbatim= and ~code~",
"<main><section><p><b>bold</b>, <i>italic</i>,\n<u>underlined</u>, \
<code>verbatim</code> and <code>code</code></p></section></main>"
);
test_suite!(
link,
"Visit[[http://example.com][link1]]or[[http://example.com][link1]].",
r#"<main><section><p>Visit<a href="http://example.com">link1</a>or<a href="http://example.com">link1</a>.</p></section></main>"#
);
2019-06-26 22:12:41 +01:00
test_suite!(
section_and_headline,
r#"* title 1
section 1
** title 2
section 2
* title 3
section 3
* title 4
section 4"#,
"<main><h1>title 1</h1><section><p>section 1</p></section>\
<h2>title 2</h2><section><p>section 2</p></section>\
<h1>title 3</h1><section><p>section 3</p></section>\
<h1>title 4</h1><section><p>section 4</p></section></main>"
2019-04-24 14:54:51 +01:00
);
2019-04-08 12:35:38 +01:00
2019-06-26 22:12:41 +01:00
test_suite!(
2019-04-24 14:54:51 +01:00
list,
r#"+ 1
2019-04-08 12:35:38 +01:00
+ 2
- 3
- 4
+ 5"#,
2019-06-26 18:53:50 +01:00
"<main><section><ul>\
2019-04-24 14:54:51 +01:00
<li><p>1</p></li>\
<li><p>2</p><ul><li><p>3</p></li><li><p>4</p></li></ul></li>\
<li><p>5</p></li>\
2019-06-26 18:53:50 +01:00
</ul></section></main>"
2019-04-24 14:54:51 +01:00
);
2019-06-26 22:12:41 +01:00
test_suite!(
snippet,
"@@html:<del>@@delete this@@html:</del>@@",
2019-06-26 18:53:50 +01:00
"<main><section><p><del>delete this</del></p></section></main>"
);
test_suite!(
paragraphs,
r#"* title
paragraph 1
paragraph 2
paragraph 3
paragraph 4"#,
"<main><h1>title</h1><section>\
<p>paragraph 1</p><p>paragraph 2</p>\
<p>paragraph 3</p><p>paragraph 4</p>\
</section></main>"
);