From 686edc56adc0d8964af8505e41dc9455c1fe732c Mon Sep 17 00:00:00 2001 From: bnewbold Date: Wed, 30 Nov 2016 21:00:59 -0800 Subject: fix metadata parsing test --- src/lib.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 3f6021d..e38d10f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -54,8 +54,12 @@ pub struct ModelEntry { pub fn parse_metadata(raw: String) -> Result { let root = toml::Parser::new(&raw).parse().unwrap(); - let model = root.get("model").unwrap().as_table().unwrap(); - let variables = root.get("variables").unwrap().as_table().unwrap(); + let model = root.get("model") + .expect("missing 'model' section") + .as_table().unwrap(); + let variables = root.get("variables") + .expect("missing 'variables' section") + .as_table().unwrap(); let mut vars = vec![]; for (slug, info) in variables { let info = info.as_table().unwrap(); @@ -183,7 +187,13 @@ pub fn pp_parseerror(raw: &str, pe: ParseError) -> Str #[test] fn test_parse_metadata() { - assert_eq!(parse_metadata("asdf".to_string()).unwrap(), + let raw = +r#" +[model] +name-en = "Bogus Dummy Model" +[variables] +"#.to_string(); + assert_eq!(parse_metadata(raw).unwrap(), ModelMetadata { name_en: "Bogus Dummy Model".to_string(), description_en: None, -- cgit v1.2.3