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");
|
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]
|
#[test]
|
||||||
fn match_or_pattern() {
|
fn match_or_pattern() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
|
|
|
@ -96,6 +96,9 @@ impl Matcher for Pattern {
|
||||||
Pattern::Value(pattern_value) => {
|
Pattern::Value(pattern_value) => {
|
||||||
// TODO: Fill this out with the rest of them
|
// TODO: Fill this out with the rest of them
|
||||||
match &pattern_value.expr {
|
match &pattern_value.expr {
|
||||||
|
Expr::Nothing => {
|
||||||
|
matches!(value, Value::Nothing { .. })
|
||||||
|
}
|
||||||
Expr::Int(x) => {
|
Expr::Int(x) => {
|
||||||
if let Value::Int { val, .. } = &value {
|
if let Value::Int { val, .. } = &value {
|
||||||
x == val
|
x == val
|
||||||
|
|
Loading…
Reference in New Issue
Block a user