From aab31833a23668a002529034057481d166af6a70 Mon Sep 17 00:00:00 2001 From: JT <547158+jntrnr@users.noreply.github.com> Date: Sat, 25 Mar 2023 17:30:35 +1300 Subject: [PATCH] Add more pattern types to matcher (#8605) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Description Add float, string, and date patterns to matcher. This could probably use some tests 😅 # User-Facing Changes _(List of all changes that impact the user experience here. This helps us keep track of breaking changes.)_ # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --- .../nu-protocol/src/engine/pattern_match.rs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/crates/nu-protocol/src/engine/pattern_match.rs b/crates/nu-protocol/src/engine/pattern_match.rs index 3f1ff3bc5c..2159ac66f8 100644 --- a/crates/nu-protocol/src/engine/pattern_match.rs +++ b/crates/nu-protocol/src/engine/pattern_match.rs @@ -77,6 +77,13 @@ impl Matcher for Pattern { false } } + Expr::Float(x) => { + if let Value::Float { val, .. } = &value { + x == val + } else { + false + } + } Expr::Binary(x) => { if let Value::Binary { val, .. } = &value { x == val @@ -91,6 +98,20 @@ impl Matcher for Pattern { false } } + Expr::String(x) => { + if let Value::String { val, .. } = &value { + x == val + } else { + false + } + } + Expr::DateTime(x) => { + if let Value::Date { val, .. } = &value { + x == val + } else { + false + } + } Expr::ValueWithUnit(amount, unit) => { if let Value::Filesize { val, .. } = &value { // FIXME: we probably want this math in one place that both the