From 1b2e680059c55c49ff17f081cabd1d0285bcf356 Mon Sep 17 00:00:00 2001 From: Ian Manske Date: Thu, 9 May 2024 23:09:44 +0000 Subject: [PATCH] Fix syntax highlighting for `not` (#12815) # Description Fixes #12813 where a panic occurs when syntax highlighting `not`. Also fixes #12814 where syntax highlighting for `not` no longer works. # User-Facing Changes Bug fix. --- crates/nu-cli/tests/commands/mod.rs | 1 + crates/nu-cli/tests/commands/nu_highlight.rs | 7 +++++++ crates/nu-cli/tests/{completions.rs => completions/mod.rs} | 0 .../tests/{ => completions}/support/completions_helpers.rs | 0 crates/nu-cli/tests/{ => completions}/support/mod.rs | 0 crates/nu-cli/tests/main.rs | 2 ++ crates/nu-parser/src/flatten.rs | 4 ++-- 7 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 crates/nu-cli/tests/commands/mod.rs create mode 100644 crates/nu-cli/tests/commands/nu_highlight.rs rename crates/nu-cli/tests/{completions.rs => completions/mod.rs} (100%) rename crates/nu-cli/tests/{ => completions}/support/completions_helpers.rs (100%) rename crates/nu-cli/tests/{ => completions}/support/mod.rs (100%) create mode 100644 crates/nu-cli/tests/main.rs diff --git a/crates/nu-cli/tests/commands/mod.rs b/crates/nu-cli/tests/commands/mod.rs new file mode 100644 index 0000000000..00488f0b9e --- /dev/null +++ b/crates/nu-cli/tests/commands/mod.rs @@ -0,0 +1 @@ +mod nu_highlight; diff --git a/crates/nu-cli/tests/commands/nu_highlight.rs b/crates/nu-cli/tests/commands/nu_highlight.rs new file mode 100644 index 0000000000..bd185a8634 --- /dev/null +++ b/crates/nu-cli/tests/commands/nu_highlight.rs @@ -0,0 +1,7 @@ +use nu_test_support::nu; + +#[test] +fn nu_highlight_not_expr() { + let actual = nu!("'not false' | nu-highlight | ansi strip"); + assert_eq!(actual.out, "not false"); +} diff --git a/crates/nu-cli/tests/completions.rs b/crates/nu-cli/tests/completions/mod.rs similarity index 100% rename from crates/nu-cli/tests/completions.rs rename to crates/nu-cli/tests/completions/mod.rs diff --git a/crates/nu-cli/tests/support/completions_helpers.rs b/crates/nu-cli/tests/completions/support/completions_helpers.rs similarity index 100% rename from crates/nu-cli/tests/support/completions_helpers.rs rename to crates/nu-cli/tests/completions/support/completions_helpers.rs diff --git a/crates/nu-cli/tests/support/mod.rs b/crates/nu-cli/tests/completions/support/mod.rs similarity index 100% rename from crates/nu-cli/tests/support/mod.rs rename to crates/nu-cli/tests/completions/support/mod.rs diff --git a/crates/nu-cli/tests/main.rs b/crates/nu-cli/tests/main.rs new file mode 100644 index 0000000000..a040a731f3 --- /dev/null +++ b/crates/nu-cli/tests/main.rs @@ -0,0 +1,2 @@ +mod commands; +mod completions; diff --git a/crates/nu-parser/src/flatten.rs b/crates/nu-parser/src/flatten.rs index e70a48e9f1..92b424783a 100644 --- a/crates/nu-parser/src/flatten.rs +++ b/crates/nu-parser/src/flatten.rs @@ -180,12 +180,12 @@ fn flatten_expression_into( flatten_expression_into(working_set, op, output); flatten_expression_into(working_set, rhs, output); } - Expr::UnaryNot(expr) => { + Expr::UnaryNot(not) => { output.push(( Span::new(expr.span.start, expr.span.start + 3), FlatShape::Operator, )); - flatten_expression_into(working_set, expr, output); + flatten_expression_into(working_set, not, output); } Expr::Closure(block_id) => { let outer_span = expr.span;