mirror of
https://github.com/nushell/nushell.git
synced 2024-11-26 18:33:50 +01:00
fixes to nuon
for inf, -inf, and NaN (#5818)
This commit is contained in:
parent
a17d46f200
commit
28c21121cf
@ -87,7 +87,11 @@ fn value_to_string(v: &Value, span: Span) -> Result<String, ShellError> {
|
|||||||
)),
|
)),
|
||||||
Value::Filesize { val, .. } => Ok(format!("{}b", *val)),
|
Value::Filesize { val, .. } => Ok(format!("{}b", *val)),
|
||||||
Value::Float { val, .. } => {
|
Value::Float { val, .. } => {
|
||||||
if &val.round() == val {
|
if &val.round() == val
|
||||||
|
&& val != &f64::NAN
|
||||||
|
&& val != &f64::INFINITY
|
||||||
|
&& val != &f64::NEG_INFINITY
|
||||||
|
{
|
||||||
Ok(format!("{}.0", *val))
|
Ok(format!("{}.0", *val))
|
||||||
} else {
|
} else {
|
||||||
Ok(format!("{}", *val))
|
Ok(format!("{}", *val))
|
||||||
|
@ -202,3 +202,39 @@ fn float_doesnt_become_int() {
|
|||||||
|
|
||||||
assert_eq!(actual.out, "1.0")
|
assert_eq!(actual.out, "1.0")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn float_inf_parsed_properly() {
|
||||||
|
let actual = nu!(
|
||||||
|
cwd: "tests/fixtures/formats", pipeline(
|
||||||
|
r#"
|
||||||
|
inf | to nuon
|
||||||
|
"#
|
||||||
|
));
|
||||||
|
|
||||||
|
assert_eq!(actual.out, "inf")
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn float_neg_inf_parsed_properly() {
|
||||||
|
let actual = nu!(
|
||||||
|
cwd: "tests/fixtures/formats", pipeline(
|
||||||
|
r#"
|
||||||
|
-inf | to nuon
|
||||||
|
"#
|
||||||
|
));
|
||||||
|
|
||||||
|
assert_eq!(actual.out, "-inf")
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn float_nan_parsed_properly() {
|
||||||
|
let actual = nu!(
|
||||||
|
cwd: "tests/fixtures/formats", pipeline(
|
||||||
|
r#"
|
||||||
|
NaN | to nuon
|
||||||
|
"#
|
||||||
|
));
|
||||||
|
|
||||||
|
assert_eq!(actual.out, "NaN")
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user