add $nothing and tests (#2995)

This commit is contained in:
Darren Schroeder 2021-02-02 00:23:12 -06:00 committed by GitHub
parent 2c52144f41
commit fd41fa31d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 0 deletions

View File

@ -253,6 +253,11 @@ fn evaluate_reference(name: &str, ctx: &EvaluationContext, tag: Tag) -> Result<V
)),
},
"$nothing" => Ok(Value {
value: UntaggedValue::nothing(),
tag,
}),
x => match ctx.scope.get_var(x) {
Some(v) => Ok(v),
None => Err(ShellError::labeled_error(

View File

@ -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");
}