test: create tests/ folder
This commit is contained in:
parent
164aff424d
commit
5e2395ed5a
|
@ -260,7 +260,7 @@ impl<'a, W: Write, E: From<Error>, H: HtmlHandler<W, E>> HtmlRender<'a, W, E, H>
|
||||||
|
|
||||||
pub fn render(&mut self) -> Result<(), E> {
|
pub fn render(&mut self) -> Result<(), E> {
|
||||||
for event in &mut self.parser {
|
for event in &mut self.parser {
|
||||||
handle_event!(event, &mut self.handler, &mut self.writer);
|
handle_event!(event, &mut self.handler, self.writer);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -637,84 +637,3 @@ impl<'a> Iterator for Parser<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn parse() {
|
|
||||||
use self::Event::*;
|
|
||||||
|
|
||||||
let expected = vec![
|
|
||||||
HeadlineBeg(Headline {
|
|
||||||
level: 1,
|
|
||||||
priority: None,
|
|
||||||
keyword: None,
|
|
||||||
title: "Title 1",
|
|
||||||
tags: None,
|
|
||||||
}),
|
|
||||||
SectionBeg,
|
|
||||||
ParagraphBeg,
|
|
||||||
BoldBeg,
|
|
||||||
Text("Section 1"),
|
|
||||||
BoldEnd,
|
|
||||||
ParagraphEnd,
|
|
||||||
SectionEnd,
|
|
||||||
HeadlineBeg(Headline {
|
|
||||||
level: 2,
|
|
||||||
priority: None,
|
|
||||||
keyword: None,
|
|
||||||
title: "Title 2",
|
|
||||||
tags: None,
|
|
||||||
}),
|
|
||||||
SectionBeg,
|
|
||||||
ParagraphBeg,
|
|
||||||
UnderlineBeg,
|
|
||||||
Text("Section 2"),
|
|
||||||
UnderlineEnd,
|
|
||||||
ParagraphEnd,
|
|
||||||
SectionEnd,
|
|
||||||
HeadlineEnd,
|
|
||||||
HeadlineEnd,
|
|
||||||
HeadlineBeg(Headline {
|
|
||||||
level: 1,
|
|
||||||
priority: None,
|
|
||||||
keyword: None,
|
|
||||||
title: "Title 3",
|
|
||||||
tags: None,
|
|
||||||
}),
|
|
||||||
SectionBeg,
|
|
||||||
ParagraphBeg,
|
|
||||||
ItalicBeg,
|
|
||||||
Text("Section 3"),
|
|
||||||
ItalicEnd,
|
|
||||||
ParagraphEnd,
|
|
||||||
SectionEnd,
|
|
||||||
HeadlineEnd,
|
|
||||||
HeadlineBeg(Headline {
|
|
||||||
level: 1,
|
|
||||||
priority: None,
|
|
||||||
keyword: None,
|
|
||||||
title: "Title 4",
|
|
||||||
tags: None,
|
|
||||||
}),
|
|
||||||
SectionBeg,
|
|
||||||
ParagraphBeg,
|
|
||||||
Verbatim("Section 4"),
|
|
||||||
ParagraphEnd,
|
|
||||||
SectionEnd,
|
|
||||||
HeadlineEnd,
|
|
||||||
];
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
Parser::new(
|
|
||||||
r#"* Title 1
|
|
||||||
*Section 1*
|
|
||||||
** Title 2
|
|
||||||
_Section 2_
|
|
||||||
* Title 3
|
|
||||||
/Section 3/
|
|
||||||
* Title 4
|
|
||||||
=Section 4="#
|
|
||||||
)
|
|
||||||
.collect::<Vec<_>>(),
|
|
||||||
expected
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
34
tests/html.rs
Normal file
34
tests/html.rs
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
extern crate orgize;
|
||||||
|
|
||||||
|
use orgize::export::HtmlRender;
|
||||||
|
use std::io::Cursor;
|
||||||
|
|
||||||
|
macro_rules! parse_assert {
|
||||||
|
($content:expr, $expected:expr) => {{
|
||||||
|
let mut cursor = Cursor::new(Vec::new());
|
||||||
|
let mut render = HtmlRender::default(&mut cursor, $content);
|
||||||
|
render.render().expect("render error");
|
||||||
|
let s = String::from_utf8(cursor.into_inner()).expect("invalid utf-8");
|
||||||
|
assert_eq!(s, $expected);
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn emphasis() {
|
||||||
|
parse_assert!(
|
||||||
|
r#"* Title 1
|
||||||
|
*Section 1*
|
||||||
|
** Title 2
|
||||||
|
_Section 2_
|
||||||
|
* Title 3
|
||||||
|
/Section 3/
|
||||||
|
* Title 4
|
||||||
|
=Section 4="#,
|
||||||
|
concat!(
|
||||||
|
"<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><section><p><code>Section 4</code></p></section>"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
Loading…
Reference in a new issue