summaryrefslogtreecommitdiffstats
path: root/library/core/tests/time.rs
diff options
context:
space:
mode:
Diffstat (limited to 'library/core/tests/time.rs')
-rw-r--r--library/core/tests/time.rs32
1 files changed, 31 insertions, 1 deletions
diff --git a/library/core/tests/time.rs b/library/core/tests/time.rs
index fe2d2f241..a05128de4 100644
--- a/library/core/tests/time.rs
+++ b/library/core/tests/time.rs
@@ -197,9 +197,31 @@ fn correct_sum() {
#[test]
fn debug_formatting_extreme_values() {
assert_eq!(
- format!("{:?}", Duration::new(18_446_744_073_709_551_615, 123_456_789)),
+ format!("{:?}", Duration::new(u64::MAX, 123_456_789)),
"18446744073709551615.123456789s"
);
+ assert_eq!(format!("{:.0?}", Duration::MAX), "18446744073709551616s");
+ assert_eq!(format!("{:.0?}", Duration::new(u64::MAX, 500_000_000)), "18446744073709551616s");
+ assert_eq!(format!("{:.0?}", Duration::new(u64::MAX, 499_999_999)), "18446744073709551615s");
+ assert_eq!(
+ format!("{:.3?}", Duration::new(u64::MAX, 999_500_000)),
+ "18446744073709551616.000s"
+ );
+ assert_eq!(
+ format!("{:.3?}", Duration::new(u64::MAX, 999_499_999)),
+ "18446744073709551615.999s"
+ );
+ assert_eq!(
+ format!("{:.8?}", Duration::new(u64::MAX, 999_999_995)),
+ "18446744073709551616.00000000s"
+ );
+ assert_eq!(
+ format!("{:.8?}", Duration::new(u64::MAX, 999_999_994)),
+ "18446744073709551615.99999999s"
+ );
+ assert_eq!(format!("{:21.0?}", Duration::MAX), "18446744073709551616s");
+ assert_eq!(format!("{:22.0?}", Duration::MAX), "18446744073709551616s ");
+ assert_eq!(format!("{:24.0?}", Duration::MAX), "18446744073709551616s ");
}
#[test]
@@ -445,3 +467,11 @@ fn duration_const() {
const SATURATING_MUL: Duration = MAX.saturating_mul(2);
assert_eq!(SATURATING_MUL, MAX);
}
+
+#[test]
+fn from_neg_zero() {
+ assert_eq!(Duration::try_from_secs_f32(-0.0), Ok(Duration::ZERO));
+ assert_eq!(Duration::try_from_secs_f64(-0.0), Ok(Duration::ZERO));
+ assert_eq!(Duration::from_secs_f32(-0.0), Duration::ZERO);
+ assert_eq!(Duration::from_secs_f64(-0.0), Duration::ZERO);
+}