mirror of
https://github.com/nushell/nushell
synced 2024-12-30 23:08:56 +00:00
202dfdaee2
should close https://github.com/nushell/nushell/issues/9965 # Description this PR implements the `todo!()` left in `lines`. # User-Facing Changes ### before ```nushell > open . | lines thread 'main' panicked at 'not yet implemented', crates/nu-command/src/filters/lines.rs:248:35 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace ``` ### after ```nushell > open . | lines Error: nu:🐚:io_error × I/O error help: Is a directory (os error 21) ``` # Tests + Formatting - 🟢 `toolkit fmt` - 🟢 `toolkit clippy` - ⚫ `toolkit test` - ⚫ `toolkit test stdlib` this PR adds the `lines_on_error` test to make sure this does not happen again 😌 # After Submitting
71 lines
1.4 KiB
Rust
71 lines
1.4 KiB
Rust
use nu_test_support::{nu, pipeline};
|
|
|
|
#[test]
|
|
fn lines() {
|
|
let actual = nu!(
|
|
cwd: "tests/fixtures/formats", pipeline(
|
|
r#"
|
|
open cargo_sample.toml -r
|
|
| lines
|
|
| skip while {|it| $it != "[dependencies]" }
|
|
| skip 1
|
|
| first
|
|
| split column "="
|
|
| get column1.0
|
|
| str trim
|
|
"#
|
|
));
|
|
|
|
assert_eq!(actual.out, "rustyline");
|
|
}
|
|
|
|
#[test]
|
|
fn lines_proper_buffering() {
|
|
let actual = nu!(
|
|
cwd: "tests/fixtures/formats", pipeline(
|
|
"
|
|
open lines_test.txt -r
|
|
| lines
|
|
| str length
|
|
| to json -r
|
|
"
|
|
));
|
|
|
|
assert_eq!(actual.out, "[8193,3]");
|
|
}
|
|
|
|
#[test]
|
|
fn lines_multi_value_split() {
|
|
let actual = nu!(
|
|
cwd: "tests/fixtures/formats", pipeline(
|
|
"
|
|
open sample-simple.json
|
|
| get first second
|
|
| lines
|
|
| length
|
|
"
|
|
));
|
|
|
|
assert_eq!(actual.out, "6");
|
|
}
|
|
|
|
/// test whether this handles CRLF and LF in the same input
|
|
#[test]
|
|
fn lines_mixed_line_endings() {
|
|
let actual = nu!(
|
|
cwd: "tests/fixtures/formats", pipeline(
|
|
r#"
|
|
"foo\nbar\r\nquux" | lines | length
|
|
"#
|
|
));
|
|
|
|
assert_eq!(actual.out, "3");
|
|
}
|
|
|
|
#[cfg(not(windows))]
|
|
#[test]
|
|
fn lines_on_error() {
|
|
let actual = nu!("open . | lines");
|
|
|
|
assert!(actual.err.contains("Is a directory"));
|
|
}
|