nushell/crates/nu-command/tests/commands/str_/collect.rs
Dan Davison 4926865c4e
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)
2022-09-11 11:48:27 +03:00

54 lines
890 B
Rust

use nu_test_support::{nu, pipeline};
#[test]
fn test_1() {
let actual = nu!(
cwd: ".", pipeline(
r#"
echo 1..5 | into string | str join
"#
)
);
assert_eq!(actual.out, "12345");
}
#[test]
fn test_2() {
let actual = nu!(
cwd: ".", pipeline(
r#"
echo [a b c d] | str join "<sep>"
"#
)
);
assert_eq!(actual.out, "a<sep>b<sep>c<sep>d");
}
#[test]
fn construct_a_path() {
let actual = nu!(
cwd: ".", pipeline(
r#"
echo [sample txt] | str join "."
"#
)
);
assert_eq!(actual.out, "sample.txt");
}
#[test]
fn sum_one_to_four() {
let actual = nu!(
cwd: ".", pipeline(
r#"
1..4 | each { |it| $it } | into string | str join "+" | math eval
"#
)
);
assert!(actual.out.contains("10"));
}