chore: remove orgize-sync package

This commit is contained in:
PoiScript 2019-10-10 10:44:59 +08:00
parent 5d26466e07
commit b15900b100
59 changed files with 62 additions and 647 deletions

68
tests/node.rs Normal file
View file

@ -0,0 +1,68 @@
use orgize::elements::Title;
use orgize::Org;
use pretty_assertions::assert_eq;
use serde_json::to_string;
#[test]
fn set_content() {
let mut org = Org::parse(
r#"* title 1
section 1
** title 2
"#,
);
let headlines: Vec<_> = org.headlines().collect();
for headline in headlines {
headline.set_title_content(String::from("a *bold* title"), &mut org);
headline.set_section_content("and a _underline_ section", &mut org);
}
let mut writer = Vec::new();
org.html(&mut writer).unwrap();
assert_eq!(
String::from_utf8(writer).unwrap(),
"<main><h1>a <b>bold</b> title</h1><section><p>and a <u>underline</u> section</p></section>\
<h2>a <b>bold</b> title</h2><section><p>and a <u>underline</u> section</p></section></main>"
);
}
#[test]
fn insert() {
let mut org = Org::new();
let document = org.document();
let h1 = org.new_headline(Title {
level: 1,
raw: "title".into(),
..Default::default()
});
h1.set_section_content("section", &mut org);
document.prepend(h1, &mut org).unwrap();
dbg!(to_string(&org).unwrap());
let h3 = org.new_headline(Title {
level: 3,
raw: "title".into(),
..Default::default()
});
h3.set_section_content("section", &mut org);
document.prepend(h3, &mut org).unwrap();
dbg!(to_string(&org).unwrap());
let h2 = org.new_headline(Title {
level: 2,
raw: "title".into(),
..Default::default()
});
h2.set_section_content("section", &mut org);
h1.insert_before(h2, &mut org).unwrap();
dbg!(to_string(&org).unwrap());
let mut writer = Vec::new();
org.html(&mut writer).unwrap();
assert_eq!(
String::from_utf8(writer).unwrap(),
"<main><h3>title</h3><section><p>section</p></section>\
<h2>title</h2><section><p>section</p></section>\
<h1>title</h1><section><p>section</p></section></main>"
);
}

85
tests/parse.rs Normal file
View file

@ -0,0 +1,85 @@
use orgize::Org;
use pretty_assertions::assert_eq;
macro_rules! test_suite {
($name:ident, $content:expr, $expected:expr) => {
#[test]
fn $name() {
let mut writer = Vec::new();
let org = Org::parse($content);
org.html(&mut writer).unwrap();
let string = String::from_utf8(writer).unwrap();
assert_eq!(string, $expected);
}
};
}
test_suite!(
emphasis,
"*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>"#
);
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>"
);
test_suite!(
list,
r#"+ 1
+ 2
- 3
- 4
+ 5"#,
"<main><section><ul>\
<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>\
</ul></section></main>"
);
test_suite!(
snippet,
"@@html:<del>@@delete this@@html:</del>@@",
"<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>"
);