mirror of
https://github.com/nushell/nushell
synced 2025-01-27 20:35:43 +00:00
Add accidentally missing tests of some command examples (#7035)
* Add missing tests of examples * Fix broken tests due to externals not being in working set * Comment out `where` test due to bug
This commit is contained in:
parent
8a812cf03c
commit
5ee7847035
3 changed files with 62 additions and 24 deletions
|
@ -46,14 +46,14 @@ impl Command for Length {
|
||||||
fn examples(&self) -> Vec<Example> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
vec![
|
vec![
|
||||||
Example {
|
Example {
|
||||||
description: "Count the number of entries in a list",
|
description: "Count the number of items in a list",
|
||||||
example: "echo [1 2 3 4 5] | length",
|
example: "[1 2 3 4 5] | length",
|
||||||
result: Some(Value::test_int(5)),
|
result: Some(Value::test_int(5)),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
description: "Count the number of columns in the calendar table",
|
description: "Count the number of columns in a table",
|
||||||
example: "cal | length -c",
|
example: "[{columnA: A0 columnB: B0}] | length -c",
|
||||||
result: Some(Value::test_int(7)),
|
result: Some(Value::test_int(2)),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -122,3 +122,15 @@ fn getcol(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_examples() {
|
||||||
|
use crate::test_examples;
|
||||||
|
|
||||||
|
test_examples(Length {})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -129,7 +129,7 @@ impl Command for Lines {
|
||||||
fn examples(&self) -> Vec<Example> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
vec![Example {
|
vec![Example {
|
||||||
description: "Split multi-line string into lines",
|
description: "Split multi-line string into lines",
|
||||||
example: "echo $'two(char nl)lines' | lines",
|
example: r#"echo $"two\nlines" | lines"#,
|
||||||
result: Some(Value::List {
|
result: Some(Value::List {
|
||||||
vals: vec![Value::test_string("two"), Value::test_string("lines")],
|
vals: vec![Value::test_string("two"), Value::test_string("lines")],
|
||||||
span: Span::test_data(),
|
span: Span::test_data(),
|
||||||
|
@ -252,3 +252,15 @@ impl RawStreamLinesAdapter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_examples() {
|
||||||
|
use crate::test_examples;
|
||||||
|
|
||||||
|
test_examples(Lines {})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ use nu_protocol::ast::Call;
|
||||||
use nu_protocol::engine::{CaptureBlock, Command, EngineState, Stack};
|
use nu_protocol::engine::{CaptureBlock, Command, EngineState, Stack};
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
Category, Example, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, ShellError,
|
Category, Example, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, ShellError,
|
||||||
Signature, Span, SyntaxShape, Value,
|
Signature, SyntaxShape, Value,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -238,23 +238,37 @@ impl Command for Where {
|
||||||
example: "ls | where modified >= (date now) - 2wk",
|
example: "ls | where modified >= (date now) - 2wk",
|
||||||
result: None,
|
result: None,
|
||||||
},
|
},
|
||||||
Example {
|
// TODO: This should work but does not. (Note that `Let` must be present in the working_set in `example_test.rs`).
|
||||||
description: "Get all numbers above 3 with an existing block condition",
|
// See https://github.com/nushell/nushell/issues/7034
|
||||||
example: "let a = {$in > 3}; [1, 2, 5, 6] | where -b $a",
|
// Example {
|
||||||
result: Some(Value::List {
|
// description: "Get all numbers above 3 with an existing block condition",
|
||||||
vals: vec![
|
// example: "let a = {$in > 3}; [1, 2, 5, 6] | where -b $a",
|
||||||
Value::Int {
|
// result: Some(Value::List {
|
||||||
val: 5,
|
// vals: vec![
|
||||||
span: Span::test_data(),
|
// Value::Int {
|
||||||
},
|
// val: 5,
|
||||||
Value::Int {
|
// span: Span::test_data(),
|
||||||
val: 6,
|
// },
|
||||||
span: Span::test_data(),
|
// Value::Int {
|
||||||
},
|
// val: 6,
|
||||||
],
|
// span: Span::test_data(),
|
||||||
span: Span::test_data(),
|
// },
|
||||||
}),
|
// ],
|
||||||
},
|
// span: Span::test_data(),
|
||||||
|
// }),
|
||||||
|
// },
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_examples() {
|
||||||
|
use crate::test_examples;
|
||||||
|
|
||||||
|
test_examples(Where {})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue