mirror of
https://github.com/nushell/nushell.git
synced 2025-02-22 21:41:26 +01:00
Add named positionals to all (#3863)
This commit is contained in:
parent
9c016ad479
commit
f3e487e829
@ -96,7 +96,11 @@ fn all(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
let result = args.input.fold(init, move |acc, row| {
|
let result = args.input.fold(init, move |acc, row| {
|
||||||
let condition = condition.clone();
|
let condition = condition.clone();
|
||||||
let ctx = ctx.clone();
|
let ctx = ctx.clone();
|
||||||
ctx.scope.add_var("$it", row);
|
if let Some(positional) = all_args.predicate.block.params.positional.get(0) {
|
||||||
|
ctx.scope.add_var(positional.0.name(), row);
|
||||||
|
} else {
|
||||||
|
ctx.scope.add_var("$it", row);
|
||||||
|
}
|
||||||
|
|
||||||
let condition = evaluate_baseline_expr(&condition, &ctx);
|
let condition = evaluate_baseline_expr(&condition, &ctx);
|
||||||
|
|
||||||
|
@ -19,6 +19,34 @@ fn checks_all_rows_are_true() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn checks_all_rows_are_false_with_param() {
|
||||||
|
Playground::setup("all_test_1", |_, nu| {
|
||||||
|
assert_that!(
|
||||||
|
nu.pipeline(&input(
|
||||||
|
r#"
|
||||||
|
[1, 2, 3, 4] | all? { |a| $a >= 5 }
|
||||||
|
"#
|
||||||
|
)),
|
||||||
|
says().stdout("false")
|
||||||
|
);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn checks_all_rows_are_true_with_param() {
|
||||||
|
Playground::setup("all_test_1", |_, nu| {
|
||||||
|
assert_that!(
|
||||||
|
nu.pipeline(&input(
|
||||||
|
r#"
|
||||||
|
[1, 2, 3, 4] | all? { |a| $a < 5 }
|
||||||
|
"#
|
||||||
|
)),
|
||||||
|
says().stdout("true")
|
||||||
|
);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn checks_all_columns_of_a_table_is_true() {
|
fn checks_all_columns_of_a_table_is_true() {
|
||||||
Playground::setup("any_test_1", |_, nu| {
|
Playground::setup("any_test_1", |_, nu| {
|
||||||
|
Loading…
Reference in New Issue
Block a user