forked from nushell/nushell
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make
to text
line endings consistent for list (streams) (nushell#14166
) # Description Fixes nushell#14151 where `to text` treats list streams and lists values differently. # User-Facing Changes New line is always added after items in a list or record except for the last item if the `--no-newline` flag is provided.
- Loading branch information
1 parent
0744a27
commit fc52b9a
Showing
2 changed files
with
91 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,54 @@ | ||
use nu_test_support::nu; | ||
|
||
const LINE_LEN: usize = if cfg!(target_os = "windows") { 2 } else { 1 }; | ||
|
||
#[test] | ||
fn list_to_text() { | ||
let actual = nu!(r#"["foo" "bar" "baz"] | to text"#); | ||
fn list() { | ||
// Using `str length` since nu! strips newlines, grr | ||
let actual = nu!(r#"[] | to text | str length"#); | ||
assert_eq!(actual.out, "0"); | ||
|
||
let actual = nu!(r#"[a] | to text | str length"#); | ||
assert_eq!(actual.out, (1 + LINE_LEN).to_string()); | ||
|
||
let actual = nu!(r#"[a b] | to text | str length"#); | ||
assert_eq!(actual.out, (2 * (1 + LINE_LEN)).to_string()); | ||
} | ||
|
||
// The output should be the same when `to text` gets a ListStream instead of a Value::List. | ||
#[test] | ||
fn list_stream() { | ||
let actual = nu!(r#"[] | each {} | to text | str length"#); | ||
assert_eq!(actual.out, "0"); | ||
|
||
let actual = nu!(r#"[a] | each {} | to text | str length"#); | ||
assert_eq!(actual.out, (1 + LINE_LEN).to_string()); | ||
|
||
// these actually have newlines between them in the real world but nu! strips newlines, grr | ||
assert_eq!(actual.out, "foobarbaz"); | ||
let actual = nu!(r#"[a b] | each {} | to text | str length"#); | ||
assert_eq!(actual.out, (2 * (1 + LINE_LEN)).to_string()); | ||
} | ||
|
||
// the output should be the same when `to text` gets a ListStream instead of a Value::List | ||
#[test] | ||
fn list_stream_to_text() { | ||
// use `each` to convert the list to a ListStream | ||
let actual = nu!(r#"["foo" "bar" "baz"] | each {|i| $i} | to text"#); | ||
fn list_no_newline() { | ||
let actual = nu!(r#"[] | to text -n | str length"#); | ||
assert_eq!(actual.out, "0"); | ||
|
||
let actual = nu!(r#"[a] | to text -n | str length"#); | ||
assert_eq!(actual.out, "1"); | ||
|
||
let actual = nu!(r#"[a b] | to text -n | str length"#); | ||
assert_eq!(actual.out, (2 + LINE_LEN).to_string()); | ||
} | ||
|
||
// The output should be the same when `to text` gets a ListStream instead of a Value::List. | ||
#[test] | ||
fn list_stream_no_newline() { | ||
let actual = nu!(r#"[] | each {} | to text -n | str length"#); | ||
assert_eq!(actual.out, "0"); | ||
|
||
let actual = nu!(r#"[a] | each {} | to text -n | str length"#); | ||
assert_eq!(actual.out, "1"); | ||
|
||
// these actually have newlines between them in the real world but nu! strips newlines, grr | ||
assert_eq!(actual.out, "foobarbaz"); | ||
let actual = nu!(r#"[a b] | each {} | to text -n | str length"#); | ||
assert_eq!(actual.out, (2 + LINE_LEN).to_string()); | ||
} |