mirror of
https://github.com/nushell/nushell
synced 2024-12-28 22:13:10 +00:00
command split
This commit is contained in:
parent
41366f6cc4
commit
8756e88e3c
2 changed files with 44 additions and 41 deletions
|
@ -7,7 +7,7 @@ use nu_protocol::{
|
||||||
Value,
|
Value,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::From;
|
use super::{From, Split};
|
||||||
|
|
||||||
pub fn test_examples(cmd: impl Command + 'static) {
|
pub fn test_examples(cmd: impl Command + 'static) {
|
||||||
let examples = cmd.examples();
|
let examples = cmd.examples();
|
||||||
|
@ -15,10 +15,11 @@ pub fn test_examples(cmd: impl Command + 'static) {
|
||||||
|
|
||||||
let delta = {
|
let delta = {
|
||||||
// Base functions that are needed for testing
|
// Base functions that are needed for testing
|
||||||
// Try to keep this working set as small to keep tests running as fast as possible
|
// Try to keep this working set small to keep tests running as fast as possible
|
||||||
let engine_state = engine_state.borrow();
|
let engine_state = engine_state.borrow();
|
||||||
let mut working_set = StateWorkingSet::new(&*engine_state);
|
let mut working_set = StateWorkingSet::new(&*engine_state);
|
||||||
working_set.add_decl(Box::new(From));
|
working_set.add_decl(Box::new(From));
|
||||||
|
working_set.add_decl(Box::new(Split));
|
||||||
|
|
||||||
// Adding the command that is being tested to the working set
|
// Adding the command that is being tested to the working set
|
||||||
working_set.add_decl(Box::new(cmd));
|
working_set.add_decl(Box::new(cmd));
|
||||||
|
|
|
@ -19,6 +19,38 @@ impl Command for SubCommand {
|
||||||
"splits a string's characters into separate rows"
|
"splits a string's characters into separate rows"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn examples(&self) -> Vec<Example> {
|
||||||
|
vec![Example {
|
||||||
|
description: "Split the string's characters into separate rows",
|
||||||
|
example: "'hello' | split chars",
|
||||||
|
result: Some(Value::List {
|
||||||
|
vals: vec![
|
||||||
|
Value::String {
|
||||||
|
val: "h".into(),
|
||||||
|
span: Span::unknown(),
|
||||||
|
},
|
||||||
|
Value::String {
|
||||||
|
val: "e".into(),
|
||||||
|
span: Span::unknown(),
|
||||||
|
},
|
||||||
|
Value::String {
|
||||||
|
val: "l".into(),
|
||||||
|
span: Span::unknown(),
|
||||||
|
},
|
||||||
|
Value::String {
|
||||||
|
val: "l".into(),
|
||||||
|
span: Span::unknown(),
|
||||||
|
},
|
||||||
|
Value::String {
|
||||||
|
val: "o".into(),
|
||||||
|
span: Span::unknown(),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
span: Span::unknown(),
|
||||||
|
}),
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
|
||||||
fn run(
|
fn run(
|
||||||
&self,
|
&self,
|
||||||
_context: &EvaluationContext,
|
_context: &EvaluationContext,
|
||||||
|
@ -27,35 +59,6 @@ impl Command for SubCommand {
|
||||||
) -> Result<nu_protocol::Value, nu_protocol::ShellError> {
|
) -> Result<nu_protocol::Value, nu_protocol::ShellError> {
|
||||||
split_chars(call, input)
|
split_chars(call, input)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn examples(&self) -> Vec<Example> {
|
|
||||||
vec![Example {
|
|
||||||
description: "Split the string's characters into separate rows",
|
|
||||||
example: "echo 'hello' | split chars",
|
|
||||||
result: Some(vec![
|
|
||||||
Value::String {
|
|
||||||
val: "h".into(),
|
|
||||||
span: Span::unknown(),
|
|
||||||
},
|
|
||||||
Value::String {
|
|
||||||
val: "e".into(),
|
|
||||||
span: Span::unknown(),
|
|
||||||
},
|
|
||||||
Value::String {
|
|
||||||
val: "l".into(),
|
|
||||||
span: Span::unknown(),
|
|
||||||
},
|
|
||||||
Value::String {
|
|
||||||
val: "l".into(),
|
|
||||||
span: Span::unknown(),
|
|
||||||
},
|
|
||||||
Value::String {
|
|
||||||
val: "o".into(),
|
|
||||||
span: Span::unknown(),
|
|
||||||
},
|
|
||||||
]),
|
|
||||||
}]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn split_chars(call: &Call, input: Value) -> Result<nu_protocol::Value, nu_protocol::ShellError> {
|
fn split_chars(call: &Call, input: Value) -> Result<nu_protocol::Value, nu_protocol::ShellError> {
|
||||||
|
@ -86,15 +89,14 @@ fn split_chars_helper(v: &Value, name: Span) -> Vec<Value> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[cfg(test)]
|
#[cfg(test)]
|
||||||
// mod tests {
|
mod test {
|
||||||
// use super::ShellError;
|
use super::*;
|
||||||
// use super::SubCommand;
|
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn examples_work_as_expected() -> Result<(), ShellError> {
|
fn test_examples() {
|
||||||
// use crate::examples::test as test_examples;
|
use crate::test_examples;
|
||||||
|
|
||||||
// test_examples(SubCommand {})
|
test_examples(SubCommand {})
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
Loading…
Reference in a new issue