diff options
-rw-r--r-- | src/lib.rs | 16 |
1 files changed, 13 insertions, 3 deletions
@@ -54,8 +54,12 @@ pub struct ModelEntry { pub fn parse_metadata(raw: String) -> Result<ModelMetadata,String> { 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<usize, (usize, &str), ()>) -> 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, |