diff --git a/crates/nu-command/src/conversions/into/string.rs b/crates/nu-command/src/conversions/into/string.rs index 5ac6938598..38b05434f6 100644 --- a/crates/nu-command/src/conversions/into/string.rs +++ b/crates/nu-command/src/conversions/into/string.rs @@ -248,7 +248,7 @@ pub fn action( span, }, Value::Nothing { .. } => Value::String { - val: "nothing".to_string(), + val: "".to_string(), span, }, Value::Record { diff --git a/crates/nu-command/tests/commands/str_/into_string.rs b/crates/nu-command/tests/commands/str_/into_string.rs index be0438bd53..b2e0a2cdd4 100644 --- a/crates/nu-command/tests/commands/str_/into_string.rs +++ b/crates/nu-command/tests/commands/str_/into_string.rs @@ -1,4 +1,5 @@ -use nu_test_support::playground::{Dirs, Playground}; +use nu_test_support::fs::Stub::FileWithContentToBeTrimmed; +use nu_test_support::playground::Playground; use nu_test_support::{nu, pipeline}; #[test] @@ -6,7 +7,7 @@ fn from_range() { let actual = nu!( cwd: ".", pipeline( r#" - echo 1..5 | into string | to json + echo 1..5 | into string | to json -r "# ) ); @@ -79,7 +80,7 @@ fn from_filename() { let actual = nu!( cwd: dirs.test(), - "ls sample.toml | get name | into string" + "ls sample.toml | get name | into string | get 0" ); assert_eq!(actual.out, "sample.toml"); @@ -99,10 +100,12 @@ fn from_filesize() { let actual = nu!( cwd: dirs.test(), - "ls sample.toml | get size | into string" + "ls sample.toml | get size | into string | get 0" ); - assert_eq!(actual.out, "25 B"); + let expected = if cfg!(windows) { "27 B" } else { "25 B" }; + + assert_eq!(actual.out, expected); }) } @@ -111,7 +114,7 @@ fn from_decimal_correct_trailing_zeros() { let actual = nu!( cwd: ".", pipeline( r#" - = 1.23000 | into string -d 3 + 1.23000 | into string -d 3 "# )); @@ -123,7 +126,7 @@ fn from_int_decimal_correct_trailing_zeros() { let actual = nu!( cwd: ".", pipeline( r#" - = 1.00000 | into string -d 3 + 1.00000 | into string -d 3 "# )); @@ -135,7 +138,7 @@ fn from_int_decimal_trim_trailing_zeros() { let actual = nu!( cwd: ".", pipeline( r#" - = 1.00000 | into string | format "{$it} flat" + 1.00000 | into string | $"($in) flat" "# )); @@ -156,3 +159,15 @@ fn from_table() { assert!(actual.out.contains("32.38")); assert!(actual.out.contains("15.20")); } + +#[test] +fn from_nothing() { + let actual = nu!( + cwd: ".", pipeline( + r#" + $nothing | into string + "# + )); + + assert_eq!(actual.out, ""); +} diff --git a/crates/nu-command/tests/commands/str_/mod.rs b/crates/nu-command/tests/commands/str_/mod.rs index 7e589fd88e..7a05c02317 100644 --- a/crates/nu-command/tests/commands/str_/mod.rs +++ b/crates/nu-command/tests/commands/str_/mod.rs @@ -1,4 +1,5 @@ mod collect; +mod into_string; use nu_test_support::fs::Stub::FileWithContent; use nu_test_support::playground::Playground;