mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 19:37:45 +02:00
Rows and values can be checked for emptiness. Allows to set a value if desired. (#1665)
This commit is contained in:
committed by
GitHub
parent
a62745eefb
commit
80025ea684
96
crates/nu-cli/tests/commands/is_empty.rs
Normal file
96
crates/nu-cli/tests/commands/is_empty.rs
Normal file
@ -0,0 +1,96 @@
|
||||
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn adds_value_provided_if_column_is_empty() {
|
||||
Playground::setup("is_empty_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"likes.csv",
|
||||
r#"
|
||||
first_name,last_name,rusty_at,likes
|
||||
Andrés,Robalino,10/11/2013,1
|
||||
Jonathan,Turner,10/12/2013,1
|
||||
Jason,Gedge,10/11/2013,1
|
||||
Yehuda,Katz,10/11/2013,
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open likes.csv
|
||||
| empty? likes 1
|
||||
| get likes
|
||||
| sum
|
||||
| echo $it
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual, "4");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn adds_value_provided_for_columns_that_are_empty() {
|
||||
Playground::setup("is_empty_test_2", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"checks.json",
|
||||
r#"
|
||||
[
|
||||
{"boost": 1, "check": []},
|
||||
{"boost": 1, "check": ""},
|
||||
{"boost": 1, "check": {}},
|
||||
{"boost": null, "check": ["" {} [] ""]}
|
||||
]
|
||||
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open checks.json
|
||||
| empty? boost check 1
|
||||
| get boost check
|
||||
| sum
|
||||
| echo $it
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual, "8");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn value_emptiness_check() {
|
||||
Playground::setup("is_empty_test_3", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"checks.json",
|
||||
r#"
|
||||
{
|
||||
"are_empty": [
|
||||
{"check": []},
|
||||
{"check": ""},
|
||||
{"check": {}},
|
||||
{"check": ["" {} [] ""]}
|
||||
]
|
||||
}
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open checks.json
|
||||
| get are_empty.check
|
||||
| empty?
|
||||
| where $it
|
||||
| count
|
||||
| echo $it
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual, "4");
|
||||
})
|
||||
}
|
@ -16,6 +16,7 @@ mod group_by;
|
||||
mod headers;
|
||||
mod histogram;
|
||||
mod insert;
|
||||
mod is_empty;
|
||||
mod last;
|
||||
mod lines;
|
||||
mod ls;
|
||||
|
Reference in New Issue
Block a user