From 4329629ee9222e1cd3ff5c108628f89e686b21d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20N=2E=20Robalino?= Date: Tue, 22 Oct 2019 03:43:39 -0500 Subject: [PATCH] baseline coverage for xml parsing. --- src/commands/from_xml.rs | 70 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/src/commands/from_xml.rs b/src/commands/from_xml.rs index 0425eb408b..e99e5664e5 100644 --- a/src/commands/from_xml.rs +++ b/src/commands/from_xml.rs @@ -134,3 +134,73 @@ fn from_xml(args: CommandArgs, registry: &CommandRegistry) -> Result) -> Tagged { + Value::string(input.into()).tagged_unknown() + } + + fn row(entries: IndexMap>) -> Tagged { + Value::row(entries).tagged_unknown() + } + + fn table(list: &Vec>) -> Tagged { + Value::table(list).tagged_unknown() + } + + fn parse(xml: &str) -> Tagged { + from_xml::from_xml_string_to_value(xml.to_string(), Tag::unknown()).unwrap() + } + + #[test] + fn parses_empty_element() { + let source = ""; + + assert_eq!( + parse(source), + row(indexmap! { + "nu".into() => table(&vec![]) + }) + ); + } + + #[test] + fn parses_element_with_text() { + let source = "La era de los tres caballeros"; + + assert_eq!( + parse(source), + row(indexmap! { + "nu".into() => table(&vec![string("La era de los tres caballeros")]) + }) + ); + } + + #[test] + fn parses_element_with_elements() { + let source = "\ + + Andrés + Jonathan + Yehuda +"; + + assert_eq!( + parse(source), + row(indexmap! { + "nu".into() => table(&vec![ + row(indexmap! {"dev".into() => table(&vec![string("Andrés")])}), + row(indexmap! {"dev".into() => table(&vec![string("Jonathan")])}), + row(indexmap! {"dev".into() => table(&vec![string("Yehuda")])}) + ]) + }) + ); + } +}