From f43ed23ed7dfc171d1c569cd184e8f96bdcba14a Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Sat, 16 May 2020 00:25:18 -0700 Subject: [PATCH] Fix parsing of invocations with a dot (#1804) --- crates/nu-parser/src/parse.rs | 3 + tests/shell/pipeline/commands/internal.rs | 110 ++++++++++++++-------- 2 files changed, 73 insertions(+), 40 deletions(-) diff --git a/crates/nu-parser/src/parse.rs b/crates/nu-parser/src/parse.rs index 3b9a60779..45cb38d26 100644 --- a/crates/nu-parser/src/parse.rs +++ b/crates/nu-parser/src/parse.rs @@ -93,6 +93,9 @@ fn parse_full_column_path( if c == delimiter { inside_delimiter = false; } + } else if c == '(' { + inside_delimiter = true; + delimiter = ')'; } else if c == '\'' || c == '"' { inside_delimiter = true; delimiter = c; diff --git a/tests/shell/pipeline/commands/internal.rs b/tests/shell/pipeline/commands/internal.rs index 69ee3c265..facf2b17a 100644 --- a/tests/shell/pipeline/commands/internal.rs +++ b/tests/shell/pipeline/commands/internal.rs @@ -1,6 +1,8 @@ +use nu_test_support::fs::Stub::EmptyFile; use nu_test_support::fs::Stub::FileWithContentToBeTrimmed; use nu_test_support::nu; -use nu_test_support::{pipeline, playground::Playground}; +use nu_test_support::pipeline; +use nu_test_support::playground::Playground; #[test] fn takes_rows_of_nu_value_strings_and_pipes_it_to_stdin_of_external() { @@ -32,6 +34,72 @@ fn takes_rows_of_nu_value_strings_and_pipes_it_to_stdin_of_external() { }) } +#[test] +fn proper_it_expansion() { + Playground::setup("ls_test_1", |dirs, sandbox| { + sandbox.with_files(vec![ + EmptyFile("andres.txt"), + EmptyFile("gedge.txt"), + EmptyFile("jonathan.txt"), + EmptyFile("yehuda.txt"), + ]); + + let actual = nu!( + cwd: dirs.test(), pipeline( + r#" + ls | sort-by name | group-by type | each { get File.name | echo $it } | to json + "# + )); + + assert_eq!( + actual.out, + r#"["andres.txt","gedge.txt","jonathan.txt","yehuda.txt"]"# + ); + }) +} + +#[test] +fn argument_invocation() { + let actual = nu!( + cwd: ".", + r#" + echo "foo" | echo $(echo $it) + "# + ); + + assert_eq!(actual.out, "foo"); +} + +#[test] +fn invocation_handles_dot() { + Playground::setup("invocation_handles_dot", |dirs, sandbox| { + sandbox.with_files(vec![FileWithContentToBeTrimmed( + "nu_times.csv", + r#" + name,rusty_luck,origin + Jason,1,Canada + Jonathan,1,New Zealand + Andrés,1,Ecuador + AndKitKatz,1,Estados Unidos + "#, + )]); + + let actual = nu!( + cwd: dirs.test(), pipeline( + r#" + echo $(open nu_times.csv) + | get name + | ^echo $it + | chop + | nth 3 + | echo $it + "# + )); + + assert_eq!(actual.out, "AndKitKat"); + }) +} + #[test] fn can_process_one_row_from_internal_and_pipes_it_to_stdin_of_external() { let actual = nu!( @@ -107,9 +175,7 @@ mod parse { } mod tilde_expansion { - use nu_test_support::fs::Stub::EmptyFile; - use nu_test_support::playground::Playground; - use nu_test_support::{nu, pipeline}; + use nu_test_support::nu; #[test] #[should_panic] @@ -138,40 +204,4 @@ mod tilde_expansion { assert_eq!(actual.out, "1~1"); } - - #[test] - fn proper_it_expansion() { - Playground::setup("ls_test_1", |dirs, sandbox| { - sandbox.with_files(vec![ - EmptyFile("andres.txt"), - EmptyFile("gedge.txt"), - EmptyFile("jonathan.txt"), - EmptyFile("yehuda.txt"), - ]); - - let actual = nu!( - cwd: dirs.test(), pipeline( - r#" - ls | sort-by name | group-by type | each { get File.name | echo $it } | to json - "# - )); - - assert_eq!( - actual.out, - r#"["andres.txt","gedge.txt","jonathan.txt","yehuda.txt"]"# - ); - }) - } - - #[test] - fn argument_invocation() { - let actual = nu!( - cwd: ".", - r#" - echo "foo" | echo $(echo $it) - "# - ); - - assert_eq!(actual.out, "foo"); - } }