mirror of
https://github.com/nushell/nushell.git
synced 2024-11-25 09:53:43 +01:00
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:
parent
cb754befe9
commit
78b4472b32
@ -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!(
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user