feat(render): add alias parameter to echo extension to support legacy dummy type
This commit is contained in:
parent
149d9ec8a0
commit
ccd00cb706
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user