From 49f377688a88387010aea0a2781bbb6a69bf67d3 Mon Sep 17 00:00:00 2001 From: Solomon Date: Fri, 13 Dec 2024 05:55:57 -0700 Subject: [PATCH] support raw strings in match patterns (#14573) Fixes #14554 # User-Facing Changes Raw strings are now supported in match patterns: ```diff match "foo" { r#'foo'# => true, _ => false } -false +true ``` --- crates/nu-command/tests/commands/match_.rs | 9 +++++++++ crates/nu-protocol/src/engine/pattern_match.rs | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/nu-command/tests/commands/match_.rs b/crates/nu-command/tests/commands/match_.rs index 23e4450d2b..5d41b3291a 100644 --- a/crates/nu-command/tests/commands/match_.rs +++ b/crates/nu-command/tests/commands/match_.rs @@ -140,6 +140,15 @@ fn match_constant_7() { assert_eq!(actual.out, "success"); } +#[test] +fn match_constant_8() { + let actual = + nu!(r#"match "foo" { r#'foo'# => { print "success" }, _ => { print "failure" } }"#); + // Make sure we don't see any of these values in the output + // As we do not auto-print loops anymore + assert_eq!(actual.out, "success"); +} + #[test] fn match_null() { let actual = nu!(r#"match null { null => { print "success"}, _ => { print "failure" }}"#); diff --git a/crates/nu-protocol/src/engine/pattern_match.rs b/crates/nu-protocol/src/engine/pattern_match.rs index 3284527cc6..32c34d22d3 100644 --- a/crates/nu-protocol/src/engine/pattern_match.rs +++ b/crates/nu-protocol/src/engine/pattern_match.rs @@ -128,7 +128,7 @@ impl Matcher for Pattern { false } } - Expr::String(x) => { + Expr::String(x) | Expr::RawString(x) => { if let Value::String { val, .. } = &value { x == val } else {