feat(node): finish headline inserting functions

This commit is contained in:
PoiScript 2019-08-12 22:45:31 +08:00
parent 89758da638
commit 0e58afada7
4 changed files with 352 additions and 75 deletions

View file

@ -1,5 +1,7 @@
use orgize::elements::Title;
use orgize::Org;
use pretty_assertions::assert_eq;
use serde_json::to_string;
#[test]
fn set_content() {
@ -22,3 +24,45 @@ section 1
<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>"
);
}