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
```
This commit is contained in:
Solomon 2024-12-13 05:55:57 -07:00 committed by GitHub
parent 0b96962157
commit 49f377688a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 1 deletions

View File

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

View File

@ -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 {