diff --git a/crates/nu-command/src/example_test.rs b/crates/nu-command/src/example_test.rs index 15228941a2..1900d5aec4 100644 --- a/crates/nu-command/src/example_test.rs +++ b/crates/nu-command/src/example_test.rs @@ -9,8 +9,8 @@ pub fn test_examples(cmd: impl Command + 'static) { #[cfg(test)] mod test_examples { use super::super::{ - Ansi, Date, Echo, From, If, Into, LetEnv, Math, MathEuler, MathPi, MathRound, Path, Random, - Split, SplitColumn, SplitRow, Str, StrJoin, StrLength, StrReplace, Url, Wrap, + Ansi, Date, Echo, From, If, Into, Let, LetEnv, Math, MathEuler, MathPi, MathRound, Path, + Random, Split, SplitColumn, SplitRow, Str, StrJoin, StrLength, StrReplace, Url, Wrap, }; use crate::{Break, Mut, To}; use itertools::Itertools; @@ -60,6 +60,7 @@ mod test_examples { // Base functions that are needed for testing // Try to keep this working set small to keep tests running as fast as possible let mut working_set = StateWorkingSet::new(&*engine_state); + working_set.add_decl(Box::new(Let)); working_set.add_decl(Box::new(Str)); working_set.add_decl(Box::new(StrJoin)); working_set.add_decl(Box::new(StrLength)); diff --git a/crates/nu-command/src/filters/where_.rs b/crates/nu-command/src/filters/where_.rs index 19e91117ce..66f1bd69f6 100644 --- a/crates/nu-command/src/filters/where_.rs +++ b/crates/nu-command/src/filters/where_.rs @@ -49,7 +49,7 @@ impl Command for Where { call: &Call, input: PipelineData, ) -> Result { - if let Ok(Some(capture_block)) = call.get_flag::(engine_state, stack, "block") { + if let Ok(Some(capture_block)) = call.get_flag::(engine_state, stack, "closure") { let metadata = input.metadata(); let ctrlc = engine_state.ctrlc.clone(); let engine_state = engine_state.clone(); @@ -303,6 +303,14 @@ impl Command for Where { span: Span::test_data(), }), }, + Example { + description: "Filter items of a list according to a stored condition", + example: "let cond = {|x| $x > 1}; [1 2] | where -b $cond", + result: Some(Value::List { + vals: vec![Value::test_int(2)], + span: Span::test_data(), + }), + }, Example { description: "List all files in the current directory with sizes greater than 2kb", example: "ls | where size > 2kb",