mirror of
https://github.com/nushell/nushell.git
synced 2025-08-11 07:44:14 +02:00
example unit test
This commit is contained in:
@ -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 {})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user