mirror of
https://github.com/nushell/nushell.git
synced 2024-12-12 18:20:55 +01:00
bbf0b45c59
# Description We made the decision that our floating point type should be referred to as `float` over `decimal`. Commands were updated by #9979 and #10320 Now make the internal codebase consistent in referring to this data type as `float`. Work for #10332 # User-Facing Changes `decimal` has been removed as a type name/symbol. Instead of ```nushell def foo [bar: decimal] decimal -> decimal {} ``` use ```nushell def foo [bar: float] float -> float {} ``` Potential effect of `SyntaxShape`'s `Display` implementation now also referring to `float` instead of `decimal` # Details - Rename `SyntaxShape::Decimal` to `Float` - Update `Display for SyntaxShape` to `float` - Update error message + fn name in dataframe code - Fix docs in command examples - Rename tests that are float specific - Update doccomment on `SyntaxShape` - Update comment in script # Tests + Formatting Updates the names of some tests
222 lines
4.3 KiB
Rust
222 lines
4.3 KiB
Rust
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
|
use nu_test_support::playground::Playground;
|
|
use nu_test_support::{nu, pipeline};
|
|
|
|
#[test]
|
|
fn from_range() {
|
|
let actual = nu!(r#"
|
|
echo 1..5 | into string | to json -r
|
|
"#);
|
|
|
|
assert_eq!(actual.out, "[\"1\",\"2\",\"3\",\"4\",\"5\"]");
|
|
}
|
|
|
|
#[test]
|
|
fn from_number() {
|
|
let actual = nu!(r#"
|
|
echo 5 | into string
|
|
"#);
|
|
|
|
assert_eq!(actual.out, "5");
|
|
}
|
|
|
|
#[test]
|
|
fn from_float() {
|
|
let actual = nu!(r#"
|
|
echo 1.5 | into string
|
|
"#);
|
|
|
|
assert_eq!(actual.out, "1.5");
|
|
}
|
|
|
|
#[test]
|
|
fn from_boolean() {
|
|
let actual = nu!(r#"
|
|
echo true | into string
|
|
"#);
|
|
|
|
assert_eq!(actual.out, "true");
|
|
}
|
|
|
|
#[test]
|
|
fn from_string() {
|
|
let actual = nu!(r#"
|
|
echo "one" | into string
|
|
"#);
|
|
|
|
assert_eq!(actual.out, "one");
|
|
}
|
|
|
|
#[test]
|
|
fn from_filename() {
|
|
Playground::setup("from_filename", |dirs, sandbox| {
|
|
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
|
"sample.toml",
|
|
r#"
|
|
[dependency]
|
|
name = "nu"
|
|
"#,
|
|
)]);
|
|
|
|
let actual = nu!(
|
|
cwd: dirs.test(),
|
|
"ls sample.toml | get name | into string | get 0"
|
|
);
|
|
|
|
assert_eq!(actual.out, "sample.toml");
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn from_filesize() {
|
|
Playground::setup("from_filesize", |dirs, sandbox| {
|
|
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
|
"sample.toml",
|
|
r#"
|
|
[dependency]
|
|
name = "nu"
|
|
"#,
|
|
)]);
|
|
|
|
let actual = nu!(
|
|
cwd: dirs.test(),
|
|
"ls sample.toml | get size | into string | get 0"
|
|
);
|
|
|
|
let expected = if cfg!(windows) { "27 B" } else { "25 B" };
|
|
|
|
assert_eq!(actual.out, expected);
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn from_float_correct_trailing_zeros() {
|
|
let actual = nu!(r#"
|
|
1.23000 | into string -d 3
|
|
"#);
|
|
|
|
assert!(actual.out.contains("1.230"));
|
|
}
|
|
|
|
#[test]
|
|
fn from_int_float_correct_trailing_zeros() {
|
|
let actual = nu!(r#"
|
|
1.00000 | into string -d 3
|
|
"#);
|
|
|
|
assert!(actual.out.contains("1.000"));
|
|
}
|
|
|
|
#[test]
|
|
fn from_int_float_trim_trailing_zeros() {
|
|
let actual = nu!(r#"
|
|
1.00000 | into string | $"($in) flat"
|
|
"#);
|
|
|
|
assert!(actual.out.contains("1 flat")); // "1" would match "1.0"
|
|
}
|
|
|
|
#[test]
|
|
fn from_table() {
|
|
let actual = nu!(pipeline(
|
|
r#"
|
|
echo '[{"name": "foo", "weight": 32.377}, {"name": "bar", "weight": 15.2}]'
|
|
| from json
|
|
| into string weight -d 2
|
|
"#
|
|
));
|
|
|
|
assert!(actual.out.contains("32.38"));
|
|
assert!(actual.out.contains("15.20"));
|
|
}
|
|
|
|
#[test]
|
|
fn from_nothing() {
|
|
let actual = nu!(r#"
|
|
null | into string
|
|
"#);
|
|
|
|
assert_eq!(actual.out, "");
|
|
}
|
|
|
|
#[test]
|
|
fn int_into_string() {
|
|
let actual = nu!(r#"
|
|
10 | into string
|
|
"#);
|
|
|
|
assert_eq!(actual.out, "10");
|
|
}
|
|
|
|
#[test]
|
|
fn int_into_string_decimals_0() {
|
|
let actual = nu!(
|
|
locale: "en_US.UTF-8",
|
|
pipeline(
|
|
r#"
|
|
10 | into string --decimals 0
|
|
"#
|
|
)
|
|
);
|
|
|
|
assert_eq!(actual.out, "10");
|
|
}
|
|
|
|
#[test]
|
|
fn int_into_string_decimals_1() {
|
|
let actual = nu!(
|
|
locale: "en_US.UTF-8",
|
|
pipeline(
|
|
r#"
|
|
10 | into string --decimals 1
|
|
"#
|
|
)
|
|
);
|
|
|
|
assert_eq!(actual.out, "10.0");
|
|
}
|
|
|
|
#[test]
|
|
fn int_into_string_decimals_10() {
|
|
let actual = nu!(
|
|
locale: "en_US.UTF-8",
|
|
pipeline(
|
|
r#"
|
|
10 | into string --decimals 10
|
|
"#
|
|
)
|
|
);
|
|
|
|
assert_eq!(actual.out, "10.0000000000");
|
|
}
|
|
|
|
#[test]
|
|
fn int_into_string_decimals_respects_system_locale_de() {
|
|
// Set locale to `de_DE`, which uses `,` (comma) as decimal separator
|
|
let actual = nu!(
|
|
locale: "de_DE.UTF-8",
|
|
pipeline(
|
|
r#"
|
|
10 | into string --decimals 1
|
|
"#
|
|
)
|
|
);
|
|
|
|
assert_eq!(actual.out, "10,0");
|
|
}
|
|
|
|
#[test]
|
|
fn int_into_string_decimals_respects_system_locale_en() {
|
|
// Set locale to `en_US`, which uses `.` (period) as decimal separator
|
|
let actual = nu!(
|
|
locale: "en_US.UTF-8",
|
|
pipeline(
|
|
r#"
|
|
10 | into string --decimals 1
|
|
"#
|
|
)
|
|
);
|
|
|
|
assert_eq!(actual.out, "10.0");
|
|
}
|