Skip to content

Instantly share code, notes, and snippets.

@Geobert
Created October 7, 2017 21:35
Show Gist options
  • Select an option

  • Save Geobert/d96ff8ec52b40ae54bb796e918cecab2 to your computer and use it in GitHub Desktop.

Select an option

Save Geobert/d96ff8ec52b40ae54bb796e918cecab2 to your computer and use it in GitHub Desktop.
#[test]
fn convert_front_ok() {
let res = JkDocument::convert_front(Some(CORRECT_JK_FRONT.to_owned()));
match res {
Err(e) => println!("error convert: {:#?}", e),
Ok(mut converted) => {
// need to remove the custom part, the fields order is not stable
let custom_offset = converted.find("custom").unwrap_or(converted.len());
let all_but_custom: String = converted.drain(..custom_offset).collect();
assert_eq!(all_but_custom, CORRECT_CB_FRONT);
let customs_builder: FrontmatterBuilder = serde_yaml::from_str(&converted).unwrap();
let customs: frontmatter::Frontmatter = customs_builder.build().ok().unwrap();
let expected: HashMap<String, liquid::Value> =
[("guid", liquid::Value::str("\"http://url.com/?p=33\"")),
("id", liquid::Value::Num(33.0f32)),
("author", liquid::Value::str("TheAuthor")),
("tags",
liquid::Value::Array(vec![liquid::Value::str("tag1"),
liquid::Value::str("tag2")]))]
.iter()
.cloned()
.collect();
assert_eq!(expected, customs.custom);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment