From 4926865c4ecc5cf3a7024dad57aea478bb16f690 Mon Sep 17 00:00:00 2001 From: Dan Davison Date: Sun, 11 Sep 2022 04:48:27 -0400 Subject: [PATCH] `str collect` => `str join` (#6531) * Initialize join.rs as a copy of collect.rs * Evolve StrCollect into StrJoin * Replace 'str collect' with 'str join' everywhere git ls-files | lines | par-each { |it| sed -i 's,str collect,str join,g' $it } * Deprecate 'str collect' * Revert "Deprecate 'str collect'" This reverts commit 959d14203ee37ef3a1e705e1826581a51d5f6ff5. * Change `str collect` help message to say that it is deprecated We cannot remove `str collect` currently (i.e. via `nu_protocol::ShellError::DeprecatedCommand` since a prominent project uses the API: https://github.com/pypa/virtualenv/blob/b85542c31ca8afcff317e618da434f59fa06d122/src/virtualenv/activation/nushell/activate.nu#L43 --- .github/workflows/release-pkg.nu | 4 +- crates/nu-command/src/default_context.rs | 1 + crates/nu-command/src/example_test.rs | 4 +- crates/nu-command/src/filters/upsert.rs | 2 +- crates/nu-command/src/platform/ansi/ansi_.rs | 8 +- crates/nu-command/src/platform/ansi/strip.rs | 2 +- crates/nu-command/src/strings/char_.rs | 2 +- crates/nu-command/src/strings/str_/collect.rs | 6 +- crates/nu-command/src/strings/str_/join.rs | 106 ++++++++++++++++++ crates/nu-command/src/strings/str_/mod.rs | 2 + crates/nu-command/tests/commands/each.rs | 2 +- crates/nu-command/tests/commands/flatten.rs | 4 +- .../nu-command/tests/commands/move_/column.rs | 12 +- crates/nu-command/tests/commands/reject.rs | 6 +- crates/nu-command/tests/commands/roll.rs | 6 +- crates/nu-command/tests/commands/rotate.rs | 8 +- crates/nu-command/tests/commands/select.rs | 4 +- .../nu-command/tests/commands/skip/until.rs | 2 +- .../nu-command/tests/commands/skip/while_.rs | 2 +- .../nu-command/tests/commands/str_/collect.rs | 8 +- .../nu-command/tests/commands/take/until.rs | 2 +- .../nu-command/tests/commands/take/while_.rs | 2 +- crates/nu-command/tests/commands/zip.rs | 2 +- .../nu-utils/src/sample_config/default_env.nu | 6 +- src/tests/test_bits.rs | 14 +-- src/tests/test_engine.rs | 2 +- src/tests/test_parser.rs | 14 +-- src/tests/test_table_operations.rs | 2 +- tests/shell/pipeline/commands/internal.rs | 6 +- 29 files changed, 173 insertions(+), 68 deletions(-) create mode 100644 crates/nu-command/src/strings/str_/join.rs diff --git a/.github/workflows/release-pkg.nu b/.github/workflows/release-pkg.nu index 7491644e25..5911b9b558 100755 --- a/.github/workflows/release-pkg.nu +++ b/.github/workflows/release-pkg.nu @@ -76,9 +76,9 @@ cp -v README.release.txt $'($dist)/README.txt' $'(char nl)Check binary release version detail:'; hr-line let ver = if $os == 'windows-latest' { - (do -i { ./output/nu.exe -c 'version' }) | str collect + (do -i { ./output/nu.exe -c 'version' }) | str join } else { - (do -i { ./output/nu -c 'version' }) | str collect + (do -i { ./output/nu -c 'version' }) | str join } if ($ver | str trim | is-empty) { $'(ansi r)Incompatible nu binary...(ansi reset)' diff --git a/crates/nu-command/src/default_context.rs b/crates/nu-command/src/default_context.rs index 43e3d741af..85af4285dc 100644 --- a/crates/nu-command/src/default_context.rs +++ b/crates/nu-command/src/default_context.rs @@ -201,6 +201,7 @@ pub fn create_default_context() -> EngineState { StrDistance, StrDowncase, StrEndswith, + StrJoin, StrReplace, StrIndexOf, StrKebabCase, diff --git a/crates/nu-command/src/example_test.rs b/crates/nu-command/src/example_test.rs index e570136129..0180262954 100644 --- a/crates/nu-command/src/example_test.rs +++ b/crates/nu-command/src/example_test.rs @@ -14,7 +14,7 @@ use crate::To; #[cfg(test)] use super::{ Ansi, Date, From, If, Into, LetEnv, Math, Path, Random, Split, SplitColumn, SplitRow, Str, - StrCollect, StrLength, StrReplace, Url, Wrap, + StrJoin, StrLength, StrReplace, Url, Wrap, }; #[cfg(test)] @@ -29,7 +29,7 @@ pub fn test_examples(cmd: impl Command + 'static) { // Try to keep this working set small to keep tests running as fast as possible let mut working_set = StateWorkingSet::new(&*engine_state); working_set.add_decl(Box::new(Str)); - working_set.add_decl(Box::new(StrCollect)); + working_set.add_decl(Box::new(StrJoin)); working_set.add_decl(Box::new(StrLength)); working_set.add_decl(Box::new(StrReplace)); working_set.add_decl(Box::new(BuildString)); diff --git a/crates/nu-command/src/filters/upsert.rs b/crates/nu-command/src/filters/upsert.rs index beb53aa9e5..c19d20ffc5 100644 --- a/crates/nu-command/src/filters/upsert.rs +++ b/crates/nu-command/src/filters/upsert.rs @@ -62,7 +62,7 @@ impl Command for Upsert { result: Some(Value::List { vals: vec![Value::Record { cols: vec!["count".into(), "fruit".into()], vals: vec![Value::test_int(2), Value::test_string("apple")], span: Span::test_data()}], span: Span::test_data()}), }, Example { description: "Use in block form for more involved updating logic", - example: "echo [[project, authors]; ['nu', ['Andrés', 'JT', 'Yehuda']]] | upsert authors {|a| $a.authors | str collect ','}", + example: "echo [[project, authors]; ['nu', ['Andrés', 'JT', 'Yehuda']]] | upsert authors {|a| $a.authors | str join ','}", result: Some(Value::List { vals: vec![Value::Record { cols: vec!["project".into(), "authors".into()], vals: vec![Value::test_string("nu"), Value::test_string("Andrés,JT,Yehuda")], span: Span::test_data()}], span: Span::test_data()}), }] } diff --git a/crates/nu-command/src/platform/ansi/ansi_.rs b/crates/nu-command/src/platform/ansi/ansi_.rs index 6d818a45fb..a4a8d0cfc3 100644 --- a/crates/nu-command/src/platform/ansi/ansi_.rs +++ b/crates/nu-command/src/platform/ansi/ansi_.rs @@ -141,7 +141,7 @@ lazy_static! { // Reference for ansi codes https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797 // Another good reference http://ascii-table.com/ansi-escape-sequences.php - // For setting title like `echo [(char title) (pwd) (char bel)] | str collect` + // For setting title like `echo [(char title) (pwd) (char bel)] | str join` AnsiCode{short_name: None, long_name:"title", code: "\x1b]2;".to_string()}, // ESC]2; xterm sets window title using OSC syntax escapes // Ansi Erase Sequences @@ -258,7 +258,7 @@ following values: https://en.wikipedia.org/wiki/ANSI_escape_code OSC: '\x1b]' is not required for --osc parameter -Example: echo [(ansi -o '0') 'some title' (char bel)] | str collect +Example: echo [(ansi -o '0') 'some title' (char bel)] | str join Format: # 0 Set window title and icon name 1 Set icon name @@ -285,14 +285,14 @@ Format: # Example { description: "Use ansi to color text (rb = red bold, gb = green bold, pb = purple bold)", - example: r#"echo [(ansi rb) Hello " " (ansi gb) Nu " " (ansi pb) World (ansi reset)] | str collect"#, + example: r#"echo [(ansi rb) Hello " " (ansi gb) Nu " " (ansi pb) World (ansi reset)] | str join"#, result: Some(Value::test_string( "\u{1b}[1;31mHello \u{1b}[1;32mNu \u{1b}[1;35mWorld\u{1b}[0m", )), }, Example { description: "Use ansi to color text (italic bright yellow on red 'Hello' with green bold 'Nu' and purple bold 'World')", - example: r#"echo [(ansi -e '3;93;41m') Hello (ansi reset) " " (ansi gb) Nu " " (ansi pb) World (ansi reset)] | str collect"#, + example: r#"echo [(ansi -e '3;93;41m') Hello (ansi reset) " " (ansi gb) Nu " " (ansi pb) World (ansi reset)] | str join"#, result: Some(Value::test_string( "\u{1b}[3;93;41mHello\u{1b}[0m \u{1b}[1;32mNu \u{1b}[1;35mWorld\u{1b}[0m", )), diff --git a/crates/nu-command/src/platform/ansi/strip.rs b/crates/nu-command/src/platform/ansi/strip.rs index dcf71d6857..af5b161fec 100644 --- a/crates/nu-command/src/platform/ansi/strip.rs +++ b/crates/nu-command/src/platform/ansi/strip.rs @@ -40,7 +40,7 @@ impl Command for SubCommand { fn examples(&self) -> Vec { vec![Example { description: "Strip ANSI escape sequences from a string", - example: r#"echo [ (ansi green) (ansi cursor_on) "hello" ] | str collect | ansi strip"#, + example: r#"echo [ (ansi green) (ansi cursor_on) "hello" ] | str join | ansi strip"#, result: Some(Value::test_string("hello")), }] } diff --git a/crates/nu-command/src/strings/char_.rs b/crates/nu-command/src/strings/char_.rs index f0bd321dfa..b82ab82407 100644 --- a/crates/nu-command/src/strings/char_.rs +++ b/crates/nu-command/src/strings/char_.rs @@ -185,7 +185,7 @@ impl Command for Char { }, Example { description: "Output prompt character, newline and a hamburger character", - example: r#"echo [(char prompt) (char newline) (char hamburger)] | str collect"#, + example: r#"echo [(char prompt) (char newline) (char hamburger)] | str join"#, result: Some(Value::test_string("\u{25b6}\n\u{2261}")), }, Example { diff --git a/crates/nu-command/src/strings/str_/collect.rs b/crates/nu-command/src/strings/str_/collect.rs index 551594ab91..034c89502c 100644 --- a/crates/nu-command/src/strings/str_/collect.rs +++ b/crates/nu-command/src/strings/str_/collect.rs @@ -25,11 +25,7 @@ impl Command for StrCollect { } fn usage(&self) -> &str { - "Concatenate multiple strings into a single string, with an optional separator between each" - } - - fn search_terms(&self) -> Vec<&str> { - vec!["join", "concatenate"] + "'str collect' is deprecated. Please use 'str join' instead." } fn run( diff --git a/crates/nu-command/src/strings/str_/join.rs b/crates/nu-command/src/strings/str_/join.rs new file mode 100644 index 0000000000..fe8f659514 --- /dev/null +++ b/crates/nu-command/src/strings/str_/join.rs @@ -0,0 +1,106 @@ +use nu_engine::CallExt; +use nu_protocol::ast::Call; +use nu_protocol::engine::{Command, EngineState, Stack}; +use nu_protocol::{ + Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, SyntaxShape, + Value, +}; + +#[derive(Clone)] +pub struct StrJoin; + +impl Command for StrJoin { + fn name(&self) -> &str { + "str join" + } + + fn signature(&self) -> Signature { + Signature::build("str join") + .optional( + "separator", + SyntaxShape::String, + "optional separator to use when creating string", + ) + .category(Category::Strings) + } + + fn usage(&self) -> &str { + "Concatenate multiple strings into a single string, with an optional separator between each" + } + + fn search_terms(&self) -> Vec<&str> { + vec!["collect", "concatenate"] + } + + fn run( + &self, + engine_state: &EngineState, + stack: &mut Stack, + call: &Call, + input: PipelineData, + ) -> Result { + let separator: Option = call.opt(engine_state, stack, 0)?; + + let config = engine_state.get_config(); + + // let output = input.collect_string(&separator.unwrap_or_default(), &config)?; + // Hmm, not sure what we actually want. If you don't use debug_string, Date comes out as human readable + // which feels funny + let mut strings: Vec = vec![]; + + for value in input { + match value { + Value::Error { error } => { + return Err(error); + } + value => { + strings.push(value.debug_string("\n", config)); + } + } + } + + let output = if let Some(separator) = separator { + strings.join(&separator) + } else { + strings.join("") + }; + + Ok(Value::String { + val: output, + span: call.head, + } + .into_pipeline_data()) + } + + fn examples(&self) -> Vec { + vec![ + Example { + description: "Create a string from input", + example: "['nu', 'shell'] | str join", + result: Some(Value::String { + val: "nushell".to_string(), + span: Span::test_data(), + }), + }, + Example { + description: "Create a string from input with a separator", + example: "['nu', 'shell'] | str join '-'", + result: Some(Value::String { + val: "nu-shell".to_string(), + span: Span::test_data(), + }), + }, + ] + } +} + +#[cfg(test)] +mod tests { + use super::*; + #[test] + fn test_examples() { + use crate::test_examples; + + test_examples(StrJoin {}) + } +} diff --git a/crates/nu-command/src/strings/str_/mod.rs b/crates/nu-command/src/strings/str_/mod.rs index cbe3ee0050..26744205b5 100644 --- a/crates/nu-command/src/strings/str_/mod.rs +++ b/crates/nu-command/src/strings/str_/mod.rs @@ -4,6 +4,7 @@ mod contains; mod distance; mod ends_with; mod index_of; +mod join; mod length; mod lpad; mod replace; @@ -19,6 +20,7 @@ pub use contains::SubCommand as StrContains; pub use distance::SubCommand as StrDistance; pub use ends_with::SubCommand as StrEndswith; pub use index_of::SubCommand as StrIndexOf; +pub use join::*; pub use length::SubCommand as StrLength; pub use lpad::SubCommand as StrLpad; pub use replace::SubCommand as StrReplace; diff --git a/crates/nu-command/tests/commands/each.rs b/crates/nu-command/tests/commands/each.rs index 5ac0c14d91..df1ba48a65 100644 --- a/crates/nu-command/tests/commands/each.rs +++ b/crates/nu-command/tests/commands/each.rs @@ -65,7 +65,7 @@ fn each_implicit_it_in_block() { let actual = nu!( cwd: "tests/fixtures/formats", pipeline( r#" - echo [[foo bar]; [a b] [c d] [e f]] | each { |it| nu --testbin cococo $it.foo } | str collect + echo [[foo bar]; [a b] [c d] [e f]] | each { |it| nu --testbin cococo $it.foo } | str join "# )); diff --git a/crates/nu-command/tests/commands/flatten.rs b/crates/nu-command/tests/commands/flatten.rs index f5df5fa0d3..8d33fdde6f 100644 --- a/crates/nu-command/tests/commands/flatten.rs +++ b/crates/nu-command/tests/commands/flatten.rs @@ -11,7 +11,7 @@ fn flatten_nested_tables_with_columns() { [[origin, people]; [Nu, ('nuno' | wrap name)]] | flatten --all | flatten --all | get name - | str collect ',' + | str join ',' "# )); @@ -27,7 +27,7 @@ fn flatten_nested_tables_that_have_many_columns() { [[origin, people]; [USA, (echo [[name, meal]; ['Katz', 'nurepa']])]] | flatten --all | flatten --all | get meal - | str collect ',' + | str join ',' "# )); diff --git a/crates/nu-command/tests/commands/move_/column.rs b/crates/nu-command/tests/commands/move_/column.rs index 1430f0139c..490197db4c 100644 --- a/crates/nu-command/tests/commands/move_/column.rs +++ b/crates/nu-command/tests/commands/move_/column.rs @@ -26,7 +26,7 @@ fn moves_a_column_before() { | rename chars | get chars | str trim - | str collect + | str join "# )); @@ -59,9 +59,9 @@ fn moves_columns_before() { | move column99 column3 --before column2 | rename _ chars_1 chars_2 | select chars_2 chars_1 - | upsert new_col {|f| $f | transpose | get column1 | str trim | str collect} + | upsert new_col {|f| $f | transpose | get column1 | str trim | str join} | get new_col - | str collect + | str join "# )); @@ -95,9 +95,9 @@ fn moves_a_column_after() { | move letters and_more --before column2 | rename _ chars_1 chars_2 | select chars_1 chars_2 - | upsert new_col {|f| $f | transpose | get column1 | str trim | str collect} + | upsert new_col {|f| $f | transpose | get column1 | str trim | str join} | get new_col - | str collect + | str join "# )); @@ -130,7 +130,7 @@ fn moves_columns_after() { | move letters and_more --after column1 | columns | select 1 2 - | str collect + | str join "# )); diff --git a/crates/nu-command/tests/commands/reject.rs b/crates/nu-command/tests/commands/reject.rs index 9060360a0e..5d35190378 100644 --- a/crates/nu-command/tests/commands/reject.rs +++ b/crates/nu-command/tests/commands/reject.rs @@ -13,7 +13,7 @@ fn regular_columns() { ] | reject type first_name | columns - | str collect ", " + | str join ", " "# )); @@ -56,7 +56,7 @@ fn complex_nested_columns() { | reject nu."0xATYKARNU" nu.committers | get nu | columns - | str collect ", " + | str join ", " "#, )); @@ -75,7 +75,7 @@ fn ignores_duplicate_columns_rejected() { ] | reject "first name" "first name" | columns - | str collect ", " + | str join ", " "# )); diff --git a/crates/nu-command/tests/commands/roll.rs b/crates/nu-command/tests/commands/roll.rs index 8bf419ee13..ccbd640e31 100644 --- a/crates/nu-command/tests/commands/roll.rs +++ b/crates/nu-command/tests/commands/roll.rs @@ -69,7 +69,7 @@ mod columns { format!("{} | {}", table(), pipeline(r#" roll left | columns - | str collect "-" + | str join "-" "#))); assert_eq!(actual.out, "origin-stars-commit_author"); @@ -82,7 +82,7 @@ mod columns { format!("{} | {}", table(), pipeline(r#" roll right --by 2 | columns - | str collect "-" + | str join "-" "#))); assert_eq!(actual.out, "origin-stars-commit_author"); @@ -97,7 +97,7 @@ mod columns { let actual = nu!( cwd: ".", - format!("{} | roll right --by 3 --cells-only | columns | str collect '-' ", four_bitstring) + format!("{} | roll right --by 3 --cells-only | columns | str join '-' ", four_bitstring) ); assert_eq!(actual.out, expected_value.1); diff --git a/crates/nu-command/tests/commands/rotate.rs b/crates/nu-command/tests/commands/rotate.rs index 7f20406215..434663695a 100644 --- a/crates/nu-command/tests/commands/rotate.rs +++ b/crates/nu-command/tests/commands/rotate.rs @@ -25,7 +25,7 @@ fn counter_clockwise() { ] | where column0 == EXPECTED | get column1 column2 column3 - | str collect "-" + | str join "-" "#, )); @@ -35,7 +35,7 @@ fn counter_clockwise() { rotate --ccw | where column0 == EXPECTED | get column1 column2 column3 - | str collect "-" + | str join "-" "#))); assert_eq!(actual.out, expected.out); @@ -66,7 +66,7 @@ fn clockwise() { ] | where column3 == EXPECTED | get column0 column1 column2 - | str collect "-" + | str join "-" "#, )); @@ -76,7 +76,7 @@ fn clockwise() { rotate | where column3 == EXPECTED | get column0 column1 column2 - | str collect "-" + | str join "-" "#))); assert_eq!(actual.out, expected.out); diff --git a/crates/nu-command/tests/commands/select.rs b/crates/nu-command/tests/commands/select.rs index d8c59aa02a..ac8eed2522 100644 --- a/crates/nu-command/tests/commands/select.rs +++ b/crates/nu-command/tests/commands/select.rs @@ -96,7 +96,7 @@ fn column_names_with_spaces() { ] | select "last name" | get "last name" - | str collect " " + | str join " " "# )); @@ -115,7 +115,7 @@ fn ignores_duplicate_columns_selected() { ] | select "first name" "last name" "first name" | columns - | str collect " " + | str join " " "# )); diff --git a/crates/nu-command/tests/commands/skip/until.rs b/crates/nu-command/tests/commands/skip/until.rs index 7ef815e98a..2a1a746eb3 100644 --- a/crates/nu-command/tests/commands/skip/until.rs +++ b/crates/nu-command/tests/commands/skip/until.rs @@ -36,7 +36,7 @@ fn condition_is_met() { | lines | skip 2 | str trim - | str collect (char nl) + | str join (char nl) | from csv | skip until "Chicken Collection" == "Red Chickens" | skip 1 diff --git a/crates/nu-command/tests/commands/skip/while_.rs b/crates/nu-command/tests/commands/skip/while_.rs index e21e364dc4..c7cd34ac82 100644 --- a/crates/nu-command/tests/commands/skip/while_.rs +++ b/crates/nu-command/tests/commands/skip/while_.rs @@ -36,7 +36,7 @@ fn condition_is_met() { | lines | skip 2 | str trim - | str collect (char nl) + | str join (char nl) | from csv | skip while "Chicken Collection" != "Red Chickens" | skip 1 diff --git a/crates/nu-command/tests/commands/str_/collect.rs b/crates/nu-command/tests/commands/str_/collect.rs index 4a4a93c1dd..820fa8d0d6 100644 --- a/crates/nu-command/tests/commands/str_/collect.rs +++ b/crates/nu-command/tests/commands/str_/collect.rs @@ -5,7 +5,7 @@ fn test_1() { let actual = nu!( cwd: ".", pipeline( r#" - echo 1..5 | into string | str collect + echo 1..5 | into string | str join "# ) ); @@ -18,7 +18,7 @@ fn test_2() { let actual = nu!( cwd: ".", pipeline( r#" - echo [a b c d] | str collect "" + echo [a b c d] | str join "" "# ) ); @@ -31,7 +31,7 @@ fn construct_a_path() { let actual = nu!( cwd: ".", pipeline( r#" - echo [sample txt] | str collect "." + echo [sample txt] | str join "." "# ) ); @@ -44,7 +44,7 @@ fn sum_one_to_four() { let actual = nu!( cwd: ".", pipeline( r#" - 1..4 | each { |it| $it } | into string | str collect "+" | math eval + 1..4 | each { |it| $it } | into string | str join "+" | math eval "# ) ); diff --git a/crates/nu-command/tests/commands/take/until.rs b/crates/nu-command/tests/commands/take/until.rs index aa129b09cc..b1cd15f056 100644 --- a/crates/nu-command/tests/commands/take/until.rs +++ b/crates/nu-command/tests/commands/take/until.rs @@ -36,7 +36,7 @@ fn condition_is_met() { | lines | skip 2 | str trim - | str collect (char nl) + | str join (char nl) | from csv | skip while "Chicken Collection" != "Blue Chickens" | take until "Chicken Collection" == "Red Chickens" diff --git a/crates/nu-command/tests/commands/take/while_.rs b/crates/nu-command/tests/commands/take/while_.rs index c46673dc7f..41ecc73948 100644 --- a/crates/nu-command/tests/commands/take/while_.rs +++ b/crates/nu-command/tests/commands/take/while_.rs @@ -36,7 +36,7 @@ fn condition_is_met() { | lines | skip 2 | str trim - | str collect (char nl) + | str join (char nl) | from csv | skip 1 | take while "Chicken Collection" != "Blue Chickens" diff --git a/crates/nu-command/tests/commands/zip.rs b/crates/nu-command/tests/commands/zip.rs index 8631425010..5c7693a4b1 100644 --- a/crates/nu-command/tests/commands/zip.rs +++ b/crates/nu-command/tests/commands/zip.rs @@ -51,7 +51,7 @@ fn zips_two_lists() { let actual = nu!( cwd: ".", pipeline( r#" - echo [0 2 4 6 8] | zip [1 3 5 7 9] | flatten | into string | str collect '-' + echo [0 2 4 6 8] | zip [1 3 5 7 9] | flatten | into string | str join '-' "# )); diff --git a/crates/nu-utils/src/sample_config/default_env.nu b/crates/nu-utils/src/sample_config/default_env.nu index 61651379fc..0269f3ffc9 100644 --- a/crates/nu-utils/src/sample_config/default_env.nu +++ b/crates/nu-utils/src/sample_config/default_env.nu @@ -13,7 +13,7 @@ def create_left_prompt [] { def create_right_prompt [] { let time_segment = ([ (date now | date format '%m/%d/%Y %r') - ] | str collect) + ] | str join) $time_segment } @@ -36,11 +36,11 @@ let-env PROMPT_MULTILINE_INDICATOR = { "::: " } let-env ENV_CONVERSIONS = { "PATH": { from_string: { |s| $s | split row (char esep) | path expand -n } - to_string: { |v| $v | path expand -n | str collect (char esep) } + to_string: { |v| $v | path expand -n | str join (char esep) } } "Path": { from_string: { |s| $s | split row (char esep) | path expand -n } - to_string: { |v| $v | path expand -n | str collect (char esep) } + to_string: { |v| $v | path expand -n | str join (char esep) } } } diff --git a/src/tests/test_bits.rs b/src/tests/test_bits.rs index 41455eea8d..6cef4eaa9a 100644 --- a/src/tests/test_bits.rs +++ b/src/tests/test_bits.rs @@ -12,7 +12,7 @@ fn bits_and_negative() -> TestResult { #[test] fn bits_and_list() -> TestResult { - run_test("[1 2 3 8 9 10] | bits and 2 | str collect '.'", "0.2.2.0.0.2") + run_test("[1 2 3 8 9 10] | bits and 2 | str join '.'", "0.2.2.0.0.2") } #[test] @@ -27,7 +27,7 @@ fn bits_or_negative() -> TestResult { #[test] fn bits_or_list() -> TestResult { - run_test("[1 2 3 8 9 10] | bits or 2 | str collect '.'", "3.2.3.10.11.10") + run_test("[1 2 3 8 9 10] | bits or 2 | str join '.'", "3.2.3.10.11.10") } #[test] @@ -42,7 +42,7 @@ fn bits_xor_negative() -> TestResult { #[test] fn bits_xor_list() -> TestResult { - run_test("[1 2 3 8 9 10] | bits xor 2 | str collect '.'", "3.0.1.10.11.8") + run_test("[1 2 3 8 9 10] | bits xor 2 | str join '.'", "3.0.1.10.11.8") } #[test] @@ -57,7 +57,7 @@ fn bits_shift_left_negative() -> TestResult { #[test] fn bits_shift_left_list() -> TestResult { - run_test("[1 2 7 32 9 10] | bits shl 3 | str collect '.'", "8.16.56.256.72.80") + run_test("[1 2 7 32 9 10] | bits shl 3 | str join '.'", "8.16.56.256.72.80") } #[test] @@ -72,7 +72,7 @@ fn bits_shift_right_negative() -> TestResult { #[test] fn bits_shift_right_list() -> TestResult { - run_test("[12 98 7 64 900 10] | bits shr 3 | str collect '.'", "1.12.0.8.112.1") + run_test("[12 98 7 64 900 10] | bits shr 3 | str join '.'", "1.12.0.8.112.1") } #[test] @@ -87,7 +87,7 @@ fn bits_rotate_left_negative() -> TestResult { #[test] fn bits_rotate_left_list() -> TestResult { - run_test("[1 2 7 32 9 10] | bits rol 3 | str collect '.'", "8.16.56.256.72.80") + run_test("[1 2 7 32 9 10] | bits rol 3 | str join '.'", "8.16.56.256.72.80") } #[test] @@ -102,5 +102,5 @@ fn bits_rotate_right_negative() -> TestResult { #[test] fn bits_rotate_right_list() -> TestResult { - run_test("[1 2 7 32 23 10] | bits ror 60 | str collect '.'", "16.32.112.512.368.160") + run_test("[1 2 7 32 23 10] | bits ror 60 | str join '.'", "16.32.112.512.368.160") } diff --git a/src/tests/test_engine.rs b/src/tests/test_engine.rs index 8d2df665fe..2483119cea 100644 --- a/src/tests/test_engine.rs +++ b/src/tests/test_engine.rs @@ -335,7 +335,7 @@ fn in_means_input() -> TestResult { #[test] fn in_iteration() -> TestResult { run_test( - r#"[3, 4, 5] | each { echo $"hi ($in)" } | str collect"#, + r#"[3, 4, 5] | each { echo $"hi ($in)" } | str join"#, "hi 3hi 4hi 5", ) } diff --git a/src/tests/test_parser.rs b/src/tests/test_parser.rs index ed7986141b..6dcde27a08 100644 --- a/src/tests/test_parser.rs +++ b/src/tests/test_parser.rs @@ -245,7 +245,7 @@ def 'call-me' [] { echo $CONST_A } -[(say-hi) (call-me)] | str collect +[(say-hi) (call-me)] | str join "#, "HelloHello", @@ -266,7 +266,7 @@ def 'say-hi' [] { echo (call-me) } -[(say-hi) (call-me)] | str collect +[(say-hi) (call-me)] | str join "#, "HelloHello", @@ -287,7 +287,7 @@ def 'call-me' [] { echo $CONST_A } -[(call-me) (say-hi)] | str collect +[(call-me) (say-hi)] | str join "#, "HelloHello", @@ -308,7 +308,7 @@ def 'say-hi' [] { echo (call-me) } -[(call-me) (say-hi)] | str collect +[(call-me) (say-hi)] | str join "#, "HelloHello", @@ -318,7 +318,7 @@ def 'say-hi' [] { #[test] fn capture_row_condition() -> TestResult { run_test( - r#"let name = "foo"; [foo] | where $'($name)' =~ $it | str collect"#, + r#"let name = "foo"; [foo] | where $'($name)' =~ $it | str join"#, "foo", ) } @@ -326,7 +326,7 @@ fn capture_row_condition() -> TestResult { #[test] fn starts_with_operator_succeeds() -> TestResult { run_test( - r#"[Moe Larry Curly] | where $it starts-with L | str collect"#, + r#"[Moe Larry Curly] | where $it starts-with L | str join"#, "Larry", ) } @@ -334,7 +334,7 @@ fn starts_with_operator_succeeds() -> TestResult { #[test] fn ends_with_operator_succeeds() -> TestResult { run_test( - r#"[Moe Larry Curly] | where $it ends-with ly | str collect"#, + r#"[Moe Larry Curly] | where $it ends-with ly | str join"#, "Curly", ) } diff --git a/src/tests/test_table_operations.rs b/src/tests/test_table_operations.rs index ce590eafd7..5ff1e0cad5 100644 --- a/src/tests/test_table_operations.rs +++ b/src/tests/test_table_operations.rs @@ -23,7 +23,7 @@ fn cell_path_var2() -> TestResult { #[test] fn flatten_simple_list() -> TestResult { run_test( - "[[N, u, s, h, e, l, l]] | flatten | str collect (char nl)", + "[[N, u, s, h, e, l, l]] | flatten | str join (char nl)", "N\nu\ns\nh\ne\nl\nl", ) } diff --git a/tests/shell/pipeline/commands/internal.rs b/tests/shell/pipeline/commands/internal.rs index a6e7b94369..b7a98e2e95 100644 --- a/tests/shell/pipeline/commands/internal.rs +++ b/tests/shell/pipeline/commands/internal.rs @@ -64,7 +64,7 @@ fn subexpression_properly_redirects() { let actual = nu!( cwd: ".", r#" - echo (nu --testbin cococo "hello") | str collect + echo (nu --testbin cococo "hello") | str join "# ); @@ -215,7 +215,7 @@ fn run_custom_subcommand() { let actual = nu!( cwd: ".", r#" - def "str double" [x] { echo $x $x | str collect }; str double bob + def "str double" [x] { echo $x $x | str join }; str double bob "# ); @@ -306,7 +306,7 @@ fn run_custom_command_with_rest_other_name() { greeting:string, ...names:string # All of the names ] { - echo $"($greeting), ($names | sort-by | str collect)" + echo $"($greeting), ($names | sort-by | str join)" } say-hello Salutations E D C A B "#