diff --git a/src/script_steps/close_window.rs b/src/script_steps/close_window.rs index 5ba0432..966f37e 100644 --- a/src/script_steps/close_window.rs +++ b/src/script_steps/close_window.rs @@ -1,15 +1,15 @@ -use crate::script_steps::parameters::calculation::Calculation; -use crate::utils::attributes::get_attribute; use quick_xml::events::Event; use quick_xml::Reader; +use crate::script_steps::parameters::calculation::Calculation; +use crate::utils::attributes::get_attribute; + pub fn sanitize(step: &str) -> Option { let mut name = String::new(); let mut calculation = String::new(); let mut only_current_file = false; let mut reader = Reader::from_str(step); - reader.trim_text(true); let mut buf: Vec = Vec::new(); loop { match reader.read_event_into(&mut buf) { @@ -52,89 +52,89 @@ mod tests { use super::*; #[test] - fn test_sanitize_close_current() { - let xml_input = " - - A85B35DE-CF80-41B0-8E2D-F01DEF157FFF - B44BF438-B30C-4E90-A410-119377690950 - - 0 - - - - - - - - - "; + fn test_close_current() { + let xml = r#" + + A85B35DE-CF80-41B0-8E2D-F01DEF157FFF + B44BF438-B30C-4E90-A410-119377690950 + + 0 + + + + + + + + + "#; let expected_output = Some("Fenster schließen".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + assert_eq!(sanitize(xml.trim()), expected_output); } #[test] - fn test_sanitize_close_by_name() { - let xml_input = " - - 0A13A686-0AEF-4A1F-954E-AA68DBD0B028 - - 16384 - - - - + + + + + + "Foo Bar" + + - - - - - - - - "; + + + + + + + "#; - let expected_output = Some("Fenster schließen [ Name: \"Foo Bar\" ]".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + let expected_output = Some(r#"Fenster schließen [ Name: "Foo Bar" ]"#.to_string()); + assert_eq!(sanitize(xml.trim()), expected_output); } #[test] - fn test_sanitize_close_only_current_file() { - let xml_input = " - - 0A13A686-0AEF-4A1F-954E-AA68DBD0B028 - - 16384 - - - - + + + + + + "Foo Bar" + + - - - - - - - - "; + + + + + + + "#; let expected_output = - Some("Fenster schließen [ Name: \"Foo Bar\" ; Current file ]".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + Some(r#"Fenster schließen [ Name: "Foo Bar" ; Current file ]"#.to_string()); + assert_eq!(sanitize(xml.trim()), expected_output); } } diff --git a/src/script_steps/comment.rs b/src/script_steps/comment.rs index 28a197e..cd8c071 100644 --- a/src/script_steps/comment.rs +++ b/src/script_steps/comment.rs @@ -1,15 +1,14 @@ -use crate::utils::attributes::get_attribute; - use quick_xml::escape::unescape; use quick_xml::events::Event; use quick_xml::Reader; +use crate::utils::attributes::get_attribute; + pub fn sanitize(step: &str) -> Option { let mut name = String::new(); let mut comment = String::new(); let mut reader = Reader::from_str(step); - reader.trim_text(true); let mut buf: Vec = Vec::new(); loop { match reader.read_event_into(&mut buf) { @@ -46,38 +45,38 @@ mod tests { use super::*; #[test] - fn test_sanitize() { - let xml_input = " - - - - - + fn test() { + let xml = r##" + + + + + - "; + "##; let expected_output = Some("# Lorem Ipsum".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + assert_eq!(sanitize(xml.trim()), expected_output); } #[test] - fn test_sanitize_empty_comment() { - let xml_input = " - - - - + fn test_empty_comment() { + let xml = r##" + + + + - "; + "##; let expected_output = Some("".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + assert_eq!(sanitize(xml.trim()), expected_output); } } diff --git a/src/script_steps/commit.rs b/src/script_steps/commit.rs index 32ba4ec..b53e37d 100644 --- a/src/script_steps/commit.rs +++ b/src/script_steps/commit.rs @@ -1,7 +1,8 @@ -use crate::utils::attributes::get_attribute; use quick_xml::events::Event; use quick_xml::Reader; +use crate::utils::attributes::get_attribute; + pub fn sanitize(step: &str) -> Option { let mut name = String::new(); let mut suppress_validations = false; @@ -12,7 +13,6 @@ pub fn sanitize(step: &str) -> Option { let mut force_text = String::new(); let mut reader = Reader::from_str(step); - reader.trim_text(true); let mut buf: Vec = Vec::new(); loop { match reader.read_event_into(&mut buf) { @@ -96,98 +96,98 @@ mod tests { use super::*; #[test] - fn test_sanitize() { - let xml_input = " - - 384 - - - - - - - - - - - - - "; + fn test() { + let xml = r#" + + 384 + + + + + + + + + + + + + "#; let expected_output = Some("Schreibe Änderung Datens./Abfrage [ Mit Dialog: OFF ]".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + assert_eq!(sanitize(xml.trim()), expected_output); } #[test] - fn test_sanitize_force() { - let xml_input = " - - 384 - - - - - - - - - - - - - "; + fn test_force() { + let xml = r#" + + 384 + + + + + + + + + + + + + "#; let expected_output = Some( "Schreibe Änderung Datens./Abfrage [ Mit Dialog: OFF ; Schreiben erzwingen ]" .to_string(), ); - assert_eq!(sanitize(xml_input.trim()), expected_output); + assert_eq!(sanitize(xml.trim()), expected_output); } #[test] - fn test_sanitize_suppress_validate() { - let xml_input = " - - 384 - - - - - - - - - - - - - "; + fn test_suppress_validate() { + let xml = r#" + + 384 + + + + + + + + + + + + + "#; let expected_output = Some("Schreibe Änderung Datens./Abfrage [ Dateneingabeüberprüfung unterdrücken ; Mit Dialog: OFF ]".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + assert_eq!(sanitize(xml.trim()), expected_output); } #[test] - fn test_sanitize_all_options() { - let xml_input = " - - 384 - - - - - - - - - - - - - "; + fn test_all_options() { + let xml = r#" + + 384 + + + + + + + + + + + + + "#; let expected_output = Some("Schreibe Änderung Datens./Abfrage [ Dateneingabeüberprüfung unterdrücken ; Mit Dialog: ON ; Schreiben erzwingen ]".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + assert_eq!(sanitize(xml.trim()), expected_output); } } diff --git a/src/script_steps/exit_script.rs b/src/script_steps/exit_script.rs index 668c868..f1efe36 100644 --- a/src/script_steps/exit_script.rs +++ b/src/script_steps/exit_script.rs @@ -1,14 +1,14 @@ -use crate::script_steps::parameters::calculation::Calculation; -use crate::utils::attributes::get_attribute; use quick_xml::events::Event; use quick_xml::Reader; +use crate::script_steps::parameters::calculation::Calculation; +use crate::utils::attributes::get_attribute; + pub fn sanitize(step: &str) -> Option { let mut name = String::new(); let mut calculation = String::new(); let mut reader = Reader::from_str(step); - reader.trim_text(true); let mut buf: Vec = Vec::new(); loop { match reader.read_event_into(&mut buf) { @@ -38,35 +38,34 @@ mod tests { use super::*; #[test] - fn test_sanitize_without_calculation() { - let xml_input = - ""; + fn test() { + let xml = r#""#; let expected_output = Some("Aktuelles Script verlassen []".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + assert_eq!(sanitize(xml.trim()), expected_output); } #[test] - fn test_sanitize_with_calculation() { - let xml_input = " - - 16384 - - - - - - - $Foo - - - - - - - "; + fn test_with_calculation() { + let xml = r#" + + 16384 + + + + + + + $Foo + + + + + + + "#; let expected_output = Some("Aktuelles Script verlassen [ $Foo ]".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + assert_eq!(sanitize(xml.trim()), expected_output); } } diff --git a/src/script_steps/go_to_field.rs b/src/script_steps/go_to_field.rs index 81021b2..65698d4 100644 --- a/src/script_steps/go_to_field.rs +++ b/src/script_steps/go_to_field.rs @@ -1,8 +1,9 @@ -use crate::script_steps::parameters::field_reference::FieldReference; -use crate::utils::attributes::get_attribute; use quick_xml::events::Event; use quick_xml::Reader; +use crate::script_steps::parameters::field_reference::FieldReference; +use crate::utils::attributes::get_attribute; + pub fn sanitize(step: &str) -> Option { let mut name = String::new(); let mut select_label = String::new(); @@ -10,7 +11,6 @@ pub fn sanitize(step: &str) -> Option { let mut field_reference = String::new(); let mut reader = Reader::from_str(step); - reader.trim_text(true); let mut buf: Vec = Vec::new(); loop { match reader.read_event_into(&mut buf) { @@ -78,65 +78,65 @@ mod tests { use super::*; #[test] - fn test_sanitize() { - let xml_input = " - - 458FFEBF-72B6-4D92-BCFB-1B2D0D78D456 - - 0 - - - - - - - "; + fn test() { + let xml = r#" + + 458FFEBF-72B6-4D92-BCFB-1B2D0D78D456 + + 0 + + + + + + + "#; let expected_output = Some("Gehe zu Feld []".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + assert_eq!(sanitize(xml.trim()), expected_output); } #[test] - fn test_sanitize_select() { - let xml_input = " - - C8E7D1E1-9C0C-458F-8835-A1686DEA003C - - 4096 - - - - - - - "; + fn test_select() { + let xml = r#" + + C8E7D1E1-9C0C-458F-8835-A1686DEA003C + + 4096 + + + + + + + "#; let expected_output = Some("Gehe zu Feld [ Auswählen/Ausführen ]".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + assert_eq!(sanitize(xml.trim()), expected_output); } #[test] - fn test_sanitize_with_field_reference() { - let xml_input = " - - 226D2607-5BFF-4283-BD95-FBDACC64426D - - 4097 - - - - - - - - - - - - - "; + fn test_with_field_reference() { + let xml = r#" + + 226D2607-5BFF-4283-BD95-FBDACC64426D + + 4097 + + + + + + + + + + + + + "#; let expected_output = Some("Gehe zu Feld [ Auswählen/Ausführen ; Foo::Bar ]".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + assert_eq!(sanitize(xml.trim()), expected_output); } } diff --git a/src/script_steps/go_to_layout.rs b/src/script_steps/go_to_layout.rs index 655d106..0c8131b 100644 --- a/src/script_steps/go_to_layout.rs +++ b/src/script_steps/go_to_layout.rs @@ -1,15 +1,15 @@ -use crate::script_steps::parameters::layout_reference::LayoutReferenceContainer; -use crate::utils::attributes::get_attribute; use quick_xml::events::Event; use quick_xml::Reader; +use crate::script_steps::parameters::layout_reference::LayoutReferenceContainer; +use crate::utils::attributes::get_attribute; + pub fn sanitize(step: &str) -> Option { let mut name = String::new(); let mut animation = String::new(); let mut layout_reference = String::new(); let mut reader = Reader::from_str(step); - reader.trim_text(true); let mut buf: Vec = Vec::new(); loop { match reader.read_event_into(&mut buf) { @@ -50,116 +50,116 @@ mod tests { use super::*; #[test] - fn test_sanitize() { - let xml_input = " - - 2862164E-6771-4BF9-904A-81C64E5B38F2 - - 0 - - - - - - - - - - - - "; + fn test() { + let xml = r#" + + 2862164E-6771-4BF9-904A-81C64E5B38F2 + + 0 + + + + + + + + + + + + "#; let expected_output = Some("Gehe zu Layout [ Layout: ; Animation: Ohne ]".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + assert_eq!(sanitize(xml.trim()), expected_output); } #[test] - fn test_sanitize_layout() { - let xml_input = " - - FF4782F3-0CC1-476B-ACA0-51A60F932210 - - 8 - - - - - - - - - - - - "; + fn test_layout() { + let xml = r#" + + FF4782F3-0CC1-476B-ACA0-51A60F932210 + + 8 + + + + + + + + + + + + "#; let expected_output = - Some("Gehe zu Layout [ Layout: \"FooLayout\" ; Animation: Ohne ]".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + Some(r#"Gehe zu Layout [ Layout: "FooLayout" ; Animation: Ohne ]"#.to_string()); + assert_eq!(sanitize(xml.trim()), expected_output); } #[test] - fn test_sanitize_by_name() { - let xml_input = " - - BD982069-347C-4B37-A5A4-A1DA05050424 - - 16384 - - - - - - - - "Foo" - + fn test_by_name() { + let xml = r#" + + BD982069-347C-4B37-A5A4-A1DA05050424 + + 16384 + + + + + + + + "Foo" + + - - - - - - - - - "; + + + + + + + + "#; let expected_output = - Some("Gehe zu Layout [ Layoutname: \"Foo\" ; Animation: Ohne ]".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + Some(r#"Gehe zu Layout [ Layoutname: "Foo" ; Animation: Ohne ]"#.to_string()); + assert_eq!(sanitize(xml.trim()), expected_output); } #[test] - fn test_sanitize_by_number() { - let xml_input = " - - 38D94396-4BAB-45AE-A585-71DB39D0FF68 - - 16384 - - - - - - - - "Bar" - + fn test_by_number() { + let xml = r#" + + 38D94396-4BAB-45AE-A585-71DB39D0FF68 + + 16384 + + + + + + + + "Bar" + + - - - - - - - - - "; + + + + + + + + "#; let expected_output = - Some("Gehe zu Layout [ Layoutnr.: \"Bar\" ; Animation: Ohne ]".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + Some(r#"Gehe zu Layout [ Layoutnr.: "Bar" ; Animation: Ohne ]"#.to_string()); + assert_eq!(sanitize(xml.trim()), expected_output); } } diff --git a/src/script_steps/go_to_object.rs b/src/script_steps/go_to_object.rs index 89cc937..4f613a7 100644 --- a/src/script_steps/go_to_object.rs +++ b/src/script_steps/go_to_object.rs @@ -1,15 +1,15 @@ -use crate::script_steps::parameters::calculation::Calculation; -use crate::utils::attributes::get_attribute; use quick_xml::events::Event; use quick_xml::Reader; +use crate::script_steps::parameters::calculation::Calculation; +use crate::utils::attributes::get_attribute; + pub fn sanitize(step: &str) -> Option { let mut name = String::new(); let mut calculation = String::new(); let mut repetition = String::new(); let mut reader = Reader::from_str(step); - reader.trim_text(true); let mut buf: Vec = Vec::new(); loop { match reader.read_event_into(&mut buf) { @@ -50,66 +50,67 @@ mod tests { #[test] fn test() { - let xml_input = " - - CAEB554C-8BA5-4074-BCEF-EAF86C7744A3 - 16384 - - - - - - - - "Foo Bar" - - - - - - - - - "; + let xml = r#" + + CAEB554C-8BA5-4074-BCEF-EAF86C7744A3 + 16384 + + + + + + + + "Foo Bar" + + + + + + + + + "#; - let expected_output = Some("Gehe zu Objekt [ \"Foo Bar\" ]".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + let expected_output = Some(r#"Gehe zu Objekt [ "Foo Bar" ]"#.to_string()); + assert_eq!(sanitize(xml.trim()), expected_output); } #[test] - fn test_repition() { - let xml_input = " - - CAEB554C-8BA5-4074-BCEF-EAF86C7744A3 - 16384 - - - - - - - - "Foo Bar" - - - - - - - - - - $Rep - + fn test_repetition() { + let xml = r#" + + CAEB554C-8BA5-4074-BCEF-EAF86C7744A3 + 16384 + + + + + + + + "Foo Bar" + + + + + + + + + + $Rep + + - - - - - - "; + + + + + "#; - let expected_output = Some("Gehe zu Objekt [ \"Foo Bar\" ; Repetition: $Rep ]".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + let expected_output = + Some(r#"Gehe zu Objekt [ "Foo Bar" ; Repetition: $Rep ]"#.to_string()); + assert_eq!(sanitize(xml.trim()), expected_output); } } diff --git a/src/script_steps/go_to_portal_row.rs b/src/script_steps/go_to_portal_row.rs index 16b0052..8a4e6ec 100644 --- a/src/script_steps/go_to_portal_row.rs +++ b/src/script_steps/go_to_portal_row.rs @@ -1,7 +1,8 @@ -use crate::utils::attributes::get_attribute; use quick_xml::events::Event; use quick_xml::Reader; +use crate::utils::attributes::get_attribute; + pub fn sanitize(step: &str) -> Option { let mut name = String::new(); let mut select_label = String::new(); @@ -9,7 +10,6 @@ pub fn sanitize(step: &str) -> Option { let mut position = String::new(); let mut reader = Reader::from_str(step); - reader.trim_text(true); let mut buf: Vec = Vec::new(); loop { match reader.read_event_into(&mut buf) { @@ -66,24 +66,24 @@ mod tests { use super::*; #[test] - fn test_sanitize() { - let xml_input = " - - 1574DCD5-7ECE-4CE0-A443-E20F4770DC86 - 4098 - - - - - - - - - - "; + fn test() { + let xml = r#" + + 1574DCD5-7ECE-4CE0-A443-E20F4770DC86 + 4098 + + + + + + + + + + "#; let expected_output = Some("Gehe zu Ausschnittreihe [ Auswahl: ON ; Letzte(r) ]".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + assert_eq!(sanitize(xml.trim()), expected_output); } } diff --git a/src/script_steps/go_to_record.rs b/src/script_steps/go_to_record.rs index f27fc14..e6078f5 100644 --- a/src/script_steps/go_to_record.rs +++ b/src/script_steps/go_to_record.rs @@ -1,8 +1,9 @@ -use crate::script_steps::parameters::calculation::Calculation; -use crate::utils::attributes::get_attribute; use quick_xml::events::Event; use quick_xml::Reader; +use crate::script_steps::parameters::calculation::Calculation; +use crate::utils::attributes::get_attribute; + pub fn sanitize(step: &str) -> Option { let mut name = String::new(); @@ -13,7 +14,6 @@ pub fn sanitize(step: &str) -> Option { let mut calculation = String::new(); let mut reader = Reader::from_str(step); - reader.trim_text(true); let mut buf: Vec = Vec::new(); loop { match reader.read_event_into(&mut buf) { @@ -76,197 +76,197 @@ mod tests { #[test] fn test_go_to_first() { - let xml_input = " - - 585E2A34-2216-49D9-92F0-8FBFC5E4DEFC - - 2 - - - - - - - "; + let xml = r#" + + 585E2A34-2216-49D9-92F0-8FBFC5E4DEFC + + 2 + + + + + + + "#; let expected_output = Some("Gehe zu Datens./Abfrage/Seite [ Erste(r) ]".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + assert_eq!(sanitize(xml.trim()), expected_output); } #[test] fn test_go_to_last() { - let xml_input = " - - FEDAA48D-C6B3-4BC0-A483-EBCDE779581D - - 2 - - - - - - - "; + let xml = r#" + + FEDAA48D-C6B3-4BC0-A483-EBCDE779581D + + 2 + + + + + + + "#; let expected_output = Some("Gehe zu Datens./Abfrage/Seite [ Letzte(r) ]".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + assert_eq!(sanitize(xml.trim()), expected_output); } #[test] fn test_go_to_previous_and_stop() { - let xml_input = " - - 5D343B16-3241-4FC1-BEAB-FF8038A356F3 - - 8194 - - - - - - - - - "; + let xml = r#" + + 5D343B16-3241-4FC1-BEAB-FF8038A356F3 + + 8194 + + + + + + + + + "#; let expected_output = Some( "Gehe zu Datens./Abfrage/Seite [ Vorherige(r) ; Nach letztem beenden: ON ]".to_string(), ); - assert_eq!(sanitize(xml_input.trim()), expected_output); + assert_eq!(sanitize(xml.trim()), expected_output); } #[test] fn test_go_to_previous_not_stop() { - let xml_input = " - - 5D343B16-3241-4FC1-BEAB-FF8038A356F3 - - 8194 - - - - - - - - - "; + let xml = r#" + + 5D343B16-3241-4FC1-BEAB-FF8038A356F3 + + 8194 + + + + + + + + + "#; let expected_output = Some( "Gehe zu Datens./Abfrage/Seite [ Vorherige(r) ; Nach letztem beenden: OFF ]" .to_string(), ); - assert_eq!(sanitize(xml_input.trim()), expected_output); + assert_eq!(sanitize(xml.trim()), expected_output); } #[test] fn test_go_to_next_and_stop() { - let xml_input = " - - 8A3099C8-C500-4C96-B4AA-98DBC7FFD417 - - 8194 - - - - - - - - - "; + let xml = r#" + + 8A3099C8-C500-4C96-B4AA-98DBC7FFD417 + + 8194 + + + + + + + + + "#; let expected_output = Some( "Gehe zu Datens./Abfrage/Seite [ Nächste(r) ; Nach letztem beenden: ON ]".to_string(), ); - assert_eq!(sanitize(xml_input.trim()), expected_output); + assert_eq!(sanitize(xml.trim()), expected_output); } #[test] fn test_go_to_next_not_stop() { - let xml_input = " - - 8A3099C8-C500-4C96-B4AA-98DBC7FFD417 - - 8194 - - - - - - - - - "; + let xml = r#" + + 8A3099C8-C500-4C96-B4AA-98DBC7FFD417 + + 8194 + + + + + + + + + "#; let expected_output = Some( "Gehe zu Datens./Abfrage/Seite [ Nächste(r) ; Nach letztem beenden: OFF ]".to_string(), ); - assert_eq!(sanitize(xml_input.trim()), expected_output); + assert_eq!(sanitize(xml.trim()), expected_output); } #[test] fn test_go_to_calculated() { - let xml_input = " - - 88D1386F-3C9A-447C-8E01-F7518DA11D4E - - 16514 - - - - - - - - - Hole - ( - LayoutNummer - ) + 1 - + let xml = r#" + + 88D1386F-3C9A-447C-8E01-F7518DA11D4E + + 16514 + + + + + + + + + Hole + ( + LayoutNummer + ) + 1 + + - - - - - - "; + + + + + "#; let expected_output = Some( "Gehe zu Datens./Abfrage/Seite [ Mit Dialog: OFF ; Hole( LayoutNummer ) + 1 ]" .to_string(), ); - assert_eq!(sanitize(xml_input.trim()), expected_output); + assert_eq!(sanitize(xml.trim()), expected_output); } #[test] fn test_go_to_calculated_with_dialog() { - let xml_input = " - - 28A20FDE-D101-4019-977B-22516A869427 - - 16386 - - - - - - - - - $Nr - + let xml = r#" + + 28A20FDE-D101-4019-977B-22516A869427 + + 16386 + + + + + + + + + $Nr + + - - - - - - "; + + + + + "#; let expected_output = Some("Gehe zu Datens./Abfrage/Seite [ Mit Dialog: ON ; $Nr ]".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + assert_eq!(sanitize(xml.trim()), expected_output); } } diff --git a/src/script_steps/if_start.rs b/src/script_steps/if_start.rs index e6bf49a..801bce1 100644 --- a/src/script_steps/if_start.rs +++ b/src/script_steps/if_start.rs @@ -1,14 +1,14 @@ -use crate::script_steps::parameters::calculation::Calculation; -use crate::utils::attributes::get_attribute; use quick_xml::events::Event; use quick_xml::Reader; +use crate::script_steps::parameters::calculation::Calculation; +use crate::utils::attributes::get_attribute; + pub fn sanitize(step: &str) -> Option { let mut name = String::new(); let mut calculation = String::new(); let mut reader = Reader::from_str(step); - reader.trim_text(true); let mut buf: Vec = Vec::new(); loop { match reader.read_event_into(&mut buf) { @@ -41,64 +41,64 @@ mod tests { use super::*; #[test] - fn test_sanitize() { - let xml_input = " - - 16384 - - - - - - - - - - - - < - - - - - - - - - - - - "; + fn test() { + let xml = r#" + + 16384 + + + + + + + + + + + + < + + + + + + + + + + + + "#; let expected_output = Some("Wenn [ Foo::Bar < Bar::Foo ]".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + assert_eq!(sanitize(xml.trim()), expected_output); } #[test] - fn test_sanitize_exit_loop_if() { - let xml_input = " - - 3ED7A361-42D8-43A8-9257-28E274A9ED6D - 16384 - - - - - - - $loopCount - = - $numberOfRelatedRecords - - - - - - - "; + fn test_exit_loop_if() { + let xml = r#" + + 3ED7A361-42D8-43A8-9257-28E274A9ED6D + 16384 + + + + + + + $loopCount + = + $numberOfRelatedRecords + + + + + + + "#; let expected_output = Some("Verlasse Schleife wenn [ $loopCount = $numberOfRelatedRecords ]".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + assert_eq!(sanitize(xml.trim()), expected_output); } } diff --git a/src/script_steps/insert_text.rs b/src/script_steps/insert_text.rs index 68787e2..92d404b 100644 --- a/src/script_steps/insert_text.rs +++ b/src/script_steps/insert_text.rs @@ -1,10 +1,10 @@ +use quick_xml::events::Event; +use quick_xml::Reader; + use crate::script_steps::parameters::target::Target; use crate::script_steps::parameters::text::Text; use crate::utils::attributes::get_attribute; -use quick_xml::events::Event; -use quick_xml::Reader; - pub fn sanitize(step: &str) -> Option { let mut name = String::new(); let mut text: Option = None; @@ -12,7 +12,6 @@ pub fn sanitize(step: &str) -> Option { let mut select = false; let mut reader = Reader::from_str(step); - reader.trim_text(true); let mut buf: Vec = Vec::new(); loop { match reader.read_event_into(&mut buf) { @@ -252,7 +251,7 @@ mod tests { } #[test] - fn test_sanitize() { + fn test() { let xml = r#" FC69A314-34A9-4393-AC4C-B5E442996917 diff --git a/src/script_steps/is_enabled.rs b/src/script_steps/is_enabled.rs index d068bb8..b8b0f01 100644 --- a/src/script_steps/is_enabled.rs +++ b/src/script_steps/is_enabled.rs @@ -1,12 +1,12 @@ -use crate::utils::attributes::get_attribute; use quick_xml::events::Event; use quick_xml::Reader; +use crate::utils::attributes::get_attribute; + pub fn sanitize(step: &str) -> bool { let mut enabled = true; let mut reader = Reader::from_str(step); - reader.trim_text(true); let mut buf: Vec = Vec::new(); loop { match reader.read_event_into(&mut buf) { diff --git a/src/script_steps/new_window.rs b/src/script_steps/new_window.rs index 1643942..73515f3 100644 --- a/src/script_steps/new_window.rs +++ b/src/script_steps/new_window.rs @@ -1,9 +1,10 @@ +use quick_xml::events::Event; +use quick_xml::Reader; + use crate::script_steps::parameters::layout_reference::LayoutReferenceContainer; use crate::utils::attributes::get_attribute; use crate::utils::xml_utils; use crate::utils::xml_utils::local_name_to_string; -use quick_xml::events::Event; -use quick_xml::Reader; #[derive(Debug, Default)] struct WindowOptions { @@ -60,7 +61,6 @@ pub fn sanitize(step: &str) -> Option { let mut current_path = Vec::new(); let mut reader = Reader::from_str(step); - reader.trim_text(true); let mut buf: Vec = Vec::new(); loop { match reader.read_event_into(&mut buf) { @@ -235,128 +235,128 @@ mod tests { use super::*; #[test] - fn test_sanitize() { - let xml_input = " - - 0376F75D-7B1E-41B9-A6D5-C585D2862A6A - - 0 - - - - - - - - - - - - - - - - True - True - True - True - True - True - True - - - - - - "; + fn test() { + let xml = r#" + + 0376F75D-7B1E-41B9-A6D5-C585D2862A6A + + 0 + + + + + + + + + + + + + + + + True + True + True + True + True + True + True + + + + + + "#; let expected_output = Some("Neues Fenster [ Style: Dokument ; Layout: ]".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + assert_eq!(sanitize(xml.trim()), expected_output); } #[test] - fn test_sanitize_window_size() { - let xml_input = " - - 0612C406-BCCF-4636-946B-2EEB14EE69CF - - 16392 - - - - - - - - - - "Foo Bar" - - - - - - - - - - + fn test_window_size() { + let xml = r#" + + 0612C406-BCCF-4636-946B-2EEB14EE69CF + + 16392 + + + + + + - - - 100 + + + "Foo Bar" - - - - - - - 200 - + + + + + + + + + + + 100 + + - - - - - - - - 300 - + + + + + + + 200 + + - - - - - - - - 400 - + + + + + + + 300 + + - - - - - True - False - False - False - False - False - False - - - - - - "; + + + + + + + 400 + + + + + + + True + False + False + False + False + False + False + + + + + + "#; - let expected_output = Some("Neues Fenster [ Style: Dokument ; Name: \"Foo Bar\" ; Layout: ; Height: 100 ; Width: 200 ; Top: 300 ; Left: 400 ; Minimize: OFF ; Maximize: OFF ; Resize: OFF ; Menu: OFF ; Toolbar: OFF ]".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + let expected_output = Some(r#"Neues Fenster [ Style: Dokument ; Name: "Foo Bar" ; Layout: ; Height: 100 ; Width: 200 ; Top: 300 ; Left: 400 ; Minimize: OFF ; Maximize: OFF ; Resize: OFF ; Menu: OFF ; Toolbar: OFF ]"#.to_string()); + assert_eq!(sanitize(xml.trim()), expected_output); } } diff --git a/src/script_steps/omit_multiple_records.rs b/src/script_steps/omit_multiple_records.rs index a0c6af2..99d2c4e 100644 --- a/src/script_steps/omit_multiple_records.rs +++ b/src/script_steps/omit_multiple_records.rs @@ -1,8 +1,9 @@ -use crate::script_steps::parameters::calculation::Calculation; -use crate::utils::attributes::get_attribute; use quick_xml::events::Event; use quick_xml::Reader; +use crate::script_steps::parameters::calculation::Calculation; +use crate::utils::attributes::get_attribute; + pub fn sanitize(step: &str) -> Option { let mut name = String::new(); let mut option_name = String::new(); @@ -10,7 +11,6 @@ pub fn sanitize(step: &str) -> Option { let mut calculation = String::new(); let mut reader = Reader::from_str(step); - reader.trim_text(true); let mut buf: Vec = Vec::new(); loop { match reader.read_event_into(&mut buf) { @@ -82,42 +82,44 @@ mod tests { #[test] fn test() { - let xml_input = "\ - - - - - - - "; + let xml = r#" + + + + + + + + "#; let expected_output = Some("Mehrere ausschließen [ Mit Dialog: ON ]".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + assert_eq!(sanitize(xml.trim()), expected_output); } #[test] fn test_with_calculation() { - let xml_input = " - - 16512 - - - - - - - - - - 123 - + let xml = r#" + + 16512 + + + + + + + + + + 123 + + - - - - "; + + + + "#; let expected_output = Some("Mehrere ausschließen [ Mit Dialog: OFF ; 123 ]".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + assert_eq!(sanitize(xml.trim()), expected_output); } } diff --git a/src/script_steps/parameters/boolean.rs b/src/script_steps/parameters/boolean.rs index adc07e1..145b9e8 100644 --- a/src/script_steps/parameters/boolean.rs +++ b/src/script_steps/parameters/boolean.rs @@ -90,13 +90,13 @@ mod tests { #[test] fn test() { - let xml_input = r#" + let xml = r#" "#; - let mut reader = Reader::from_str(xml_input.trim()); + let mut reader = Reader::from_str(xml.trim()); let element = match reader.read_event() { Ok(Event::Start(e)) => e, _ => panic!("Wrong read event"), @@ -114,13 +114,13 @@ mod tests { #[test] fn test_without_name() { - let xml_input = r#" + let xml = r#" "#; - let mut reader = Reader::from_str(xml_input.trim()); + let mut reader = Reader::from_str(xml.trim()); let element = match reader.read_event() { Ok(Event::Start(e)) => e, _ => panic!("Wrong read event"), diff --git a/src/script_steps/parameters/field_reference.rs b/src/script_steps/parameters/field_reference.rs index d1eb4fa..b984e52 100644 --- a/src/script_steps/parameters/field_reference.rs +++ b/src/script_steps/parameters/field_reference.rs @@ -1,8 +1,9 @@ -use crate::script_steps::parameters::calculation::Calculation; -use crate::utils::attributes::{get_attribute, get_attributes}; use quick_xml::events::{BytesStart, Event}; use quick_xml::Reader; +use crate::script_steps::parameters::calculation::Calculation; +use crate::utils::attributes::{get_attribute, get_attributes}; + #[derive(Debug, Default)] pub struct FieldReference { pub table_reference: Option, @@ -108,18 +109,21 @@ impl FieldReference { #[cfg(test)] mod tests { - use crate::script_steps::parameters::field_reference::FieldReference; use quick_xml::events::Event; use quick_xml::Reader; + use crate::script_steps::parameters::field_reference::FieldReference; + #[test] fn test_field_reference() { - let xml_input = " - - - "; + let xml = r#" + + + + + "#; - let mut reader = Reader::from_str(xml_input); + let mut reader = Reader::from_str(xml.trim()); let element = match reader.read_event() { Ok(Event::Start(e)) => e, _ => panic!("Wrong read event"), @@ -137,12 +141,14 @@ mod tests { #[test] fn test_field_reference_with_repetition() { - let xml_input = " - - - "; + let xml = r#" + + + + + "#; - let mut reader = Reader::from_str(xml_input); + let mut reader = Reader::from_str(xml.trim()); let element = match reader.read_event() { Ok(Event::Start(e)) => e, _ => panic!("Wrong read event"), diff --git a/src/script_steps/parameters/layout_reference.rs b/src/script_steps/parameters/layout_reference.rs index f7b0e2c..4d16fc7 100644 --- a/src/script_steps/parameters/layout_reference.rs +++ b/src/script_steps/parameters/layout_reference.rs @@ -1,8 +1,9 @@ +use quick_xml::events::{BytesStart, Event}; +use quick_xml::Reader; + use crate::script_steps::parameters::calculation::Calculation; use crate::utils::attributes::get_attribute; use crate::utils::xml_utils::text_to_string; -use quick_xml::events::{BytesStart, Event}; -use quick_xml::Reader; #[derive(Debug, Default)] pub struct LayoutReferenceContainer { @@ -102,9 +103,13 @@ mod tests { #[test] fn test() { - let xml_input = ""; + let xml = r#" + + + + "#; - let mut reader = Reader::from_str(xml_input); + let mut reader = Reader::from_str(xml.trim()); let element = match reader.read_event() { Ok(Event::Start(e)) => e, _ => panic!("Wrong read event"), @@ -121,19 +126,19 @@ mod tests { #[test] fn test_layout() { - let xml_input = "\ - \ - - - "; + let xml = r#" + + + + "#; - let mut reader = Reader::from_str(xml_input); + let mut reader = Reader::from_str(xml.trim()); let element = match reader.read_event() { Ok(Event::Start(e)) => e, _ => panic!("Wrong read event"), }; - let expected_output = Some("Layout: \"Aufgabenliste\"".to_string()); + let expected_output = Some(r#"Layout: "Aufgabenliste""#.to_string()); assert_eq!( LayoutReferenceContainer::from_xml(&mut reader, &element) .unwrap() @@ -144,27 +149,26 @@ mod tests { #[test] fn test_by_name() { - let xml_input = " - - - - - - "LAYOUT_NAME_CALCULATION" - + let xml = r#" + + + + + + "LAYOUT_NAME_CALCULATION" + + - - - "; + + "#; - let mut reader = Reader::from_str(xml_input); - reader.trim_text(true); + let mut reader = Reader::from_str(xml.trim()); let element = match reader.read_event() { Ok(Event::Start(e)) => e, _ => panic!("Wrong read event"), }; - let expected_output = Some("Layoutname: \"LAYOUT_NAME_CALCULATION\"".to_string()); + let expected_output = Some(r#"Layoutname: "LAYOUT_NAME_CALCULATION""#.to_string()); assert_eq!( LayoutReferenceContainer::from_xml(&mut reader, &element) .unwrap() @@ -175,28 +179,26 @@ mod tests { #[test] fn test_by_number() { - let xml_input = " - - - - - - "LAYOUT_NUMBER_CALCULATION" - + let xml = r#" + + + + + + "LAYOUT_NUMBER_CALCULATION" + + - - - "; - - let mut reader = Reader::from_str(xml_input); - reader.trim_text(true); + + "#; + let mut reader = Reader::from_str(xml.trim()); let element = match reader.read_event() { Ok(Event::Start(e)) => e, _ => panic!("Wrong read event"), }; - let expected_output = Some("Layoutnr.: \"LAYOUT_NUMBER_CALCULATION\"".to_string()); + let expected_output = Some(r#"Layoutnr.: "LAYOUT_NUMBER_CALCULATION""#.to_string()); assert_eq!( LayoutReferenceContainer::from_xml(&mut reader, &element) .unwrap() diff --git a/src/script_steps/parameters/parameter_values.rs b/src/script_steps/parameters/parameter_values.rs index f15e6a9..81f9bf3 100644 --- a/src/script_steps/parameters/parameter_values.rs +++ b/src/script_steps/parameters/parameter_values.rs @@ -71,15 +71,15 @@ mod tests { #[test] fn test() { - let xml_input = r#" - - - - - + let xml = r#" + + + + + "#; - let mut reader = Reader::from_str(xml_input.trim()); + let mut reader = Reader::from_str(xml.trim()); let element = match reader.read_event() { Ok(Event::Start(e)) => e, _ => panic!("Wrong read event"), diff --git a/src/script_steps/parameters/target.rs b/src/script_steps/parameters/target.rs index 21a32fa..955a0b3 100644 --- a/src/script_steps/parameters/target.rs +++ b/src/script_steps/parameters/target.rs @@ -1,8 +1,9 @@ -use crate::script_steps::parameters::field_reference::FieldReference; -use crate::script_steps::parameters::variable_reference::VariableReference; use quick_xml::events::{BytesStart, Event}; use quick_xml::Reader; +use crate::script_steps::parameters::field_reference::FieldReference; +use crate::script_steps::parameters::variable_reference::VariableReference; + #[derive(Debug, Default)] pub struct Target { pub target: Option, @@ -54,13 +55,14 @@ impl Target { #[cfg(test)] mod tests { - use crate::script_steps::parameters::target::Target; use quick_xml::events::Event; use quick_xml::Reader; + use crate::script_steps::parameters::target::Target; + #[test] fn test() { - let xml_input = r#" + let xml = r#" @@ -68,7 +70,7 @@ mod tests { "#; - let mut reader = Reader::from_str(xml_input.trim()); + let mut reader = Reader::from_str(xml.trim()); let element = match reader.read_event() { Ok(Event::Start(e)) => e, _ => panic!("Wrong read event"), diff --git a/src/script_steps/parameters/text.rs b/src/script_steps/parameters/text.rs index c6bd0c4..864d688 100644 --- a/src/script_steps/parameters/text.rs +++ b/src/script_steps/parameters/text.rs @@ -1,8 +1,9 @@ -use crate::utils::attributes::get_attribute; use quick_xml::escape::unescape; use quick_xml::events::{BytesStart, Event}; use quick_xml::Reader; +use crate::utils::attributes::get_attribute; + #[derive(Debug, Default)] pub struct Text { pub text: Option, @@ -44,15 +45,16 @@ impl Text { #[cfg(test)] mod tests { - use crate::script_steps::parameters::text::Text; use quick_xml::events::Event; use quick_xml::Reader; + use crate::script_steps::parameters::text::Text; + #[test] fn test() { - let xml_input = r#""#; + let xml = r#""#; - let mut reader = Reader::from_str(xml_input.trim()); + let mut reader = Reader::from_str(xml.trim()); let element = match reader.read_event() { Ok(Event::Start(e)) => e, _ => panic!("Wrong read event"), diff --git a/src/script_steps/parameters/variable_reference.rs b/src/script_steps/parameters/variable_reference.rs index 9114f4f..daed06c 100644 --- a/src/script_steps/parameters/variable_reference.rs +++ b/src/script_steps/parameters/variable_reference.rs @@ -1,7 +1,8 @@ -use crate::utils::attributes::get_attribute; use quick_xml::events::{BytesStart, Event}; use quick_xml::Reader; +use crate::utils::attributes::get_attribute; + #[derive(Debug, Default)] pub struct VariableReference { pub name: Option, @@ -64,19 +65,20 @@ impl VariableReference { #[cfg(test)] mod tests { - use crate::script_steps::parameters::variable_reference::VariableReference; use quick_xml::events::Event; use quick_xml::Reader; + use crate::script_steps::parameters::variable_reference::VariableReference; + #[test] fn test() { - let xml_input = r#" + let xml = r#" "#; - let mut reader = Reader::from_str(xml_input.trim()); + let mut reader = Reader::from_str(xml.trim()); let element = match reader.read_event() { Ok(Event::Start(e)) => e, _ => panic!("Wrong read event"), @@ -94,13 +96,13 @@ mod tests { #[test] fn test_with_repetition() { - let xml_input = r#" + let xml = r#" "#; - let mut reader = Reader::from_str(xml_input.trim()); + let mut reader = Reader::from_str(xml.trim()); let element = match reader.read_event() { Ok(Event::Start(e)) => e, _ => panic!("Wrong read event"), diff --git a/src/script_steps/perform_find.rs b/src/script_steps/perform_find.rs index 827bf3d..7c62b18 100644 --- a/src/script_steps/perform_find.rs +++ b/src/script_steps/perform_find.rs @@ -1,14 +1,14 @@ -use crate::utils::attributes::get_attribute; use quick_xml::events::Event; use quick_xml::Reader; +use crate::utils::attributes::get_attribute; + pub fn sanitize(step: &str) -> Option { let mut name = String::new(); let mut restore = false; let mut reader = Reader::from_str(step); - reader.trim_text(true); let mut buf: Vec = Vec::new(); loop { match reader.read_event_into(&mut buf) { @@ -46,49 +46,50 @@ mod tests { #[test] fn test() { - let xml_input = " - - 0 - "; + let xml = r#" + + 0 + + "#; let expected_output = Some("Ergebnismenge suchen".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + assert_eq!(sanitize(xml.trim()), expected_output); } #[test] fn test_with_criteria() { - let xml_input = " - - 33587200 - - - - - - - - - - - - - - - - - - - - - - - - - - - "; + let xml = r#" + + 33587200 + + + + + + + + + + + + + + + + + + + + + + + + + + + "#; let expected_output = Some("Ergebnismenge suchen [ ⚠️ RESTORE ⚠️ ]".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + assert_eq!(sanitize(xml.trim()), expected_output); } } diff --git a/src/script_steps/perform_script.rs b/src/script_steps/perform_script.rs index f0ebca6..c5616f9 100644 --- a/src/script_steps/perform_script.rs +++ b/src/script_steps/perform_script.rs @@ -1,8 +1,9 @@ -use crate::script_steps::parameters::calculation::Calculation; -use crate::utils::attributes::get_attribute; use quick_xml::events::Event; use quick_xml::Reader; +use crate::script_steps::parameters::calculation::Calculation; +use crate::utils::attributes::get_attribute; + pub fn sanitize(step: &str) -> Option { let mut name = String::new(); let mut script_reference_type = String::new(); @@ -11,7 +12,6 @@ pub fn sanitize(step: &str) -> Option { let mut calculation = String::new(); let mut reader = Reader::from_str(step); - reader.trim_text(true); let mut buf: Vec = Vec::new(); loop { match reader.read_event_into(&mut buf) { @@ -69,98 +69,99 @@ mod tests { #[test] fn test_without_parameter() { - let xml_input = " - - 16448 - - - - - - - - - - - - "; + let xml = r#" + + 16448 + + + + + + + + + + + + "#; - let expected_output = Some("Script ausführen [ Aus Liste ; \"Do something\" ]".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + let expected_output = + Some(r#"Script ausführen [ Aus Liste ; "Do something" ]"#.to_string()); + assert_eq!(sanitize(xml.trim()), expected_output); } #[test] fn test_with_parameter() { - let xml_input = " - - 16448 - - - - - - - - - - - - - cf_ScriptparameterSetzen - ( "CurlId" ; - $curl - ) - - - - - - - - "; + let xml = r#" + + 16448 + + + + + + + + + + + + + cf_ScriptparameterSetzen + ( "CurlId" ; + $curl + ) + + + + + + + + "#; - let expected_output = Some("Script ausführen [ Aus Liste ; \"Do something\" ; Parameter: cf_ScriptparameterSetzen ( \"CurlId\" ; $curl ) ]".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + let expected_output = Some(r#"Script ausführen [ Aus Liste ; "Do something" ; Parameter: cf_ScriptparameterSetzen ( "CurlId" ; $curl ) ]"#.to_string()); + assert_eq!(sanitize(xml.trim()), expected_output); } #[test] fn test_by_name_with_parameter() { - let xml_input = " - - 15EDD097-DB5C-4473-BC2A-16D6ECD50E75 - - 33572864 - - - - - - - - "Do something" - + let xml = r#" + + 15EDD097-DB5C-4473-BC2A-16D6ECD50E75 + + 33572864 + + + + + + + + "Do something" + + - - - - - - - - - - 123 - + + + + + + + + + 123 + + - + - - - - "; + + + "#; let expected_output = - Some("Script ausführen [ Nach Name ; \"Do something\" ; Parameter: 123 ]".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + Some(r#"Script ausführen [ Nach Name ; "Do something" ; Parameter: 123 ]"#.to_string()); + assert_eq!(sanitize(xml.trim()), expected_output); } } diff --git a/src/script_steps/primitive.rs b/src/script_steps/primitive.rs index 0059cc2..3145e5c 100644 --- a/src/script_steps/primitive.rs +++ b/src/script_steps/primitive.rs @@ -1,10 +1,10 @@ -use crate::utils::attributes::get_attribute; use quick_xml::events::Event; use quick_xml::Reader; +use crate::utils::attributes::get_attribute; + pub fn sanitize(step: &str) -> Option { let mut reader = Reader::from_str(step); - reader.trim_text(true); let mut buf: Vec = Vec::new(); loop { match reader.read_event_into(&mut buf) { @@ -32,10 +32,10 @@ mod tests { use super::*; #[test] - fn test_sanitize() { - let xml_input = ""; + fn test() { + let xml = r#""#; let expected_output = Some("Fenster fixieren".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + assert_eq!(sanitize(xml.trim()), expected_output); } } diff --git a/src/script_steps/primitive_with_booleans.rs b/src/script_steps/primitive_with_booleans.rs index 4ba2f4e..4f0b51e 100644 --- a/src/script_steps/primitive_with_booleans.rs +++ b/src/script_steps/primitive_with_booleans.rs @@ -9,7 +9,6 @@ pub fn sanitize(step: &str) -> Option { let mut parameters: Vec = Vec::new(); let mut reader = Reader::from_str(step); - reader.trim_text(true); let mut buf: Vec = Vec::new(); loop { match reader.read_event_into(&mut buf) { @@ -50,53 +49,53 @@ mod tests { use super::*; #[test] - fn test_sanitize_enabled() { - let xml_input = " - - 196608 - - - - - - - "; + fn test_enabled() { + let xml = r#" + + 196608 + + + + + + + "#; let expected_output = Some("Fehleraufzeichnung setzen [ ON ]".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + assert_eq!(sanitize(xml.trim()), expected_output); } #[test] - fn test_sanitize_disabled() { - let xml_input = " - - 196608 - - - - - - - "; + fn test_disabled() { + let xml = r#" + + 196608 + + + + + + + "#; let expected_output = Some("Fehleraufzeichnung setzen [ OFF ]".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + assert_eq!(sanitize(xml.trim()), expected_output); } #[test] - fn test_sanitize_enter_find_mode() { - let xml_input = " - - 3C5EBF9C-BAE0-460F-92AF-3FB73649951B - - - - - - - "; + fn test_enter_find_mode() { + let xml = r#" + + 3C5EBF9C-BAE0-460F-92AF-3FB73649951B + + + + + + + "#; let expected_output = Some("Suchenmodus aktivieren [ Pause: OFF ]".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + assert_eq!(sanitize(xml.trim()), expected_output); } } diff --git a/src/script_steps/refresh_object.rs b/src/script_steps/refresh_object.rs index 6e4e6a2..f37a671 100644 --- a/src/script_steps/refresh_object.rs +++ b/src/script_steps/refresh_object.rs @@ -1,8 +1,9 @@ -use crate::utils::attributes::get_attribute; -use crate::utils::xml_utils; use quick_xml::events::Event; use quick_xml::Reader; +use crate::utils::attributes::get_attribute; +use crate::utils::xml_utils; + pub fn sanitize(step: &str) -> Option { let mut name = String::new(); let mut in_object_name_calculation = false; @@ -11,7 +12,6 @@ pub fn sanitize(step: &str) -> Option { let mut repetition_calculation = String::new(); let mut reader = Reader::from_str(step); - reader.trim_text(true); let mut buf: Vec = Vec::new(); loop { match reader.read_event_into(&mut buf) { @@ -63,98 +63,98 @@ mod tests { use super::*; #[test] - fn test_sanitize() { - let xml_input = " - - B15C461D-629E-4EE6-990A-81AC5D203DA2 - - 0 - - - - - - - - "; + fn test() { + let xml = r#" + + B15C461D-629E-4EE6-990A-81AC5D203DA2 + + 0 + + + + + + + + "#; let expected_output = Some("Objekt aktualisieren []".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + assert_eq!(sanitize(xml.trim()), expected_output); } #[test] - fn test_sanitize_by_name() { - let xml_input = " - - 8A55155F-0DEF-40C6-842B-5A8DDE9E2289 - - 16384 - - - - - - - - "Foo" - + fn test_by_name() { + let xml = r#" + + 8A55155F-0DEF-40C6-842B-5A8DDE9E2289 + + 16384 + + + + + + + + "Foo" + + - - - - - - - - 1 - + + + + + + + 1 + + - - - - - - "; + + + + + "#; - let expected_output = Some("Objekt aktualisieren [ Name: \"Foo\" ]".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + let expected_output = Some(r#"Objekt aktualisieren [ Name: "Foo" ]"#.to_string()); + assert_eq!(sanitize(xml.trim()), expected_output); } #[test] - fn test_sanitize_by_name_with_rep() { - let xml_input = " - - 6E838F90-D32C-480C-B0C9-3D6510F0904F - - 16384 - - - - - - - - "Foo" - + fn test_by_name_with_rep() { + let xml = r#" + + 6E838F90-D32C-480C-B0C9-3D6510F0904F + + 16384 + + + + + + + + "Foo" + + - - - - - - - - 2 - + + + + + + + 2 + + - - - - - - "; + + + + + "#; - let expected_output = Some("Objekt aktualisieren [ Name: \"Foo\" ; 2 ]".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + let expected_output = Some(r#"Objekt aktualisieren [ Name: "Foo" ; 2 ]"#.to_string()); + assert_eq!(sanitize(xml.trim()), expected_output); } } diff --git a/src/script_steps/replace_field_contents.rs b/src/script_steps/replace_field_contents.rs index b69fb87..7a5c0c3 100644 --- a/src/script_steps/replace_field_contents.rs +++ b/src/script_steps/replace_field_contents.rs @@ -1,8 +1,9 @@ +use quick_xml::events::Event; +use quick_xml::Reader; + use crate::script_steps::parameters::calculation::Calculation; use crate::script_steps::parameters::field_reference::FieldReference; use crate::utils::attributes::get_attribute; -use quick_xml::events::Event; -use quick_xml::Reader; pub fn sanitize(step: &str) -> Option { let mut name = String::new(); @@ -16,7 +17,6 @@ pub fn sanitize(step: &str) -> Option { let mut list_name_to_input_dialog_label = false; let mut reader = Reader::from_str(step); - reader.trim_text(true); let mut buf: Vec = Vec::new(); loop { match reader.read_event_into(&mut buf) { @@ -52,7 +52,7 @@ pub fn sanitize(step: &str) -> Option { if list_name_to_input_dialog_label { if get_attribute(&e, "value").unwrap() == "True" { if let Some(last_param) = params.last_mut() { - last_param.0 = last_param.1.clone(); + last_param.0.clone_from(&last_param.1); last_param.1 = get_attribute(&e, "name").unwrap().to_string(); } } @@ -115,240 +115,248 @@ mod tests { #[test] fn test_broken_reference() { - let xml_input = " - - 1 - - - - - - - - - - - - - - "; + let xml = r#" + + 1 + + + + + + + + + + + + + + + "#; let expected_output = Some("Ersetze alle Feldwerte [ Mit Dialog: ON ; 🚨🚨🚨 BROKEN REFERENCE 🚨🚨🚨 ; Aktueller Inhalt ]".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + assert_eq!(sanitize(xml.trim()), expected_output); } #[test] fn test_no_reference_with_calculation() { - let xml_input = " - - 16384 - - - - - - - - - - - 123456 - + let xml = r#" + + 16384 + + + + + + + + + + + 123456 + + - - - - - "; + + + + + "#; let expected_output = Some( "Ersetze alle Feldwerte [ Mit Dialog: ON ; Durch Berechnung ersetzen: 123456 ]" .to_string(), ); - assert_eq!(sanitize(xml_input.trim()), expected_output); + assert_eq!(sanitize(xml.trim()), expected_output); } #[test] fn test_with_reference() { - let xml_input = " - - 5 - - - - - - - - - - - - - - - "; + let xml = r#" + + 5 + + + + + + + + + + + + + + + + "#; let expected_output = Some( "Ersetze alle Feldwerte [ Mit Dialog: ON ; _Syntax::On ; Aktueller Inhalt ]" .to_string(), ); - assert_eq!(sanitize(xml_input.trim()), expected_output); + assert_eq!(sanitize(xml.trim()), expected_output); } #[test] fn test_auto_increment_dialog() { - let xml_input = " - - 5 - - - - - - - - - - - - - - - - - - "; + let xml = r#" + + 5 + + + + + + + + + + + + + + + + + + + "#; let expected_output = Some("Ersetze alle Feldwerte [ Mit Dialog: ON ; _Syntax::On ; Durch fortlaufende Nummern ersetzen: Werte der Eingabeoptionen ]".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + assert_eq!(sanitize(xml.trim()), expected_output); } #[test] fn test_auto_increment_fixed_values() { - let xml_input = " - - 5 - - - - - - - - - - - - - - - + let xml = r#" + + 5 + + + + + + + + + + + + + + + + + - - - - - "; + + + + "#; let expected_output = Some("Ersetze alle Feldwerte [ Mit Dialog: ON ; _Syntax::On ; Durch fortlaufende Nummern ersetzen ; Initial: 1 ; Interval: 1 ]".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + assert_eq!(sanitize(xml.trim()), expected_output); } #[test] fn test_auto_increment_and_update_options() { - let xml_input = " - - 5 - - - - - - - - - - - - - - - + let xml = r#" + + 5 + + + + + + + + + + + + + + + + + - - - - - "; + + + + "#; let expected_output = Some("Ersetze alle Feldwerte [ Mit Dialog: ON ; _Syntax::__ID ; Durch fortlaufende Nummern ersetzen ; Eingabeoptionen aktualisieren: ON ; Initial: 100 ; Interval: 10 ]".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + assert_eq!(sanitize(xml.trim()), expected_output); } #[test] fn test_auto_increment_dialog_given_start_and_interval() { - let xml_input = " - - 5 - - - - - - - - - - - - - - - + let xml = r#" + + 5 + + + + + + + + + + + + + + + + + - - - - - "; + + + + "#; let expected_output = Some("Ersetze alle Feldwerte [ Mit Dialog: ON ; _Syntax::__ID ; Durch fortlaufende Nummern ersetzen ; Eingabeoptionen aktualisieren: ON ; Initial: 100 ; Interval: 10 ]".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + assert_eq!(sanitize(xml.trim()), expected_output); } #[test] fn test_with_calculation() { - let xml_input = " - - 16389 - - - - - - - - - - - - - - - - - "Calc" - + let xml = r#" + + 16389 + + + + + + + + + + + + + + + + + "Calc" + + - - - - - "; + + + + + "#; let expected_output = - Some("Ersetze alle Feldwerte [ Mit Dialog: ON ; _Syntax::On ; Durch Berechnung ersetzen: \"Calc\" ]".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + Some(r#"Ersetze alle Feldwerte [ Mit Dialog: ON ; _Syntax::On ; Durch Berechnung ersetzen: "Calc" ]"#.to_string()); + assert_eq!(sanitize(xml.trim()), expected_output); } } diff --git a/src/script_steps/set_field_data.rs b/src/script_steps/set_field_data.rs index 2f9a1e6..e400511 100644 --- a/src/script_steps/set_field_data.rs +++ b/src/script_steps/set_field_data.rs @@ -1,8 +1,9 @@ +use quick_xml::events::Event; +use quick_xml::Reader; + use crate::script_steps::parameters::calculation::Calculation; use crate::script_steps::parameters::field_reference::FieldReference; use crate::utils::attributes::get_attribute; -use quick_xml::events::Event; -use quick_xml::Reader; pub fn sanitize(step: &str) -> Option { let mut name = String::new(); @@ -10,7 +11,6 @@ pub fn sanitize(step: &str) -> Option { let mut calculation = String::new(); let mut reader = Reader::from_str(step); - reader.trim_text(true); let mut buf: Vec = Vec::new(); loop { match reader.read_event_into(&mut buf) { @@ -49,37 +49,37 @@ mod tests { use super::*; #[test] - fn test_sanitize() { - let xml_input = " - - 16385 - - - - - - - - - - - - - - - - - - - - - - - - "; + fn test() { + let xml = r#" + + 16385 + + + + + + + + + + + + + + + + + + + + + + + + "#; let expected_output = Some("Feldwert setzen [ TableFoo::FieldFoo ; TableBar::FieldBar ]".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + assert_eq!(sanitize(xml.trim()), expected_output); } } diff --git a/src/script_steps/set_variable.rs b/src/script_steps/set_variable.rs index 96828cc..72ef768 100644 --- a/src/script_steps/set_variable.rs +++ b/src/script_steps/set_variable.rs @@ -1,8 +1,9 @@ -use crate::script_steps::parameters::calculation::Calculation; -use crate::utils::attributes::get_attribute; use quick_xml::events::Event; use quick_xml::Reader; +use crate::script_steps::parameters::calculation::Calculation; +use crate::utils::attributes::get_attribute; + pub fn sanitize(step: &str) -> Option { let mut name = String::new(); let mut variable_name = String::new(); @@ -10,7 +11,6 @@ pub fn sanitize(step: &str) -> Option { let mut repetition = String::new(); let mut reader = Reader::from_str(step); - reader.trim_text(true); let mut buf: Vec = Vec::new(); loop { match reader.read_event_into(&mut buf) { @@ -54,68 +54,68 @@ mod tests { #[test] fn test() { - let xml_input = " - - 16388 - - - - - - - - "Bar" - - - - - - - - - - "; + let xml = r#" + + 16388 + + + + + + + + "Bar" + + + + + + + + + + "#; - let expected_output = Some("Variable setzen [ $Foo ; \"Bar\" ]".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + let expected_output = Some(r#"Variable setzen [ $Foo ; "Bar" ]"#.to_string()); + assert_eq!(sanitize(xml.trim()), expected_output); } #[test] fn test_complex() { - let xml_input = " - - E9ADFC26-91FA-4C6E-81A4-4979ECA90EF8 - - 16388 - - - - - - - - Bar - + let xml = r#" + + E9ADFC26-91FA-4C6E-81A4-4979ECA90EF8 + + 16388 + + + + + + + + Bar + + - - - - - - - - - $Rep - + + + + + + + + $Rep + + - - - - - - "; + + + + + "#; let expected_output = Some("Variable setzen [ $Foo[$Rep] ; $Bar ]".to_string()); - assert_eq!(sanitize(xml_input.trim()), expected_output); + assert_eq!(sanitize(xml.trim()), expected_output); } } diff --git a/src/script_steps_catalog.rs b/src/script_steps_catalog.rs index 251ad3b..f983b1f 100644 --- a/src/script_steps_catalog.rs +++ b/src/script_steps_catalog.rs @@ -1,19 +1,20 @@ -use crate::script_steps::constants::{id_to_script_step, ScriptStep}; -use crate::script_steps::sanitizer::sanitize; -use crate::{escape_filename, join_scope_id_and_name}; -use quick_xml::events::{BytesStart, Event}; -use quick_xml::reader::Reader; use std::collections::HashMap; use std::fs; use std::io::{BufRead, Read}; use std::path::Path; +use quick_xml::events::{BytesStart, Event}; +use quick_xml::reader::Reader; + +use crate::script_steps::constants::{id_to_script_step, ScriptStep}; +use crate::script_steps::sanitizer::sanitize; use crate::utils::attributes::{get_attribute, get_attributes}; use crate::utils::xml_utils::{ cdata_element_to_string, end_element_to_string, local_name_to_string, start_element_to_string, text_element_to_string, }; use crate::utils::{initialize_out_dir, write_text_file, write_xml_file}; +use crate::{escape_filename, join_scope_id_and_name}; #[derive(Debug, Default)] struct ScriptInfo { @@ -79,7 +80,7 @@ pub fn xml_explode_script_catalog( match script_id_path_map.get(&script_info.id) { None => {} Some(path) => { - script_info.path = path.clone(); + script_info.path.clone_from(path); } }; } else if depth == 4 && local_name_to_string(e.name().as_ref()) == "Step" { diff --git a/src/table_catalog.rs b/src/table_catalog.rs index 6a7f166..6e87289 100644 --- a/src/table_catalog.rs +++ b/src/table_catalog.rs @@ -1,16 +1,17 @@ -use crate::{escape_filename, join_scope_id_and_name}; -use quick_xml::events::{BytesStart, Event}; -use quick_xml::reader::Reader; use std::collections::HashMap; use std::io::{BufRead, Read}; use std::path::Path; +use quick_xml::events::{BytesStart, Event}; +use quick_xml::reader::Reader; + use crate::utils::attributes::{get_attribute, get_attributes}; use crate::utils::xml_utils::{ cdata_element_to_string, end_element_to_string, local_name_to_string, start_element_to_string, text_element_to_string, }; use crate::utils::{initialize_out_dir, write_xml_file, Entity}; +use crate::{escape_filename, join_scope_id_and_name}; pub fn xml_explode_table_catalog( reader: &mut Reader, @@ -56,7 +57,7 @@ pub fn xml_explode_table_catalog( match table_name_id_map.get(&table_info.name) { None => {} Some(table_id) => { - table_info.id = table_id.clone(); + table_info.id.clone_from(table_id); } }; } diff --git a/src/utils/attributes.rs b/src/utils/attributes.rs index e3cf9b4..cc87411 100644 --- a/src/utils/attributes.rs +++ b/src/utils/attributes.rs @@ -1,6 +1,7 @@ +use std::borrow::Cow; + use quick_xml::events::BytesStart; use quick_xml::name::QName; -use std::borrow::Cow; pub fn key_to_string(key: QName) -> String { return String::from_utf8_lossy(key.as_ref()).to_string(); @@ -41,15 +42,15 @@ pub fn get_attribute(e: &BytesStart, name: &str) -> Option { #[cfg(test)] mod tests { - use crate::utils; use quick_xml::events::Event; use quick_xml::Reader; + use crate::utils; + #[test] fn test_get_name_attribute() { let xml_tag = ""; let mut reader = Reader::from_str(xml_tag); - reader.trim_text(true); if let Ok(Event::Start(ref e)) = reader.read_event() { assert_eq!(