Fix $in in blocks given to any and all (#6951)

* Fix $in in blocks given to `any` and `all` (closes #6917)

* Fix help message typos

* Fix tests ($in doesn't work in examples?!)

* Fix formatting
This commit is contained in:
Leon
2022-11-02 04:36:54 +10:00
committed by GitHub
parent e46d610f77
commit 43aec8cdbe
5 changed files with 168 additions and 24 deletions

View File

@ -67,3 +67,43 @@ fn checks_if_all_returns_error_with_invalid_command() {
assert!(actual.err.contains("can't run executable") || actual.err.contains("did you mean"));
}
#[test]
fn works_with_1_param_blocks() {
let actual = nu!(
cwd: ".", pipeline(
r#"[1 2 3] | all {|e| print $e | true }"#
));
assert_eq!(actual.out, "123true");
}
#[test]
fn works_with_0_param_blocks() {
let actual = nu!(
cwd: ".", pipeline(
r#"[1 2 3] | all { print $in | true }"#
));
assert_eq!(actual.out, "123true");
}
#[test]
fn early_exits_with_1_param_blocks() {
let actual = nu!(
cwd: ".", pipeline(
r#"[1 2 3] | all {|e| print $e | false }"#
));
assert_eq!(actual.out, "1false");
}
#[test]
fn early_exits_with_0_param_blocks() {
let actual = nu!(
cwd: ".", pipeline(
r#"[1 2 3] | all { print $in | false }"#
));
assert_eq!(actual.out, "1false");
}

View File

@ -43,3 +43,43 @@ fn checks_if_any_returns_error_with_invalid_command() {
assert!(actual.err.contains("can't run executable") || actual.err.contains("did you mean"));
}
#[test]
fn works_with_1_param_blocks() {
let actual = nu!(
cwd: ".", pipeline(
r#"[1 2 3] | any {|e| print $e | false }"#
));
assert_eq!(actual.out, "123false");
}
#[test]
fn works_with_0_param_blocks() {
let actual = nu!(
cwd: ".", pipeline(
r#"[1 2 3] | any { print $in | false }"#
));
assert_eq!(actual.out, "123false");
}
#[test]
fn early_exits_with_1_param_blocks() {
let actual = nu!(
cwd: ".", pipeline(
r#"[1 2 3] | any {|e| print $e | true }"#
));
assert_eq!(actual.out, "1true");
}
#[test]
fn early_exits_with_0_param_blocks() {
let actual = nu!(
cwd: ".", pipeline(
r#"[1 2 3] | any { print $in | true }"#
));
assert_eq!(actual.out, "1true");
}

View File

@ -5,17 +5,57 @@ fn reports_emptiness() {
let actual = nu!(
cwd: ".", pipeline(
r#"
echo [[are_empty];
[([[check]; [[]] ])]
[([[check]; [""] ])]
[([[check]; [{}] ])]
]
| get are_empty
[[] '' {} null]
| all {
is-empty check
is-empty
}
"#
));
assert_eq!(actual.out, "true");
}
#[test]
fn reports_nonemptiness() {
let actual = nu!(
cwd: ".", pipeline(
r#"
[[1] ' ' {a:1} 0]
| any {
is-empty
}
"#
));
assert_eq!(actual.out, "false");
}
#[test]
fn reports_emptiness_by_columns() {
let actual = nu!(
cwd: ".", pipeline(
r#"
[{a:1 b:null c:null} {a:2 b:null c:null}]
| any {
is-empty b c
}
"#
));
assert_eq!(actual.out, "true");
}
#[test]
fn reports_nonemptiness_by_columns() {
let actual = nu!(
cwd: ".", pipeline(
r#"
[{a:1 b:null c:3} {a:null b:5 c:2}]
| any {
is-empty a b
}
"#
));
assert_eq!(actual.out, "false");
}