fix(render): fix warnings

This commit is contained in:
Federico Terzi 2021-10-05 23:18:39 +02:00
parent 2cd974c80b
commit c318b1aaf6
6 changed files with 41 additions and 83 deletions

View File

@ -78,16 +78,13 @@ impl DateExtension {
mod tests { mod tests {
use super::*; use super::*;
use chrono::offset::TimeZone; use chrono::offset::TimeZone;
use std::iter::FromIterator;
#[test] #[test]
fn date_formatted_correctly() { fn date_formatted_correctly() {
let mut extension = DateExtension::new(); let mut extension = DateExtension::new();
extension.fixed_date = Some(Local.ymd(2014, 7, 8).and_hms(9, 10, 11)); extension.fixed_date = Some(Local.ymd(2014, 7, 8).and_hms(9, 10, 11));
let param = Params::from_iter( let param = vec![("format".to_string(), Value::String("%H:%M:%S".to_string()))].into_iter().collect::<Params>();
vec![("format".to_string(), Value::String("%H:%M:%S".to_string()))].into_iter(),
);
assert_eq!( assert_eq!(
extension extension
.calculate(&Default::default(), &Default::default(), &param) .calculate(&Default::default(), &Default::default(), &param)
@ -102,13 +99,11 @@ mod tests {
let mut extension = DateExtension::new(); let mut extension = DateExtension::new();
extension.fixed_date = Some(Local.ymd(2014, 7, 8).and_hms(9, 10, 11)); extension.fixed_date = Some(Local.ymd(2014, 7, 8).and_hms(9, 10, 11));
let param = Params::from_iter( let param = vec![
vec![
("format".to_string(), Value::String("%H:%M:%S".to_string())), ("format".to_string(), Value::String("%H:%M:%S".to_string())),
("offset".to_string(), Value::Number(Number::Integer(3600))), ("offset".to_string(), Value::Number(Number::Integer(3600))),
] ]
.into_iter(), .into_iter().collect::<Params>();
);
assert_eq!( assert_eq!(
extension extension
.calculate(&Default::default(), &Default::default(), &param) .calculate(&Default::default(), &Default::default(), &param)

View File

@ -67,14 +67,13 @@ pub enum EchoExtensionError {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use std::iter::FromIterator;
#[test] #[test]
fn echo_works_correctly() { fn echo_works_correctly() {
let extension = EchoExtension::new(); let extension = EchoExtension::new();
let param = 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::<Params>();
assert_eq!( assert_eq!(
extension extension
.calculate(&Default::default(), &Default::default(), &param) .calculate(&Default::default(), &Default::default(), &param)

View File

@ -71,14 +71,12 @@ pub enum RandomExtensionError {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use std::iter::FromIterator;
#[test] #[test]
fn random_works_correctly() { fn random_works_correctly() {
let extension = RandomExtension::new(); let extension = RandomExtension::new();
let param = Params::from_iter( let param = vec![(
vec![(
"choices".to_string(), "choices".to_string(),
Value::Array(vec![ Value::Array(vec![
Value::String("first".to_string()), Value::String("first".to_string()),
@ -86,8 +84,7 @@ mod tests {
Value::String("third".to_string()), Value::String("third".to_string()),
]), ]),
)] )]
.into_iter(), .into_iter().collect::<Params>();
);
assert!(matches!( assert!(matches!(
extension extension
.calculate(&Default::default(), &Default::default(), &param) .calculate(&Default::default(), &Default::default(), &param)

View File

@ -181,7 +181,6 @@ mod tests {
use super::*; use super::*;
#[cfg(not(target_os = "windows"))] #[cfg(not(target_os = "windows"))]
use crate::Scope; use crate::Scope;
use std::iter::FromIterator;
fn get_extension() -> ScriptExtension { fn get_extension() -> ScriptExtension {
ScriptExtension::new(&PathBuf::new(), &PathBuf::new(), &PathBuf::new()) ScriptExtension::new(&PathBuf::new(), &PathBuf::new(), &PathBuf::new())
@ -192,16 +191,14 @@ mod tests {
fn basic() { fn basic() {
let extension = get_extension(); let extension = get_extension();
let param = Params::from_iter( let param = vec![(
vec![(
"args".to_string(), "args".to_string(),
Value::Array(vec![ Value::Array(vec![
Value::String("echo".to_string()), Value::String("echo".to_string()),
Value::String("hello world".to_string()), Value::String("hello world".to_string()),
]), ]),
)] )]
.into_iter(), .into_iter().collect::<Params>();
);
assert_eq!( assert_eq!(
extension extension
.calculate(&Default::default(), &Default::default(), &param) .calculate(&Default::default(), &Default::default(), &param)
@ -216,8 +213,7 @@ mod tests {
fn basic_no_trim() { fn basic_no_trim() {
let extension = get_extension(); let extension = get_extension();
let param = Params::from_iter( let param = vec![
vec![
( (
"args".to_string(), "args".to_string(),
Value::Array(vec![ Value::Array(vec![
@ -227,8 +223,7 @@ mod tests {
), ),
("trim".to_string(), Value::Bool(false)), ("trim".to_string(), Value::Bool(false)),
] ]
.into_iter(), .into_iter().collect::<Params>();
);
if cfg!(target_os = "windows") { if cfg!(target_os = "windows") {
assert_eq!( assert_eq!(
extension extension
@ -253,8 +248,7 @@ mod tests {
fn var_injection() { fn var_injection() {
let extension = get_extension(); let extension = get_extension();
let param = Params::from_iter( let param = vec![
vec![
( (
"args".to_string(), "args".to_string(),
Value::Array(vec![ Value::Array(vec![
@ -264,8 +258,7 @@ mod tests {
]), ]),
), ),
] ]
.into_iter(), .into_iter().collect::<Params>();
);
let mut scope = Scope::new(); let mut scope = Scope::new();
scope.insert("var1", ExtensionOutput::Single("hello world".to_string())); scope.insert("var1", ExtensionOutput::Single("hello world".to_string()));
assert_eq!( assert_eq!(
@ -281,8 +274,7 @@ mod tests {
fn invalid_command() { fn invalid_command() {
let extension = get_extension(); let extension = get_extension();
let param = Params::from_iter( let param = vec![
vec![
( (
"args".to_string(), "args".to_string(),
Value::Array(vec![ Value::Array(vec![
@ -290,8 +282,7 @@ mod tests {
]), ]),
), ),
] ]
.into_iter(), .into_iter().collect::<Params>();
);
assert!(matches!( assert!(matches!(
extension.calculate(&Default::default(), &Default::default(), &param), extension.calculate(&Default::default(), &Default::default(), &param),
ExtensionResult::Error(_) ExtensionResult::Error(_)
@ -303,8 +294,7 @@ mod tests {
fn exit_error() { fn exit_error() {
let extension = get_extension(); let extension = get_extension();
let param = Params::from_iter( let param = vec![
vec![
( (
"args".to_string(), "args".to_string(),
Value::Array(vec![ Value::Array(vec![
@ -314,8 +304,7 @@ mod tests {
]), ]),
), ),
] ]
.into_iter(), .into_iter().collect::<Params>();
);
assert!(matches!( assert!(matches!(
extension.calculate(&Default::default(), &Default::default(), &param), extension.calculate(&Default::default(), &Default::default(), &param),
ExtensionResult::Error(_) ExtensionResult::Error(_)
@ -327,8 +316,7 @@ mod tests {
fn ignore_error() { fn ignore_error() {
let extension = get_extension(); let extension = get_extension();
let param = Params::from_iter( let param = vec![
vec![
( (
"args".to_string(), "args".to_string(),
Value::Array(vec![ Value::Array(vec![
@ -339,8 +327,7 @@ mod tests {
), ),
("ignore_error".to_string(), Value::Bool(true)), ("ignore_error".to_string(), Value::Bool(true)),
] ]
.into_iter(), .into_iter().collect::<Params>();
);
assert_eq!( assert_eq!(
extension extension
.calculate(&Default::default(), &Default::default(), &param) .calculate(&Default::default(), &Default::default(), &param)

View File

@ -27,6 +27,7 @@ use crate::{Extension, ExtensionOutput, ExtensionResult, Params, Value};
use log::{info, warn}; use log::{info, warn};
use thiserror::Error; use thiserror::Error;
#[allow(clippy::upper_case_acronyms)]
pub enum Shell { pub enum Shell {
Cmd, Cmd,
Powershell, Powershell,
@ -252,22 +253,19 @@ pub enum ShellExtensionError {
mod tests { mod tests {
use super::*; use super::*;
use crate::Scope; use crate::Scope;
use std::iter::FromIterator;
#[test] #[test]
fn shell_not_trimmed() { fn shell_not_trimmed() {
let extension = ShellExtension::new(&PathBuf::new()); let extension = ShellExtension::new(&PathBuf::new());
let param = Params::from_iter( let param = vec![
vec![
( (
"cmd".to_string(), "cmd".to_string(),
Value::String("echo \"hello world\"".to_string()), Value::String("echo \"hello world\"".to_string()),
), ),
("trim".to_string(), Value::Bool(false)), ("trim".to_string(), Value::Bool(false)),
] ]
.into_iter(), .into_iter().collect::<Params>();
);
if cfg!(target_os = "windows") { if cfg!(target_os = "windows") {
assert_eq!( assert_eq!(
extension extension
@ -291,13 +289,12 @@ mod tests {
fn shell_trimmed() { fn shell_trimmed() {
let extension = ShellExtension::new(&PathBuf::new()); let extension = ShellExtension::new(&PathBuf::new());
let param = Params::from_iter( let param = vec![(
vec![(
"cmd".to_string(), "cmd".to_string(),
Value::String("echo \"hello world\"".to_string()), Value::String("echo \"hello world\"".to_string()),
)] )]
.into_iter(), .into_iter().collect::<Params>();
);
assert_eq!( assert_eq!(
extension extension
.calculate(&Default::default(), &Default::default(), &param) .calculate(&Default::default(), &Default::default(), &param)
@ -312,13 +309,11 @@ mod tests {
fn pipes() { fn pipes() {
let extension = ShellExtension::new(&PathBuf::new()); let extension = ShellExtension::new(&PathBuf::new());
let param = Params::from_iter( let param = vec![(
vec![(
"cmd".to_string(), "cmd".to_string(),
Value::String("echo \"hello world\" | cat".to_string()), Value::String("echo \"hello world\" | cat".to_string()),
)] )]
.into_iter(), .into_iter().collect::<Params>();
);
assert_eq!( assert_eq!(
extension extension
.calculate(&Default::default(), &Default::default(), &param) .calculate(&Default::default(), &Default::default(), &param)
@ -333,15 +328,12 @@ mod tests {
let extension = ShellExtension::new(&PathBuf::new()); let extension = ShellExtension::new(&PathBuf::new());
let param = if cfg!(not(target_os = "windows")) { let param = if cfg!(not(target_os = "windows")) {
Params::from_iter(
vec![( vec![(
"cmd".to_string(), "cmd".to_string(),
Value::String("echo $ESPANSO_VAR1".to_string()), Value::String("echo $ESPANSO_VAR1".to_string()),
)] )]
.into_iter(), .into_iter().collect::<Params>()
)
} else { } else {
Params::from_iter(
vec![ vec![
( (
"cmd".to_string(), "cmd".to_string(),
@ -349,8 +341,7 @@ mod tests {
), ),
("shell".to_string(), Value::String("cmd".to_string())), ("shell".to_string(), Value::String("cmd".to_string())),
] ]
.into_iter(), .into_iter().collect::<Params>()
)
}; };
let mut scope = Scope::new(); let mut scope = Scope::new();
scope.insert("var1", ExtensionOutput::Single("hello world".to_string())); scope.insert("var1", ExtensionOutput::Single("hello world".to_string()));
@ -367,13 +358,12 @@ mod tests {
fn invalid_command() { fn invalid_command() {
let extension = ShellExtension::new(&PathBuf::new()); let extension = ShellExtension::new(&PathBuf::new());
let param = Params::from_iter( let param =
vec![( vec![(
"cmd".to_string(), "cmd".to_string(),
Value::String("nonexistentcommand".to_string()), Value::String("nonexistentcommand".to_string()),
)] )]
.into_iter(), .into_iter().collect::<Params>();
);
assert!(matches!( assert!(matches!(
extension.calculate(&Default::default(), &Default::default(), &param), extension.calculate(&Default::default(), &Default::default(), &param),
ExtensionResult::Error(_) ExtensionResult::Error(_)
@ -386,7 +376,7 @@ mod tests {
let extension = ShellExtension::new(&PathBuf::new()); let extension = ShellExtension::new(&PathBuf::new());
let param = 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::<Params>();
assert!(matches!( assert!(matches!(
extension.calculate(&Default::default(), &Default::default(), &param), extension.calculate(&Default::default(), &Default::default(), &param),
ExtensionResult::Error(_) ExtensionResult::Error(_)
@ -398,13 +388,11 @@ mod tests {
fn ignore_error() { fn ignore_error() {
let extension = ShellExtension::new(&PathBuf::new()); let extension = ShellExtension::new(&PathBuf::new());
let param = Params::from_iter( let param = vec![
vec![
("cmd".to_string(), Value::String("exit 1".to_string())), ("cmd".to_string(), Value::String("exit 1".to_string())),
("ignore_error".to_string(), Value::Bool(true)), ("ignore_error".to_string(), Value::Bool(true)),
] ]
.into_iter(), .into_iter().collect::<Params>();
);
assert_eq!( assert_eq!(
extension extension
.calculate(&Default::default(), &Default::default(), &param) .calculate(&Default::default(), &Default::default(), &param)

View File

@ -321,9 +321,7 @@ mod tests {
.map(|(name, value)| Variable { .map(|(name, value)| Variable {
name: (*name).to_string(), name: (*name).to_string(),
var_type: "mock".to_string(), var_type: "mock".to_string(),
params: Params::from_iter( params: vec![("echo".to_string(), Value::String((*value).to_string()))].into_iter().collect::<Params>(),
vec![("echo".to_string(), Value::String((*value).to_string()))].into_iter(),
),
}) })
.collect(); .collect();
Template { Template {
@ -432,9 +430,7 @@ mod tests {
Variable { Variable {
name: "local".to_string(), name: "local".to_string(),
var_type: "mock".to_string(), var_type: "mock".to_string(),
params: Params::from_iter( params: vec![("echo".to_string(), Value::String("Bob".to_string()))].into_iter().collect::<Params>(),
vec![("echo".to_string(), Value::String("Bob".to_string()))].into_iter(),
),
}, },
Variable { Variable {
name: "var".to_string(), name: "var".to_string(),
@ -470,9 +466,7 @@ mod tests {
vars: vec![Variable { vars: vec![Variable {
name: "var".to_string(), name: "var".to_string(),
var_type: "match".to_string(), var_type: "match".to_string(),
params: Params::from_iter( params: vec![("trigger".to_string(), Value::String("nested".to_string()))].into_iter().collect::<Params>(),
vec![("trigger".to_string(), Value::String("nested".to_string()))].into_iter(),
),
}], }],
..Default::default() ..Default::default()
}; };
@ -500,9 +494,7 @@ mod tests {
vars: vec![Variable { vars: vec![Variable {
name: "var".to_string(), name: "var".to_string(),
var_type: "match".to_string(), var_type: "match".to_string(),
params: Params::from_iter( params: vec![("trigger".to_string(), Value::String("nested".to_string()))].into_iter().collect::<Params>(),
vec![("trigger".to_string(), Value::String("nested".to_string()))].into_iter(),
),
}], }],
..Default::default() ..Default::default()
}; };
@ -524,7 +516,7 @@ mod tests {
vars: vec![Variable { vars: vec![Variable {
name: "var".to_string(), name: "var".to_string(),
var_type: "mock".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::<Params>(),
}], }],
..Default::default() ..Default::default()
}; };
@ -540,7 +532,7 @@ mod tests {
vars: vec![Variable { vars: vec![Variable {
name: "var".to_string(), name: "var".to_string(),
var_type: "mock".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::<Params>(),
}], }],
..Default::default() ..Default::default()
}; };