allow str from to convert more things to string (#2977)

* allow str from to convert more things to string

* fixed FileSize so it reports with units configured

* added tests
This commit is contained in:
Darren Schroeder
2021-01-29 07:43:35 -06:00
committed by GitHub
parent d0a2a02eea
commit 47c4b8e88a
20 changed files with 638 additions and 441 deletions

View File

@@ -128,7 +128,7 @@ fn converts_to_int() {
| rename number
| where number == 1
| get number
"#
));
@@ -343,57 +343,6 @@ fn substrings_the_input_and_treats_end_index_as_length_if_blank_end_index_given(
})
}
#[test]
fn from_decimal_correct_trailing_zeros() {
let actual = nu!(
cwd: ".", pipeline(
r#"
= 1.23000 | str from -d 3
"#
));
assert!(actual.out.contains("1.230"));
}
#[test]
fn from_int_decimal_correct_trailing_zeros() {
let actual = nu!(
cwd: ".", pipeline(
r#"
= 1.00000 | str from -d 3
"#
));
assert!(actual.out.contains("1.000"));
}
#[test]
fn from_int_decimal_trim_trailing_zeros() {
let actual = nu!(
cwd: ".", pipeline(
r#"
= 1.00000 | str from | format "{$it} flat"
"#
));
assert!(actual.out.contains("1 flat")); // "1" would match "1.0"
}
#[test]
fn from_table() {
let actual = nu!(
cwd: ".", pipeline(
r#"
echo '[{"name": "foo", "weight": 32.377}, {"name": "bar", "weight": 15.2}]'
| from json
| str from weight -d 2
"#
));
assert!(actual.out.contains("32.38"));
assert!(actual.out.contains("15.20"));
}
#[test]
fn str_reverse() {
let actual = nu!(