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)]
impl <'a> ClipboardExtension<'a> {
impl<'a> ClipboardExtension<'a> {
pub fn new(provider: &'a dyn ClipboardProvider) -> Self {
Self { provider }
}
}
impl <'a> Extension for ClipboardExtension<'a> {
impl<'a> Extension for ClipboardExtension<'a> {
fn name(&self) -> &str {
"clipboard"
}

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)
@ -100,10 +102,11 @@ mod tests {
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())),
("offset".to_string(), Value::Number(Number::Integer(3600))),
]
.into_iter().collect::<Params>();
("format".to_string(), Value::String("%H:%M:%S".to_string())),
("offset".to_string(), Value::Number(Number::Integer(3600))),
]
.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;
mod util;
pub mod script;
pub mod shell;
mod util;

View File

@ -77,14 +77,15 @@ mod tests {
let extension = RandomExtension::new();
let param = vec![(
"choices".to_string(),
Value::Array(vec![
Value::String("first".to_string()),
Value::String("second".to_string()),
Value::String("third".to_string()),
]),
)]
.into_iter().collect::<Params>();
"choices".to_string(),
Value::Array(vec![
Value::String("first".to_string()),
Value::String("second".to_string()),
Value::String("third".to_string()),
]),
)]
.into_iter()
.collect::<Params>();
assert!(matches!(
extension
.calculate(&Default::default(), &Default::default(), &param)

View File

@ -192,13 +192,14 @@ mod tests {
let extension = get_extension();
let param = vec![(
"args".to_string(),
Value::Array(vec![
Value::String("echo".to_string()),
Value::String("hello world".to_string()),
]),
)]
.into_iter().collect::<Params>();
"args".to_string(),
Value::Array(vec![
Value::String("echo".to_string()),
Value::String("hello world".to_string()),
]),
)]
.into_iter()
.collect::<Params>();
assert_eq!(
extension
.calculate(&Default::default(), &Default::default(), &param)
@ -214,16 +215,17 @@ mod tests {
let extension = get_extension();
let param = vec![
(
"args".to_string(),
Value::Array(vec![
Value::String("echo".to_string()),
Value::String("hello world".to_string()),
]),
),
("trim".to_string(), Value::Bool(false)),
]
.into_iter().collect::<Params>();
(
"args".to_string(),
Value::Array(vec![
Value::String("echo".to_string()),
Value::String("hello world".to_string()),
]),
),
("trim".to_string(), Value::Bool(false)),
]
.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![
(
"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>();
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>();
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![
(
"args".to_string(),
Value::Array(vec![
Value::String("nonexistentcommand".to_string()),
]),
),
]
.into_iter().collect::<Params>();
let param = vec![(
"args".to_string(),
Value::Array(vec![Value::String("nonexistentcommand".to_string())]),
)]
.into_iter()
.collect::<Params>();
assert!(matches!(
extension.calculate(&Default::default(), &Default::default(), &param),
ExtensionResult::Error(_)
@ -293,18 +291,17 @@ mod tests {
#[cfg(not(target_os = "windows"))]
fn exit_error() {
let extension = get_extension();
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>();
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>();
assert!(matches!(
extension.calculate(&Default::default(), &Default::default(), &param),
ExtensionResult::Error(_)
@ -315,19 +312,20 @@ mod tests {
#[cfg(not(target_os = "windows"))]
fn ignore_error() {
let extension = get_extension();
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()),
]),
),
("ignore_error".to_string(), Value::Bool(true)),
]
.into_iter().collect::<Params>();
(
"args".to_string(),
Value::Array(vec![
Value::String("sh".to_string()),
Value::String("-c".to_string()),
Value::String("exit 1".to_string()),
]),
),
("ignore_error".to_string(), Value::Bool(true)),
]
.into_iter()
.collect::<Params>();
assert_eq!(
extension
.calculate(&Default::default(), &Default::default(), &param)

View File

@ -259,13 +259,14 @@ mod tests {
let extension = ShellExtension::new(&PathBuf::new());
let param = vec![
(
"cmd".to_string(),
Value::String("echo \"hello world\"".to_string()),
),
("trim".to_string(), Value::Bool(false)),
]
.into_iter().collect::<Params>();
(
"cmd".to_string(),
Value::String("echo \"hello world\"".to_string()),
),
("trim".to_string(), Value::Bool(false)),
]
.into_iter()
.collect::<Params>();
if cfg!(target_os = "windows") {
assert_eq!(
extension
@ -290,11 +291,12 @@ mod tests {
let extension = ShellExtension::new(&PathBuf::new());
let param = vec![(
"cmd".to_string(),
Value::String("echo \"hello world\"".to_string()),
)]
.into_iter().collect::<Params>();
"cmd".to_string(),
Value::String("echo \"hello world\"".to_string()),
)]
.into_iter()
.collect::<Params>();
assert_eq!(
extension
.calculate(&Default::default(), &Default::default(), &param)
@ -310,10 +312,11 @@ mod tests {
let extension = ShellExtension::new(&PathBuf::new());
let param = vec![(
"cmd".to_string(),
Value::String("echo \"hello world\" | cat".to_string()),
)]
.into_iter().collect::<Params>();
"cmd".to_string(),
Value::String("echo \"hello world\" | cat".to_string()),
)]
.into_iter()
.collect::<Params>();
assert_eq!(
extension
.calculate(&Default::default(), &Default::default(), &param)
@ -328,20 +331,22 @@ mod tests {
let extension = ShellExtension::new(&PathBuf::new());
let param = if cfg!(not(target_os = "windows")) {
vec![(
"cmd".to_string(),
Value::String("echo $ESPANSO_VAR1".to_string()),
)]
.into_iter().collect::<Params>()
vec![(
"cmd".to_string(),
Value::String("echo $ESPANSO_VAR1".to_string()),
)]
.into_iter()
.collect::<Params>()
} else {
vec![
(
"cmd".to_string(),
Value::String("echo %ESPANSO_VAR1%".to_string()),
),
("shell".to_string(), Value::String("cmd".to_string())),
]
.into_iter().collect::<Params>()
(
"cmd".to_string(),
Value::String("echo %ESPANSO_VAR1%".to_string()),
),
("shell".to_string(), Value::String("cmd".to_string())),
]
.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![(
"cmd".to_string(),
Value::String("nonexistentcommand".to_string()),
)]
.into_iter().collect::<Params>();
let param = vec![(
"cmd".to_string(),
Value::String("nonexistentcommand".to_string()),
)]
.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(_)
@ -389,10 +395,11 @@ mod tests {
let extension = ShellExtension::new(&PathBuf::new());
let param = vec![
("cmd".to_string(), Value::String("exit 1".to_string())),
("ignore_error".to_string(), Value::Bool(true)),
]
.into_iter().collect::<Params>();
("cmd".to_string(), Value::String("exit 1".to_string())),
("ignore_error".to_string(), Value::Bool(true)),
]
.into_iter()
.collect::<Params>();
assert_eq!(
extension
.calculate(&Default::default(), &Default::default(), &param)

View File

@ -287,9 +287,9 @@ mod tests {
}
// If the "read" param is present, echo the value of the corresponding result in the scope
if let Some(Value::String(string)) = params.get("read") {
if let Some(ExtensionOutput::Single(value)) = scope.get(string.as_str()) {
return ExtensionResult::Success(ExtensionOutput::Single(value.to_string()));
}
if let Some(ExtensionOutput::Single(value)) = scope.get(string.as_str()) {
return ExtensionResult::Success(ExtensionOutput::Single(value.to_string()));
}
}
if params.get("abort").is_some() {
return ExtensionResult::Aborted;
@ -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();
@ -49,4 +49,4 @@ mod tests {
HashSet::from_iter(vec!["world", "greet"]),
);
}
}
}