mirror of
https://github.com/nushell/nushell.git
synced 2024-11-29 03:44:19 +01:00
406df7f208
# Description Judiciously try to avoid allocations/clone by changing the signature of functions - **Don't pass str by value unnecessarily if only read** - **Don't require a vec in `Sandbox::with_files`** - **Remove unnecessary string clone** - **Fixup unnecessary borrow** - **Use `&str` in shape color instead** - **Vec -> Slice** - **Elide string clone** - **Elide `Path` clone** - **Take &str to elide clone in tests** # User-Facing Changes None # Tests + Formatting This touches many tests purely in changing from owned to borrowed/static data
50 lines
1.3 KiB
Rust
50 lines
1.3 KiB
Rust
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
|
use nu_test_support::playground::Playground;
|
|
use nu_test_support::{nu, pipeline};
|
|
|
|
#[test]
|
|
fn to_column() {
|
|
Playground::setup("split_column_test_1", |dirs, sandbox| {
|
|
sandbox.with_files(&[
|
|
FileWithContentToBeTrimmed(
|
|
"sample.txt",
|
|
r#"
|
|
importer,shipper,tariff_item,name,origin
|
|
"#,
|
|
),
|
|
FileWithContentToBeTrimmed(
|
|
"sample2.txt",
|
|
r#"
|
|
importer , shipper , tariff_item , name , origin
|
|
"#,
|
|
),
|
|
]);
|
|
|
|
let actual = nu!(
|
|
cwd: dirs.test(), pipeline(
|
|
r#"
|
|
open sample.txt
|
|
| lines
|
|
| str trim
|
|
| split column ","
|
|
| get column2
|
|
"#
|
|
));
|
|
|
|
assert!(actual.out.contains("shipper"));
|
|
|
|
let actual = nu!(
|
|
cwd: dirs.test(), pipeline(
|
|
r"
|
|
open sample2.txt
|
|
| lines
|
|
| str trim
|
|
| split column --regex '\s*,\s*'
|
|
| get column2
|
|
"
|
|
));
|
|
|
|
assert!(actual.out.contains("shipper"));
|
|
})
|
|
}
|