From 89225cf55c323baefea50f68067825c23743e957 Mon Sep 17 00:00:00 2001 From: Antonio Natilla Date: Mon, 1 Nov 2021 09:37:07 +0100 Subject: [PATCH] Adding examples and test for Echo --- crates/nu-command/src/core_commands/echo.rs | 29 ++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/crates/nu-command/src/core_commands/echo.rs b/crates/nu-command/src/core_commands/echo.rs index af9fd57b0d..be921b62d8 100644 --- a/crates/nu-command/src/core_commands/echo.rs +++ b/crates/nu-command/src/core_commands/echo.rs @@ -1,7 +1,6 @@ use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{PipelineData, ShellError, Signature, SyntaxShape}; -//TODO: add Example +use nu_protocol::{Example, PipelineData, ShellError, Signature, SyntaxShape, Value}; #[derive(Clone)] pub struct Echo; @@ -28,5 +27,29 @@ impl Command for Echo { ) -> Result { Ok(input) } - //TODO: implement fn examples(&self) -> Vec + + fn examples(&self) -> Vec { + 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 {}) + } }