From c318b1aaf6ad61ec1c9cad0031e015593499d728 Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Tue, 5 Oct 2021 23:18:39 +0200 Subject: [PATCH] fix(render): fix warnings --- espanso-render/src/extension/date.rs | 11 ++---- espanso-render/src/extension/echo.rs | 3 +- espanso-render/src/extension/random.rs | 7 ++-- espanso-render/src/extension/script.rs | 37 +++++++-------------- espanso-render/src/extension/shell.rs | 46 ++++++++++---------------- espanso-render/src/renderer/mod.rs | 20 ++++------- 6 files changed, 41 insertions(+), 83 deletions(-) diff --git a/espanso-render/src/extension/date.rs b/espanso-render/src/extension/date.rs index d696144..f82b387 100644 --- a/espanso-render/src/extension/date.rs +++ b/espanso-render/src/extension/date.rs @@ -78,16 +78,13 @@ impl DateExtension { mod tests { use super::*; use chrono::offset::TimeZone; - use std::iter::FromIterator; #[test] fn date_formatted_correctly() { let mut extension = DateExtension::new(); extension.fixed_date = Some(Local.ymd(2014, 7, 8).and_hms(9, 10, 11)); - let param = Params::from_iter( - vec![("format".to_string(), Value::String("%H:%M:%S".to_string()))].into_iter(), - ); + let param = vec![("format".to_string(), Value::String("%H:%M:%S".to_string()))].into_iter().collect::(); assert_eq!( extension .calculate(&Default::default(), &Default::default(), ¶m) @@ -102,13 +99,11 @@ mod tests { let mut extension = DateExtension::new(); extension.fixed_date = Some(Local.ymd(2014, 7, 8).and_hms(9, 10, 11)); - let param = Params::from_iter( - vec![ + let param = vec![ ("format".to_string(), Value::String("%H:%M:%S".to_string())), ("offset".to_string(), Value::Number(Number::Integer(3600))), ] - .into_iter(), - ); + .into_iter().collect::(); assert_eq!( extension .calculate(&Default::default(), &Default::default(), ¶m) diff --git a/espanso-render/src/extension/echo.rs b/espanso-render/src/extension/echo.rs index 83b0764..edb1387 100644 --- a/espanso-render/src/extension/echo.rs +++ b/espanso-render/src/extension/echo.rs @@ -67,14 +67,13 @@ pub enum EchoExtensionError { #[cfg(test)] mod tests { use super::*; - use std::iter::FromIterator; #[test] fn echo_works_correctly() { let extension = EchoExtension::new(); let param = - Params::from_iter(vec![("echo".to_string(), Value::String("test".to_string()))].into_iter()); + vec![("echo".to_string(), Value::String("test".to_string()))].into_iter().collect::(); assert_eq!( extension .calculate(&Default::default(), &Default::default(), ¶m) diff --git a/espanso-render/src/extension/random.rs b/espanso-render/src/extension/random.rs index 91fd49a..a905156 100644 --- a/espanso-render/src/extension/random.rs +++ b/espanso-render/src/extension/random.rs @@ -71,14 +71,12 @@ pub enum RandomExtensionError { #[cfg(test)] mod tests { use super::*; - use std::iter::FromIterator; #[test] fn random_works_correctly() { let extension = RandomExtension::new(); - let param = Params::from_iter( - vec![( + let param = vec![( "choices".to_string(), Value::Array(vec![ Value::String("first".to_string()), @@ -86,8 +84,7 @@ mod tests { Value::String("third".to_string()), ]), )] - .into_iter(), - ); + .into_iter().collect::(); assert!(matches!( extension .calculate(&Default::default(), &Default::default(), ¶m) diff --git a/espanso-render/src/extension/script.rs b/espanso-render/src/extension/script.rs index 2ac9632..3bd846c 100644 --- a/espanso-render/src/extension/script.rs +++ b/espanso-render/src/extension/script.rs @@ -181,7 +181,6 @@ mod tests { use super::*; #[cfg(not(target_os = "windows"))] use crate::Scope; - use std::iter::FromIterator; fn get_extension() -> ScriptExtension { ScriptExtension::new(&PathBuf::new(), &PathBuf::new(), &PathBuf::new()) @@ -192,16 +191,14 @@ mod tests { fn basic() { let extension = get_extension(); - let param = Params::from_iter( - vec![( + let param = vec![( "args".to_string(), Value::Array(vec![ Value::String("echo".to_string()), Value::String("hello world".to_string()), ]), )] - .into_iter(), - ); + .into_iter().collect::(); assert_eq!( extension .calculate(&Default::default(), &Default::default(), ¶m) @@ -216,8 +213,7 @@ mod tests { fn basic_no_trim() { let extension = get_extension(); - let param = Params::from_iter( - vec![ + let param = vec![ ( "args".to_string(), Value::Array(vec![ @@ -227,8 +223,7 @@ mod tests { ), ("trim".to_string(), Value::Bool(false)), ] - .into_iter(), - ); + .into_iter().collect::(); if cfg!(target_os = "windows") { assert_eq!( extension @@ -253,8 +248,7 @@ mod tests { fn var_injection() { let extension = get_extension(); - let param = Params::from_iter( - vec![ + let param = vec![ ( "args".to_string(), Value::Array(vec![ @@ -264,8 +258,7 @@ mod tests { ]), ), ] - .into_iter(), - ); + .into_iter().collect::(); let mut scope = Scope::new(); scope.insert("var1", ExtensionOutput::Single("hello world".to_string())); assert_eq!( @@ -281,8 +274,7 @@ mod tests { fn invalid_command() { let extension = get_extension(); - let param = Params::from_iter( - vec![ + let param = vec![ ( "args".to_string(), Value::Array(vec![ @@ -290,8 +282,7 @@ mod tests { ]), ), ] - .into_iter(), - ); + .into_iter().collect::(); assert!(matches!( extension.calculate(&Default::default(), &Default::default(), ¶m), ExtensionResult::Error(_) @@ -303,8 +294,7 @@ mod tests { fn exit_error() { let extension = get_extension(); - let param = Params::from_iter( - vec![ + let param = vec![ ( "args".to_string(), Value::Array(vec![ @@ -314,8 +304,7 @@ mod tests { ]), ), ] - .into_iter(), - ); + .into_iter().collect::(); assert!(matches!( extension.calculate(&Default::default(), &Default::default(), ¶m), ExtensionResult::Error(_) @@ -327,8 +316,7 @@ mod tests { fn ignore_error() { let extension = get_extension(); - let param = Params::from_iter( - vec![ + let param = vec![ ( "args".to_string(), Value::Array(vec![ @@ -339,8 +327,7 @@ mod tests { ), ("ignore_error".to_string(), Value::Bool(true)), ] - .into_iter(), - ); + .into_iter().collect::(); assert_eq!( extension .calculate(&Default::default(), &Default::default(), ¶m) diff --git a/espanso-render/src/extension/shell.rs b/espanso-render/src/extension/shell.rs index de99b1c..15a91a3 100644 --- a/espanso-render/src/extension/shell.rs +++ b/espanso-render/src/extension/shell.rs @@ -27,6 +27,7 @@ use crate::{Extension, ExtensionOutput, ExtensionResult, Params, Value}; use log::{info, warn}; use thiserror::Error; +#[allow(clippy::upper_case_acronyms)] pub enum Shell { Cmd, Powershell, @@ -252,22 +253,19 @@ pub enum ShellExtensionError { mod tests { use super::*; use crate::Scope; - use std::iter::FromIterator; #[test] fn shell_not_trimmed() { let extension = ShellExtension::new(&PathBuf::new()); - let param = Params::from_iter( - vec![ + let param = vec![ ( "cmd".to_string(), Value::String("echo \"hello world\"".to_string()), ), ("trim".to_string(), Value::Bool(false)), ] - .into_iter(), - ); + .into_iter().collect::(); if cfg!(target_os = "windows") { assert_eq!( extension @@ -291,13 +289,12 @@ mod tests { fn shell_trimmed() { let extension = ShellExtension::new(&PathBuf::new()); - let param = Params::from_iter( - vec![( + let param = vec![( "cmd".to_string(), Value::String("echo \"hello world\"".to_string()), )] - .into_iter(), - ); + .into_iter().collect::(); + assert_eq!( extension .calculate(&Default::default(), &Default::default(), ¶m) @@ -312,13 +309,11 @@ mod tests { fn pipes() { let extension = ShellExtension::new(&PathBuf::new()); - let param = Params::from_iter( - vec![( + let param = vec![( "cmd".to_string(), Value::String("echo \"hello world\" | cat".to_string()), )] - .into_iter(), - ); + .into_iter().collect::(); assert_eq!( extension .calculate(&Default::default(), &Default::default(), ¶m) @@ -333,24 +328,20 @@ mod tests { let extension = ShellExtension::new(&PathBuf::new()); let param = if cfg!(not(target_os = "windows")) { - Params::from_iter( - vec![( + vec![( "cmd".to_string(), Value::String("echo $ESPANSO_VAR1".to_string()), )] - .into_iter(), - ) + .into_iter().collect::() } else { - Params::from_iter( - vec![ + vec![ ( "cmd".to_string(), Value::String("echo %ESPANSO_VAR1%".to_string()), ), ("shell".to_string(), Value::String("cmd".to_string())), ] - .into_iter(), - ) + .into_iter().collect::() }; let mut scope = Scope::new(); scope.insert("var1", ExtensionOutput::Single("hello world".to_string())); @@ -367,13 +358,12 @@ mod tests { fn invalid_command() { let extension = ShellExtension::new(&PathBuf::new()); - let param = Params::from_iter( + let param = vec![( "cmd".to_string(), Value::String("nonexistentcommand".to_string()), )] - .into_iter(), - ); + .into_iter().collect::(); assert!(matches!( extension.calculate(&Default::default(), &Default::default(), ¶m), ExtensionResult::Error(_) @@ -386,7 +376,7 @@ mod tests { let extension = ShellExtension::new(&PathBuf::new()); let param = - Params::from_iter(vec![("cmd".to_string(), Value::String("exit 1".to_string()))].into_iter()); + vec![("cmd".to_string(), Value::String("exit 1".to_string()))].into_iter().collect::(); assert!(matches!( extension.calculate(&Default::default(), &Default::default(), ¶m), ExtensionResult::Error(_) @@ -398,13 +388,11 @@ mod tests { fn ignore_error() { let extension = ShellExtension::new(&PathBuf::new()); - let param = Params::from_iter( - vec![ + let param = vec![ ("cmd".to_string(), Value::String("exit 1".to_string())), ("ignore_error".to_string(), Value::Bool(true)), ] - .into_iter(), - ); + .into_iter().collect::(); assert_eq!( extension .calculate(&Default::default(), &Default::default(), ¶m) diff --git a/espanso-render/src/renderer/mod.rs b/espanso-render/src/renderer/mod.rs index 1f25895..3cea2b6 100644 --- a/espanso-render/src/renderer/mod.rs +++ b/espanso-render/src/renderer/mod.rs @@ -321,9 +321,7 @@ mod tests { .map(|(name, value)| Variable { name: (*name).to_string(), var_type: "mock".to_string(), - params: Params::from_iter( - vec![("echo".to_string(), Value::String((*value).to_string()))].into_iter(), - ), + params: vec![("echo".to_string(), Value::String((*value).to_string()))].into_iter().collect::(), }) .collect(); Template { @@ -432,9 +430,7 @@ mod tests { Variable { name: "local".to_string(), var_type: "mock".to_string(), - params: Params::from_iter( - vec![("echo".to_string(), Value::String("Bob".to_string()))].into_iter(), - ), + params: vec![("echo".to_string(), Value::String("Bob".to_string()))].into_iter().collect::(), }, Variable { name: "var".to_string(), @@ -470,9 +466,7 @@ mod tests { vars: vec![Variable { name: "var".to_string(), var_type: "match".to_string(), - params: Params::from_iter( - vec![("trigger".to_string(), Value::String("nested".to_string()))].into_iter(), - ), + params: vec![("trigger".to_string(), Value::String("nested".to_string()))].into_iter().collect::(), }], ..Default::default() }; @@ -500,9 +494,7 @@ mod tests { vars: vec![Variable { name: "var".to_string(), var_type: "match".to_string(), - params: Params::from_iter( - vec![("trigger".to_string(), Value::String("nested".to_string()))].into_iter(), - ), + params: vec![("trigger".to_string(), Value::String("nested".to_string()))].into_iter().collect::(), }], ..Default::default() }; @@ -524,7 +516,7 @@ mod tests { vars: vec![Variable { name: "var".to_string(), var_type: "mock".to_string(), - params: Params::from_iter(vec![("abort".to_string(), Value::Null)].into_iter()), + params: vec![("abort".to_string(), Value::Null)].into_iter().collect::(), }], ..Default::default() }; @@ -540,7 +532,7 @@ mod tests { vars: vec![Variable { name: "var".to_string(), var_type: "mock".to_string(), - params: Params::from_iter(vec![("error".to_string(), Value::Null)].into_iter()), + params: vec![("error".to_string(), Value::Null)].into_iter().collect::(), }], ..Default::default() };