From fd41fa31d5917310d8480a6979c1ed4e41ede3ac Mon Sep 17 00:00:00 2001 From: Darren Schroeder <343840+fdncred@users.noreply.github.com> Date: Tue, 2 Feb 2021 00:23:12 -0600 Subject: [PATCH] add $nothing and tests (#2995) --- crates/nu-engine/src/evaluate/evaluator.rs | 5 ++++ crates/nu-engine/tests/evaluate/invocation.rs | 23 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/crates/nu-engine/src/evaluate/evaluator.rs b/crates/nu-engine/src/evaluate/evaluator.rs index 9272f3974..930b2ea0a 100644 --- a/crates/nu-engine/src/evaluate/evaluator.rs +++ b/crates/nu-engine/src/evaluate/evaluator.rs @@ -253,6 +253,11 @@ fn evaluate_reference(name: &str, ctx: &EvaluationContext, tag: Tag) -> Result Ok(Value { + value: UntaggedValue::nothing(), + tag, + }), + x => match ctx.scope.get_var(x) { Some(v) => Ok(v), None => Err(ShellError::labeled_error( diff --git a/crates/nu-engine/tests/evaluate/invocation.rs b/crates/nu-engine/tests/evaluate/invocation.rs index cb695fd0c..705ddea2c 100644 --- a/crates/nu-engine/tests/evaluate/invocation.rs +++ b/crates/nu-engine/tests/evaluate/invocation.rs @@ -11,3 +11,26 @@ fn test_parse_invocation_with_range() { ); assert_eq!(actual.out, "[1,2,3]") } + +#[test] +fn create_nothing_in_table() { + let actual = nu!( + cwd: ".", + r#" + echo [[column]; [$nothing]] | to json + "# + ); + assert_eq!(actual.out, "{\"column\":null}"); +} + +#[test] +fn compare_to_nothing() { + let actual = nu!( + cwd: ".", + r#" + let f = $nothing + if $f == $nothing {echo $true} {echo $false} + "# + ); + assert_eq!(actual.out, "true"); +}