From b796cda060b904fe8499b198395b1cd4b5ecf850 Mon Sep 17 00:00:00 2001 From: Stefan Holderbach Date: Mon, 6 Feb 2023 11:01:08 +0100 Subject: [PATCH] Test return in `reduce` closure from #7961 (#7973) # Description Functionality added by @nabacg in #7961 already h/t @YuriGeinishO for the example in #7933 Closes #7933 # User-Facing Changes None # Tests + Formatting +1 end to end example --- crates/nu-command/tests/commands/reduce.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/crates/nu-command/tests/commands/reduce.rs b/crates/nu-command/tests/commands/reduce.rs index b87d6af19..35bdc394f 100644 --- a/crates/nu-command/tests/commands/reduce.rs +++ b/crates/nu-command/tests/commands/reduce.rs @@ -46,6 +46,25 @@ fn reduce_rows_example() { assert_eq!(actual.out, "14.8"); } +#[test] +fn reduce_with_return_in_closure() { + let actual = nu!( + cwd: ".", pipeline( + r#" + [1, 2] | reduce --fold null { |it, state| + if $it == 1 { + return 10 + }; + return ($it * $state) + } + "# + ) + ); + + assert_eq!(actual.out, "20"); + assert!(actual.err.is_empty()); +} + #[test] fn reduce_enumerate_example() { let actual = nu!(