Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: reformat files #34

Merged
merged 1 commit into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 74 additions & 74 deletions src/script_steps/close_window.rs
Original file line number Diff line number Diff line change
@@ -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<String> {
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<u8> = Vec::new();
loop {
match reader.read_event_into(&mut buf) {
Expand Down Expand Up @@ -52,89 +52,89 @@ mod tests {
use super::*;

#[test]
fn test_sanitize_close_current() {
let xml_input = "
<Step index=\"12\" id=\"121\" name=\"Fenster schließen\" enable=\"True\">
<UUID>A85B35DE-CF80-41B0-8E2D-F01DEF157FFF</UUID>
<SourceUUID>B44BF438-B30C-4E90-A410-119377690950</SourceUUID>
<OwnerID></OwnerID>
<Options>0</Options>
<ParameterValues membercount=\"1\">
<Parameter type=\"WindowReference\">
<WindowReference>
<Select kind=\"0\" type=\"current\"></Select>
</WindowReference>
</Parameter>
</ParameterValues>
</Step>
";
fn test_close_current() {
let xml = r#"
<Step index="12" id="121" name="Fenster schließen" enable="True">
<UUID>A85B35DE-CF80-41B0-8E2D-F01DEF157FFF</UUID>
<SourceUUID>B44BF438-B30C-4E90-A410-119377690950</SourceUUID>
<OwnerID></OwnerID>
<Options>0</Options>
<ParameterValues membercount="1">
<Parameter type="WindowReference">
<WindowReference>
<Select kind="0" type="current"></Select>
</WindowReference>
</Parameter>
</ParameterValues>
</Step>
"#;

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 = "
<Step index=\"13\" id=\"121\" name=\"Fenster schließen\" enable=\"True\">
<UUID>0A13A686-0AEF-4A1F-954E-AA68DBD0B028</UUID>
<OwnerID></OwnerID>
<Options>16384</Options>
<ParameterValues membercount=\"1\">
<Parameter type=\"WindowReference\">
<WindowReference>
<Select kind=\"1\" type=\"Calculated\">
<Name current=\"False\">
<Calculation datatype=\"1\" position=\"0\">
<Calculation>
<Text><![CDATA[\"Foo Bar\"]]></Text>
<ChunkList hash=\"525D18B1E8FB2D7DFFF28F99FBDA6054\">
<Chunk type=\"NoRef\">&quot;Foo Bar&quot;</Chunk>
</ChunkList>
fn test_close_by_name() {
let xml = r#"
<Step index="13" id="121" name="Fenster schließen" enable="True">
<UUID>0A13A686-0AEF-4A1F-954E-AA68DBD0B028</UUID>
<OwnerID></OwnerID>
<Options>16384</Options>
<ParameterValues membercount="1">
<Parameter type="WindowReference">
<WindowReference>
<Select kind="1" type="Calculated">
<Name current="False">
<Calculation datatype="1" position="0">
<Calculation>
<Text><![CDATA["Foo Bar"]]></Text>
<ChunkList hash="525D18B1E8FB2D7DFFF28F99FBDA6054">
<Chunk type="NoRef">&quot;Foo Bar&quot;</Chunk>
</ChunkList>
</Calculation>
</Calculation>
</Calculation>
</Name>
</Select>
</WindowReference>
</Parameter>
</ParameterValues>
</Step>
";
</Name>
</Select>
</WindowReference>
</Parameter>
</ParameterValues>
</Step>
"#;

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 = "
<Step index=\"13\" id=\"121\" name=\"Fenster schließen\" enable=\"True\">
<UUID>0A13A686-0AEF-4A1F-954E-AA68DBD0B028</UUID>
<OwnerID></OwnerID>
<Options>16384</Options>
<ParameterValues membercount=\"1\">
<Parameter type=\"WindowReference\">
<WindowReference>
<Select kind=\"1\" type=\"Calculated\">
<Name current=\"True\">
<Calculation datatype=\"1\" position=\"0\">
<Calculation>
<Text><![CDATA[\"Foo Bar\"]]></Text>
<ChunkList hash=\"525D18B1E8FB2D7DFFF28F99FBDA6054\">
<Chunk type=\"NoRef\">&quot;Foo Bar&quot;</Chunk>
</ChunkList>
fn test_close_only_current_file() {
let xml = r#"
<Step index="13" id="121" name="Fenster schließen" enable="True">
<UUID>0A13A686-0AEF-4A1F-954E-AA68DBD0B028</UUID>
<OwnerID></OwnerID>
<Options>16384</Options>
<ParameterValues membercount="1">
<Parameter type="WindowReference">
<WindowReference>
<Select kind="1" type="Calculated">
<Name current="True">
<Calculation datatype="1" position="0">
<Calculation>
<Text><![CDATA["Foo Bar"]]></Text>
<ChunkList hash="525D18B1E8FB2D7DFFF28F99FBDA6054">
<Chunk type="NoRef">&quot;Foo Bar&quot;</Chunk>
</ChunkList>
</Calculation>
</Calculation>
</Calculation>
</Name>
</Select>
</WindowReference>
</Parameter>
</ParameterValues>
</Step>
";
</Name>
</Select>
</WindowReference>
</Parameter>
</ParameterValues>
</Step>
"#;

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);
}
}
39 changes: 19 additions & 20 deletions src/script_steps/comment.rs
Original file line number Diff line number Diff line change
@@ -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<String> {
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<u8> = Vec::new();
loop {
match reader.read_event_into(&mut buf) {
Expand Down Expand Up @@ -46,38 +45,38 @@ mod tests {
use super::*;

#[test]
fn test_sanitize() {
let xml_input = "
<Step id=\"89\" name=\"# (Kommentar)\" enable=\"True\">
<ParameterValues membercount=\"1\">
<ParameterValues membercount=\"1\">
<Parameter type=\"Comment\">
<Comment value=\"Lorem Ipsum\"></Comment>
fn test() {
let xml = r##"
<Step id="89" name="# (Kommentar)" enable="True">
<ParameterValues membercount="1">
<ParameterValues membercount="1">
<Parameter type="Comment">
<Comment value="Lorem Ipsum"></Comment>
</Parameter>
</ParameterValues>
</ParameterValues>
</Step>
";
"##;

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 = "
<Step id=\"89\" name=\"# (Kommentar)\" enable=\"True\">
<ParameterValues membercount=\"1\">
<ParameterValues membercount=\"1\">
<Parameter type=\"Comment\">
fn test_empty_comment() {
let xml = r##"
<Step id="89" name="# (Kommentar)" enable="True">
<ParameterValues membercount="1">
<ParameterValues membercount="1">
<Parameter type="Comment">
<Comment></Comment>
</Parameter>
</ParameterValues>
</ParameterValues>
</Step>
";
"##;

let expected_output = Some("".to_string());
assert_eq!(sanitize(xml_input.trim()), expected_output);
assert_eq!(sanitize(xml.trim()), expected_output);
}
}
Loading
Loading