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

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

View File

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

View File

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

View File

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

View File

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

View File

@ -265,7 +265,8 @@ mod tests {
),
("trim".to_string(), Value::Bool(false)),
]
.into_iter().collect::<Params>();
.into_iter()
.collect::<Params>();
if cfg!(target_os = "windows") {
assert_eq!(
extension
@ -293,7 +294,8 @@ mod tests {
"cmd".to_string(),
Value::String("echo \"hello world\"".to_string()),
)]
.into_iter().collect::<Params>();
.into_iter()
.collect::<Params>();
assert_eq!(
extension
@ -313,7 +315,8 @@ mod tests {
"cmd".to_string(),
Value::String("echo \"hello world\" | cat".to_string()),
)]
.into_iter().collect::<Params>();
.into_iter()
.collect::<Params>();
assert_eq!(
extension
.calculate(&Default::default(), &Default::default(), &param)
@ -332,7 +335,8 @@ mod tests {
"cmd".to_string(),
Value::String("echo $ESPANSO_VAR1".to_string()),
)]
.into_iter().collect::<Params>()
.into_iter()
.collect::<Params>()
} else {
vec![
(
@ -341,7 +345,8 @@ mod tests {
),
("shell".to_string(), Value::String("cmd".to_string())),
]
.into_iter().collect::<Params>()
.into_iter()
.collect::<Params>()
};
let mut scope = Scope::new();
scope.insert("var1", ExtensionOutput::Single("hello world".to_string()));
@ -358,12 +363,12 @@ mod tests {
fn invalid_command() {
let extension = ShellExtension::new(&PathBuf::new());
let param =
vec![(
let param = vec![(
"cmd".to_string(),
Value::String("nonexistentcommand".to_string()),
)]
.into_iter().collect::<Params>();
.into_iter()
.collect::<Params>();
assert!(matches!(
extension.calculate(&Default::default(), &Default::default(), &param),
ExtensionResult::Error(_)
@ -375,8 +380,9 @@ mod tests {
fn exit_error() {
let extension = ShellExtension::new(&PathBuf::new());
let param =
vec![("cmd".to_string(), Value::String("exit 1".to_string()))].into_iter().collect::<Params>();
let param = vec![("cmd".to_string(), Value::String("exit 1".to_string()))]
.into_iter()
.collect::<Params>();
assert!(matches!(
extension.calculate(&Default::default(), &Default::default(), &param),
ExtensionResult::Error(_)
@ -392,7 +398,8 @@ mod tests {
("cmd".to_string(), Value::String("exit 1".to_string())),
("ignore_error".to_string(), Value::Bool(true)),
]
.into_iter().collect::<Params>();
.into_iter()
.collect::<Params>();
assert_eq!(
extension
.calculate(&Default::default(), &Default::default(), &param)

View File

@ -321,7 +321,9 @@ mod tests {
.map(|(name, value)| Variable {
name: (*name).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();
Template {
@ -430,7 +432,9 @@ mod tests {
Variable {
name: "local".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 {
name: "var".to_string(),
@ -466,7 +470,9 @@ mod tests {
vars: vec![Variable {
name: "var".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()
};
@ -494,7 +500,9 @@ mod tests {
vars: vec![Variable {
name: "var".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()
};
@ -516,7 +524,9 @@ mod tests {
vars: vec![Variable {
name: "var".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()
};
@ -532,7 +542,9 @@ mod tests {
vars: vec![Variable {
name: "var".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()
};

View File

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