feat(render): add alias parameter to echo extension to support legacy dummy type

This commit is contained in:
Federico Terzi 2021-06-05 15:31:55 +02:00
parent 149d9ec8a0
commit ccd00cb706

View File

@ -20,18 +20,28 @@
use crate::{Extension, ExtensionOutput, ExtensionResult, Params, Value}; use crate::{Extension, ExtensionOutput, ExtensionResult, Params, Value};
use thiserror::Error; use thiserror::Error;
pub struct EchoExtension {} pub struct EchoExtension {
alias: String
}
#[allow(clippy::new_without_default)] #[allow(clippy::new_without_default)]
impl EchoExtension { impl EchoExtension {
pub fn new() -> Self { 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 { impl Extension for EchoExtension {
fn name(&self) -> &str { fn name(&self) -> &str {
"echo" self.alias.as_str()
} }
fn calculate( fn calculate(
@ -81,4 +91,13 @@ mod tests {
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]
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");
}
} }