From 0d2ee78f91070c93855ea14e04c4b8b70161877f Mon Sep 17 00:00:00 2001 From: elkowar <5300871+elkowar@users.noreply.github.com> Date: Mon, 28 Dec 2020 16:38:29 +0100 Subject: [PATCH] add tests for source-code extraction from xml --- src/config/xml_ext.rs | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/config/xml_ext.rs b/src/config/xml_ext.rs index 0d14413..1e090c8 100644 --- a/src/config/xml_ext.rs +++ b/src/config/xml_ext.rs @@ -240,3 +240,47 @@ impl<'a, 'b> From> for XmlNode<'a, 'b> { } } } + +#[cfg(test)] +mod test { + use super::*; + #[test] + pub fn test_parse_sourcecode_singleline() { + let input = "whatever"; + let document = roxmltree::Document::parse(&input).unwrap(); + let root_node = XmlNode::from(document.root_element()); + assert_eq!( + root_node.as_element().unwrap().only_child().unwrap().as_text_or_sourcecode(), + "whatever".to_string() + ); + } + + #[test] + pub fn test_parse_sourcecode_multiline() { + let input = r#" +this is +multiline + "#; + let document = roxmltree::Document::parse(&input).unwrap(); + let root_node = XmlNode::from(document.root_element()); + assert_eq!( + root_node.as_element().unwrap().only_child().unwrap().as_text_or_sourcecode(), + "this is\nmultiline".to_string() + ); + } + + #[test] + pub fn test_parse_sourcecode_code() { + let input = r#" +if [ "this" == '$that' ]; then + echo `hi` +fi + "#; + let document = roxmltree::Document::parse(&input).unwrap(); + let root_node = XmlNode::from(document.root_element()); + assert_eq!( + root_node.as_element().unwrap().only_child().unwrap().as_text_or_sourcecode(), + "if [ \"this\" == '$that' ]; then\necho `hi`\nfi".to_string() + ); + } +}