style(render): fix formatting

This commit is contained in:
Federico Terzi 2021-10-06 18:41:56 +02:00
parent c10dab9e80
commit a8a5ef16a2
9 changed files with 160 additions and 135 deletions

View File

@ -29,13 +29,13 @@ pub struct ClipboardExtension<'a> {
} }
#[allow(clippy::new_without_default)] #[allow(clippy::new_without_default)]
impl <'a> ClipboardExtension<'a> { impl<'a> ClipboardExtension<'a> {
pub fn new(provider: &'a dyn ClipboardProvider) -> Self { pub fn new(provider: &'a dyn ClipboardProvider) -> Self {
Self { provider } Self { provider }
} }
} }
impl <'a> Extension for ClipboardExtension<'a> { impl<'a> Extension for ClipboardExtension<'a> {
fn name(&self) -> &str { fn name(&self) -> &str {
"clipboard" "clipboard"
} }

View File

@ -84,7 +84,9 @@ 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 = vec![("format".to_string(), Value::String("%H:%M:%S".to_string()))].into_iter().collect::<Params>(); let param = vec![("format".to_string(), Value::String("%H:%M:%S".to_string()))]
.into_iter()
.collect::<Params>();
assert_eq!( assert_eq!(
extension extension
.calculate(&Default::default(), &Default::default(), &param) .calculate(&Default::default(), &Default::default(), &param)
@ -103,7 +105,8 @@ mod tests {
("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().collect::<Params>(); .into_iter()
.collect::<Params>();
assert_eq!( assert_eq!(
extension extension
.calculate(&Default::default(), &Default::default(), &param) .calculate(&Default::default(), &Default::default(), &param)

View File

@ -21,7 +21,7 @@ use crate::{Extension, ExtensionOutput, ExtensionResult, Params, Value};
use thiserror::Error; use thiserror::Error;
pub struct EchoExtension { pub struct EchoExtension {
alias: String alias: String,
} }
#[allow(clippy::new_without_default)] #[allow(clippy::new_without_default)]
@ -72,8 +72,9 @@ mod tests {
fn echo_works_correctly() { fn echo_works_correctly() {
let extension = EchoExtension::new(); let extension = EchoExtension::new();
let param = let param = vec![("echo".to_string(), Value::String("test".to_string()))]
vec![("echo".to_string(), Value::String("test".to_string()))].into_iter().collect::<Params>(); .into_iter()
.collect::<Params>();
assert_eq!( assert_eq!(
extension extension
.calculate(&Default::default(), &Default::default(), &param) .calculate(&Default::default(), &Default::default(), &param)
@ -88,7 +89,10 @@ mod tests {
let extension = EchoExtension::new(); let extension = EchoExtension::new();
let param = Params::new(); let param = Params::new();
assert!(matches!(extension.calculate(&Default::default(), &Default::default(), &param), ExtensionResult::Error(_))); assert!(matches!(
extension.calculate(&Default::default(), &Default::default(), &param),
ExtensionResult::Error(_)
));
} }
#[test] #[test]

View File

@ -17,11 +17,11 @@
* along with espanso. If not, see <https://www.gnu.org/licenses/>. * along with espanso. If not, see <https://www.gnu.org/licenses/>.
*/ */
pub mod clipboard;
pub mod date; pub mod date;
pub mod echo; pub mod echo;
pub mod form; pub mod form;
pub mod clipboard;
pub mod shell;
pub mod script;
pub mod random; pub mod random;
pub mod script;
pub mod shell;
mod util; mod util;

View File

@ -84,7 +84,8 @@ mod tests {
Value::String("third".to_string()), Value::String("third".to_string()),
]), ]),
)] )]
.into_iter().collect::<Params>(); .into_iter()
.collect::<Params>();
assert!(matches!( assert!(matches!(
extension extension
.calculate(&Default::default(), &Default::default(), &param) .calculate(&Default::default(), &Default::default(), &param)

View File

@ -198,7 +198,8 @@ mod tests {
Value::String("hello world".to_string()), Value::String("hello world".to_string()),
]), ]),
)] )]
.into_iter().collect::<Params>(); .into_iter()
.collect::<Params>();
assert_eq!( assert_eq!(
extension extension
.calculate(&Default::default(), &Default::default(), &param) .calculate(&Default::default(), &Default::default(), &param)
@ -223,7 +224,8 @@ mod tests {
), ),
("trim".to_string(), Value::Bool(false)), ("trim".to_string(), Value::Bool(false)),
] ]
.into_iter().collect::<Params>(); .into_iter()
.collect::<Params>();
if cfg!(target_os = "windows") { if cfg!(target_os = "windows") {
assert_eq!( assert_eq!(
extension extension
@ -248,17 +250,16 @@ mod tests {
fn var_injection() { fn var_injection() {
let extension = get_extension(); let extension = get_extension();
let param = vec![ let param = vec![(
(
"args".to_string(), "args".to_string(),
Value::Array(vec![ Value::Array(vec![
Value::String("sh".to_string()), Value::String("sh".to_string()),
Value::String("-c".to_string()), Value::String("-c".to_string()),
Value::String("echo $ESPANSO_VAR1".to_string()), Value::String("echo $ESPANSO_VAR1".to_string()),
]), ]),
), )]
] .into_iter()
.into_iter().collect::<Params>(); .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!(
@ -274,15 +275,12 @@ mod tests {
fn invalid_command() { fn invalid_command() {
let extension = get_extension(); let extension = get_extension();
let param = vec![ let param = vec![(
(
"args".to_string(), "args".to_string(),
Value::Array(vec![ Value::Array(vec![Value::String("nonexistentcommand".to_string())]),
Value::String("nonexistentcommand".to_string()), )]
]), .into_iter()
), .collect::<Params>();
]
.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(_)
@ -294,17 +292,16 @@ mod tests {
fn exit_error() { fn exit_error() {
let extension = get_extension(); let extension = get_extension();
let param = vec![ let param = vec![(
(
"args".to_string(), "args".to_string(),
Value::Array(vec![ Value::Array(vec![
Value::String("sh".to_string()), Value::String("sh".to_string()),
Value::String("-c".to_string()), Value::String("-c".to_string()),
Value::String("exit 1".to_string()), Value::String("exit 1".to_string()),
]), ]),
), )]
] .into_iter()
.into_iter().collect::<Params>(); .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,7 +324,8 @@ mod tests {
), ),
("ignore_error".to_string(), Value::Bool(true)), ("ignore_error".to_string(), Value::Bool(true)),
] ]
.into_iter().collect::<Params>(); .into_iter()
.collect::<Params>();
assert_eq!( assert_eq!(
extension extension
.calculate(&Default::default(), &Default::default(), &param) .calculate(&Default::default(), &Default::default(), &param)

View File

@ -265,7 +265,8 @@ mod tests {
), ),
("trim".to_string(), Value::Bool(false)), ("trim".to_string(), Value::Bool(false)),
] ]
.into_iter().collect::<Params>(); .into_iter()
.collect::<Params>();
if cfg!(target_os = "windows") { if cfg!(target_os = "windows") {
assert_eq!( assert_eq!(
extension extension
@ -293,7 +294,8 @@ mod tests {
"cmd".to_string(), "cmd".to_string(),
Value::String("echo \"hello world\"".to_string()), Value::String("echo \"hello world\"".to_string()),
)] )]
.into_iter().collect::<Params>(); .into_iter()
.collect::<Params>();
assert_eq!( assert_eq!(
extension extension
@ -313,7 +315,8 @@ mod tests {
"cmd".to_string(), "cmd".to_string(),
Value::String("echo \"hello world\" | cat".to_string()), Value::String("echo \"hello world\" | cat".to_string()),
)] )]
.into_iter().collect::<Params>(); .into_iter()
.collect::<Params>();
assert_eq!( assert_eq!(
extension extension
.calculate(&Default::default(), &Default::default(), &param) .calculate(&Default::default(), &Default::default(), &param)
@ -332,7 +335,8 @@ mod tests {
"cmd".to_string(), "cmd".to_string(),
Value::String("echo $ESPANSO_VAR1".to_string()), Value::String("echo $ESPANSO_VAR1".to_string()),
)] )]
.into_iter().collect::<Params>() .into_iter()
.collect::<Params>()
} else { } else {
vec![ vec![
( (
@ -341,7 +345,8 @@ mod tests {
), ),
("shell".to_string(), Value::String("cmd".to_string())), ("shell".to_string(), Value::String("cmd".to_string())),
] ]
.into_iter().collect::<Params>() .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()));
@ -358,12 +363,12 @@ mod tests {
fn invalid_command() { fn invalid_command() {
let extension = ShellExtension::new(&PathBuf::new()); let extension = ShellExtension::new(&PathBuf::new());
let param = let param = vec![(
vec![(
"cmd".to_string(), "cmd".to_string(),
Value::String("nonexistentcommand".to_string()), Value::String("nonexistentcommand".to_string()),
)] )]
.into_iter().collect::<Params>(); .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(_)
@ -375,8 +380,9 @@ mod tests {
fn exit_error() { fn exit_error() {
let extension = ShellExtension::new(&PathBuf::new()); let extension = ShellExtension::new(&PathBuf::new());
let param = let param = vec![("cmd".to_string(), Value::String("exit 1".to_string()))]
vec![("cmd".to_string(), Value::String("exit 1".to_string()))].into_iter().collect::<Params>(); .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(_)
@ -392,7 +398,8 @@ mod tests {
("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().collect::<Params>(); .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,7 +321,9 @@ 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: vec![("echo".to_string(), Value::String((*value).to_string()))].into_iter().collect::<Params>(), params: vec![("echo".to_string(), Value::String((*value).to_string()))]
.into_iter()
.collect::<Params>(),
}) })
.collect(); .collect();
Template { Template {
@ -430,7 +432,9 @@ mod tests {
Variable { Variable {
name: "local".to_string(), name: "local".to_string(),
var_type: "mock".to_string(), var_type: "mock".to_string(),
params: vec![("echo".to_string(), Value::String("Bob".to_string()))].into_iter().collect::<Params>(), params: vec![("echo".to_string(), Value::String("Bob".to_string()))]
.into_iter()
.collect::<Params>(),
}, },
Variable { Variable {
name: "var".to_string(), name: "var".to_string(),
@ -466,7 +470,9 @@ 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: vec![("trigger".to_string(), Value::String("nested".to_string()))].into_iter().collect::<Params>(), params: vec![("trigger".to_string(), Value::String("nested".to_string()))]
.into_iter()
.collect::<Params>(),
}], }],
..Default::default() ..Default::default()
}; };
@ -494,7 +500,9 @@ 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: vec![("trigger".to_string(), Value::String("nested".to_string()))].into_iter().collect::<Params>(), params: vec![("trigger".to_string(), Value::String("nested".to_string()))]
.into_iter()
.collect::<Params>(),
}], }],
..Default::default() ..Default::default()
}; };
@ -516,7 +524,9 @@ 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: vec![("abort".to_string(), Value::Null)].into_iter().collect::<Params>(), params: vec![("abort".to_string(), Value::Null)]
.into_iter()
.collect::<Params>(),
}], }],
..Default::default() ..Default::default()
}; };
@ -532,7 +542,9 @@ 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: vec![("error".to_string(), Value::Null)].into_iter().collect::<Params>(), params: vec![("error".to_string(), Value::Null)]
.into_iter()
.collect::<Params>(),
}], }],
..Default::default() ..Default::default()
}; };

View File

@ -17,8 +17,8 @@
* along with espanso. If not, see <https://www.gnu.org/licenses/>. * along with espanso. If not, see <https://www.gnu.org/licenses/>.
*/ */
use std::collections::HashSet;
use super::VAR_REGEX; use super::VAR_REGEX;
use std::collections::HashSet;
pub(crate) fn get_body_variable_names(body: &str) -> HashSet<&str> { pub(crate) fn get_body_variable_names(body: &str) -> HashSet<&str> {
let mut variables = HashSet::new(); let mut variables = HashSet::new();