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 959d14203e.

* 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:

b85542c31c/src/virtualenv/activation/nushell/activate.nu (L43)
This commit is contained in:
Dan Davison
2022-09-11 04:48:27 -04:00
committed by GitHub
parent 9ee4086dfa
commit 4926865c4e
29 changed files with 173 additions and 68 deletions

View File

@ -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
"#
));

View File

@ -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 ','
"#
));

View File

@ -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
"#
));

View File

@ -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 ", "
"#
));

View File

@ -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);

View File

@ -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);

View File

@ -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 " "
"#
));

View File

@ -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

View File

@ -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

View File

@ -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 "<sep>"
echo [a b c d] | str join "<sep>"
"#
)
);
@ -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
"#
)
);

View File

@ -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"

View File

@ -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"

View File

@ -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 '-'
"#
));