Add 'str from' subcommand (#2125)

* add human, precision commands

* add 'str from' subcommand (converted from human/precision commands)

move human tests to str from

* add default locale, platform-specific SystemLocale use

* fix platform specific num-format dependency, remove invalid test

* change 'str from' localization to static num_format::Locale::en

* minor cleanup, nudge ci

* re-attempt ci
This commit is contained in:
bailey-layzer
2020-07-11 20:57:39 -07:00
committed by GitHub
parent 8d03cf5b02
commit bdef5d7d72
8 changed files with 383 additions and 4 deletions

View File

@ -340,3 +340,54 @@ fn substrings_the_input_and_treats_end_index_as_length_if_blank_end_index_given(
assert_eq!(actual.out, "arepas");
})
}
#[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"));
}