More fixes for bigint duration (#3557)

This commit is contained in:
JT 2021-06-05 04:54:18 +12:00 committed by GitHub
parent 51890baace
commit 1d0d0425d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 24 deletions

View file

@ -477,11 +477,7 @@ pub fn compute_values(
}
let y = y.as_bigint_and_exponent();
let z = y.0.to_i64();
match z {
Some(z) => Ok(x / z),
None => Err((left.type_name(), right.type_name())),
}
Ok(x / y.0)
}
_ => Err((left.type_name(), right.type_name())),
}?;

View file

@ -76,15 +76,6 @@ impl CommandArgs {
Ok((f(&evaluated_args.args)?, evaluated_args.input))
}
// pub fn process<'de, T: Deserialize<'de>>(self) -> Result<(T, InputStream), ShellError> {
// let args = self.evaluate_once()?;
// let call_info = args.call_info.clone();
// let mut deserializer = ConfigDeserializer::from_call_info(call_info);
// Ok((T::deserialize(&mut deserializer)?, args.input))
// }
}
pub struct EvaluatedCommandArgs {

View file

@ -587,21 +587,21 @@ impl Unit {
Unit::Tebibyte => filesize(size * 1024 * 1024 * 1024 * 1024),
Unit::Pebibyte => filesize(size * 1024 * 1024 * 1024 * 1024 * 1024),
Unit::Nanosecond => duration(size.to_i64().expect("Conversion should never fail.")),
Unit::Nanosecond => duration(size.to_bigint().expect("Conversion should never fail.")),
Unit::Microsecond => {
duration(size.to_i64().expect("Conversion should never fail.") * 1000)
duration(size.to_bigint().expect("Conversion should never fail.") * 1000)
}
Unit::Millisecond => {
duration(size.to_i64().expect("Conversion should never fail.") * 1000 * 1000)
}
Unit::Second => {
duration(size.to_i64().expect("Conversion should never fail.") * 1000 * 1000 * 1000)
duration(size.to_bigint().expect("Conversion should never fail.") * 1000 * 1000)
}
Unit::Second => duration(
size.to_bigint().expect("Conversion should never fail.") * 1000 * 1000 * 1000,
),
Unit::Minute => duration(
size.to_i64().expect("Conversion should never fail.") * 60 * 1000 * 1000 * 1000,
size.to_bigint().expect("Conversion should never fail.") * 60 * 1000 * 1000 * 1000,
),
Unit::Hour => duration(
size.to_i64().expect("Conversion should never fail.")
size.to_bigint().expect("Conversion should never fail.")
* 60
* 60
* 1000
@ -609,7 +609,7 @@ impl Unit {
* 1000,
),
Unit::Day => duration(
size.to_i64().expect("Conversion should never fail.")
size.to_bigint().expect("Conversion should never fail.")
* 24
* 60
* 60
@ -618,7 +618,7 @@ impl Unit {
* 1000,
),
Unit::Week => duration(
size.to_i64().expect("Conversion should never fail.")
size.to_bigint().expect("Conversion should never fail.")
* 7
* 24
* 60

View file

@ -898,6 +898,31 @@ fn table_with_commas() {
assert_eq!(actual.out, "141");
}
#[test]
fn duration_overflow() {
let actual = nu!(
cwd: ".", pipeline(
r#"
ls | get modified | each { $it + 10000000000000000day }
"#)
);
assert!(actual.err.contains("Duration overflow"));
}
#[test]
fn date_and_duration_overflow() {
let actual = nu!(
cwd: ".", pipeline(
r#"
ls | get modified | each { $it + 1000000000day }
"#)
);
// assert_eq!(actual.err, "overflow");
assert!(actual.err.contains("Duration and date addition overflow"));
}
mod parse {
use nu_test_support::nu;