Adding examples and test for Echo

This commit is contained in:
Antonio Natilla 2021-11-01 09:37:07 +01:00
parent f4ed4fa7e3
commit 89225cf55c

View File

@ -1,7 +1,6 @@
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{PipelineData, ShellError, Signature, SyntaxShape}; use nu_protocol::{Example, PipelineData, ShellError, Signature, SyntaxShape, Value};
//TODO: add Example
#[derive(Clone)] #[derive(Clone)]
pub struct Echo; pub struct Echo;
@ -28,5 +27,29 @@ impl Command for Echo {
) -> Result<PipelineData, ShellError> { ) -> Result<PipelineData, ShellError> {
Ok(input) Ok(input)
} }
//TODO: implement fn examples(&self) -> Vec<Example>
fn examples(&self) -> Vec<Example> {
vec![
Example {
description: "Put a hello message in the pipeline",
example: "echo 'hello'",
result: Some(Value::test_string("hello")),
},
Example {
description: "Print the value of the special '$nu' variable",
example: "echo $nu",
result: None,
},
]
}
}
#[cfg(test)]
mod test {
#[test]
fn test_examples() {
use super::Echo;
use crate::test_examples;
test_examples(Echo {})
}
} }