From df691c6c91b605b3f967d2ecac9f351647a9ab54 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Sun, 30 Aug 2020 19:03:18 +1200 Subject: [PATCH] Light fixes (#2455) * Add optional commas for items in lists and tables * A couple last fixes --- crates/nu-data/src/base/shape.rs | 4 +-- crates/nu-protocol/src/hir.rs | 30 +++++++++++++++++++++++ tests/shell/pipeline/commands/internal.rs | 12 +++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/crates/nu-data/src/base/shape.rs b/crates/nu-data/src/base/shape.rs index bf6cd8f3de..a8f70a86f3 100644 --- a/crates/nu-data/src/base/shape.rs +++ b/crates/nu-data/src/base/shape.rs @@ -142,8 +142,8 @@ impl PrettyDebug for FormatInlineShape { let (right, right_inclusion) = &range.to; let op = match (left_inclusion, right_inclusion) { - (RangeInclusion::Inclusive, RangeInclusion::Exclusive) => "..", - _ => unimplemented!("No syntax for ranges that aren't inclusive on the left and exclusive on the right") + (RangeInclusion::Inclusive, RangeInclusion::Inclusive) => "..", + _ => unimplemented!("No syntax for ranges that aren't inclusive on the left and inclusive on the right") }; left.clone().format().pretty() + b::operator(op) + right.clone().format().pretty() diff --git a/crates/nu-protocol/src/hir.rs b/crates/nu-protocol/src/hir.rs index 69055e7f74..71dd4f53e7 100644 --- a/crates/nu-protocol/src/hir.rs +++ b/crates/nu-protocol/src/hir.rs @@ -610,6 +610,22 @@ impl SpannedExpression { } false } + Expression::Table(headers, cells) => { + for l in headers { + if l.has_shallow_it_usage() { + return true; + } + } + + for row in cells { + for cell in row { + if cell.has_shallow_it_usage() { + return true; + } + } + } + false + } Expression::Invocation(block) => { for commands in block.block.iter() { for command in commands.list.iter() { @@ -646,6 +662,20 @@ impl SpannedExpression { item.expand_it_usage(); } } + SpannedExpression { + expr: Expression::Table(headers, cells), + .. + } => { + for header in headers.iter_mut() { + header.expand_it_usage(); + } + + for row in cells.iter_mut() { + for cell in row { + cell.expand_it_usage() + } + } + } SpannedExpression { expr: Expression::Path(path), .. diff --git a/tests/shell/pipeline/commands/internal.rs b/tests/shell/pipeline/commands/internal.rs index d3cfc6cbb5..516bdbe936 100644 --- a/tests/shell/pipeline/commands/internal.rs +++ b/tests/shell/pipeline/commands/internal.rs @@ -454,6 +454,18 @@ fn list_with_commas() { assert_eq!(actual.out, "6"); } +#[test] +fn it_expansion_of_tables() { + let actual = nu!( + cwd: ".", + r#" + echo foo | echo [[`foo {{$it}} bar`]; [`{{$it}} foo`]] | get "foo foo bar" + "# + ); + + assert_eq!(actual.out, "foo foo"); +} + #[test] fn table_with_commas() { let actual = nu!(