From ccd00cb7061aa0e0b6c8d65c21f8a2c3a9580da2 Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Sat, 5 Jun 2021 15:31:55 +0200 Subject: [PATCH] feat(render): add alias parameter to echo extension to support legacy dummy type --- espanso-render/src/extension/echo.rs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/espanso-render/src/extension/echo.rs b/espanso-render/src/extension/echo.rs index 69decbd..83b0764 100644 --- a/espanso-render/src/extension/echo.rs +++ b/espanso-render/src/extension/echo.rs @@ -20,18 +20,28 @@ use crate::{Extension, ExtensionOutput, ExtensionResult, Params, Value}; use thiserror::Error; -pub struct EchoExtension {} +pub struct EchoExtension { + alias: String +} #[allow(clippy::new_without_default)] impl EchoExtension { pub fn new() -> Self { - Self {} + Self { + alias: "echo".to_string(), + } + } + + pub fn new_with_alias(alias: &str) -> Self { + Self { + alias: alias.to_string(), + } } } impl Extension for EchoExtension { fn name(&self) -> &str { - "echo" + self.alias.as_str() } fn calculate( @@ -81,4 +91,13 @@ mod tests { let param = Params::new(); assert!(matches!(extension.calculate(&Default::default(), &Default::default(), ¶m), ExtensionResult::Error(_))); } + + #[test] + fn alias() { + let extension_with_alias = EchoExtension::new_with_alias("dummy"); + let extension = EchoExtension::new(); + + assert_eq!(extension.name(), "echo"); + assert_eq!(extension_with_alias.name(), "dummy"); + } }