Support pattern matching null literals (#10829)

# Description
Support pattern matching against the `null` literal.  Fixes #10799 

### Before
```nushell
> match null { null => "success", _ => "failure" }
failure
```

### After
```nushell
> match null { null => "success", _ => "failure" }
success
```

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->
Users can pattern match against a `null` literal.
This commit is contained in:
Hudson Clark 2023-10-24 18:30:45 -04:00 committed by GitHub
parent cb754befe9
commit 78b4472b32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View File

@ -132,6 +132,12 @@ fn match_constant_7() {
assert_eq!(actual.out, "success");
}
#[test]
fn match_null() {
let actual = nu!(r#"match null { null => { print "success"}, _ => { print "failure" }}"#);
assert_eq!(actual.out, "success");
}
#[test]
fn match_or_pattern() {
let actual = nu!(

View File

@ -96,6 +96,9 @@ impl Matcher for Pattern {
Pattern::Value(pattern_value) => {
// TODO: Fill this out with the rest of them
match &pattern_value.expr {
Expr::Nothing => {
matches!(value, Value::Nothing { .. })
}
Expr::Int(x) => {
if let Value::Int { val, .. } = &value {
x == val