mirror of
https://github.com/nushell/nushell
synced 2025-01-27 20:35:43 +00:00
Use iterator chain instead of string concat. (#2655)
* Use iterator chain instead of string concat * Add regression test for multi-value lines
This commit is contained in:
parent
6817b472d0
commit
5770b15270
3 changed files with 22 additions and 3 deletions
|
@ -75,9 +75,9 @@ async fn lines(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputSt
|
||||||
} => {
|
} => {
|
||||||
let mut leftover_string = leftover_string.lock();
|
let mut leftover_string = leftover_string.lock();
|
||||||
|
|
||||||
let st = (&*leftover_string).clone() + &st;
|
let lo_lines = (&*leftover_string).lines().map(|x| x.to_string());
|
||||||
|
let st_lines = st.lines().map(|x| x.to_string());
|
||||||
let mut lines: Vec<String> = st.lines().map(|x| x.to_string()).collect();
|
let mut lines: Vec<String> = lo_lines.chain(st_lines).collect();
|
||||||
|
|
||||||
leftover_string.clear();
|
leftover_string.clear();
|
||||||
|
|
||||||
|
|
|
@ -34,3 +34,18 @@ fn lines_proper_buffering() {
|
||||||
|
|
||||||
assert_eq!(actual.out, "[8194,4]");
|
assert_eq!(actual.out, "[8194,4]");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn lines_multi_value_split() {
|
||||||
|
let actual = nu!(
|
||||||
|
cwd: "tests/fixtures/formats", pipeline(
|
||||||
|
r#"
|
||||||
|
open sample-simple.json
|
||||||
|
| get first second
|
||||||
|
| lines
|
||||||
|
| count
|
||||||
|
"#
|
||||||
|
));
|
||||||
|
|
||||||
|
assert_eq!(actual.out, "6");
|
||||||
|
}
|
||||||
|
|
4
tests/fixtures/formats/sample-simple.json
vendored
Normal file
4
tests/fixtures/formats/sample-simple.json
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"first": "first",
|
||||||
|
"second": "this\nshould\nbe\nseparate\nlines"
|
||||||
|
}
|
Loading…
Reference in a new issue