example unit test

This commit is contained in:
Fernando Herrera
2021-10-09 14:10:10 +01:00
parent 5021d61800
commit e3e4ae0591
10 changed files with 285 additions and 25 deletions

View File

@ -1,7 +1,7 @@
use nu_engine::eval_expression;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EvaluationContext};
use nu_protocol::{ShellError, Signature, SyntaxShape, Value};
use nu_protocol::{Example, ShellError, Signature, Span, SyntaxShape, Value};
pub struct BuildString;
@ -18,6 +18,27 @@ impl Command for BuildString {
Signature::build("build-string").rest("rest", SyntaxShape::String, "list of string")
}
fn examples(&self) -> Vec<Example> {
vec![
Example {
example: "build-string a b c",
description: "Builds a string from letters a b c",
result: Some(Value::String {
val: "abc".to_string(),
span: Span::unknown(),
}),
},
Example {
example: "build-string (1 + 2) = one ' ' plus ' ' two",
description: "Builds a string from letters a b c",
result: Some(Value::String {
val: "3=one plus two".to_string(),
span: Span::unknown(),
}),
},
]
}
fn run(
&self,
context: &EvaluationContext,
@ -36,3 +57,15 @@ impl Command for BuildString {
})
}
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_examples() {
use crate::test_examples;
test_examples(BuildString {})
}
}