mirror of
https://github.com/nushell/nushell
synced 2024-12-29 14:33:13 +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,20 +19,12 @@ impl Command for SubCommand {
|
||||||
"splits a string's characters into separate rows"
|
"splits a string's characters into separate rows"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run(
|
|
||||||
&self,
|
|
||||||
_context: &EvaluationContext,
|
|
||||||
call: &Call,
|
|
||||||
input: Value,
|
|
||||||
) -> Result<nu_protocol::Value, nu_protocol::ShellError> {
|
|
||||||
split_chars(call, input)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn examples(&self) -> Vec<Example> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
vec![Example {
|
vec![Example {
|
||||||
description: "Split the string's characters into separate rows",
|
description: "Split the string's characters into separate rows",
|
||||||
example: "echo 'hello' | split chars",
|
example: "'hello' | split chars",
|
||||||
result: Some(vec![
|
result: Some(Value::List {
|
||||||
|
vals: vec![
|
||||||
Value::String {
|
Value::String {
|
||||||
val: "h".into(),
|
val: "h".into(),
|
||||||
span: Span::unknown(),
|
span: Span::unknown(),
|
||||||
|
@ -53,9 +45,20 @@ impl Command for SubCommand {
|
||||||
val: "o".into(),
|
val: "o".into(),
|
||||||
span: Span::unknown(),
|
span: Span::unknown(),
|
||||||
},
|
},
|
||||||
]),
|
],
|
||||||
|
span: Span::unknown(),
|
||||||
|
}),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn run(
|
||||||
|
&self,
|
||||||
|
_context: &EvaluationContext,
|
||||||
|
call: &Call,
|
||||||
|
input: Value,
|
||||||
|
) -> Result<nu_protocol::Value, nu_protocol::ShellError> {
|
||||||
|
split_chars(call, input)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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