orgize/tests/html.rs

67 lines
1.5 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>"
);
2019-06-26 22:12:41 +01:00
test_suite!(
section_and_headline,
2019-04-24 14:54:51 +01:00
r#"* Title 1
2019-04-07 18:40:52 +01:00
*Section 1*
** Title 2
_Section 2_
* Title 3
/Section 3/
* Title 4
=Section 4="#,
2019-06-26 18:53:50 +01:00
"<main><h1>Title 1</h1>\
<section><p><b>Section 1</b></p></section>\
<h2>Title 2</h2>\
<section><p><u>Section 2</u></p></section>\
<h1>Title 3</h1>\
<section><p><i>Section 3</i></p></section>\
<h1>Title 4</h1>\
2019-06-26 18:53:50 +01:00
<section><p><code>Section 4</code></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>"
);