about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authormarmeladema <xademax@gmail.com>2020-05-21 20:22:47 +0100
committermarmeladema <xademax@gmail.com>2020-07-15 21:37:16 +0100
commit4a96800aef385a70d7ee083058413c293c2f34c2 (patch)
tree4a3bf573a8214236108530807d27a2e032ca51c2 /src/test
parent7e11379f3b4c376fbb9a6c4d44f3286ccc28d149 (diff)
downloadrust-4a96800aef385a70d7ee083058413c293c2f34c2.tar.gz
rust-4a96800aef385a70d7ee083058413c293c2f34c2.zip
Constify most non-trait `Duration` methods as described in #72440
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/consts/duration-consts-2.rs57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/test/ui/consts/duration-consts-2.rs b/src/test/ui/consts/duration-consts-2.rs
new file mode 100644
index 00000000000..c8b39399331
--- /dev/null
+++ b/src/test/ui/consts/duration-consts-2.rs
@@ -0,0 +1,57 @@
+// run-pass
+
+#![feature(const_panic)]
+#![feature(duration_consts_2)]
+#![feature(div_duration)]
+
+use std::time::Duration;
+
+fn duration() {
+    const ZERO : Duration = Duration::new(0, 0);
+    assert_eq!(ZERO, Duration::from_secs(0));
+
+    const ONE : Duration = Duration::new(0, 1);
+    assert_eq!(ONE, Duration::from_nanos(1));
+
+    const MAX : Duration = Duration::new(u64::MAX, 1_000_000_000 - 1);
+
+    const MAX_ADD_ZERO : Option<Duration> = MAX.checked_add(ZERO);
+    assert_eq!(MAX_ADD_ZERO, Some(MAX));
+
+    const MAX_ADD_ONE : Option<Duration> = MAX.checked_add(ONE);
+    assert_eq!(MAX_ADD_ONE, None);
+
+    const ONE_SUB_ONE : Option<Duration> = ONE.checked_sub(ONE);
+    assert_eq!(ONE_SUB_ONE, Some(ZERO));
+
+    const ZERO_SUB_ONE : Option<Duration> = ZERO.checked_sub(ONE);
+    assert_eq!(ZERO_SUB_ONE, None);
+
+    const ONE_MUL_ONE : Option<Duration> = ONE.checked_mul(1);
+    assert_eq!(ONE_MUL_ONE, Some(ONE));
+
+    const MAX_MUL_TWO : Option<Duration> = MAX.checked_mul(2);
+    assert_eq!(MAX_MUL_TWO, None);
+
+    const ONE_DIV_ONE : Option<Duration> = ONE.checked_div(1);
+    assert_eq!(ONE_DIV_ONE, Some(ONE));
+
+    const ONE_DIV_ZERO : Option<Duration> = ONE.checked_div(0);
+    assert_eq!(ONE_DIV_ZERO, None);
+
+    const MAX_AS_F32 : f32 = MAX.as_secs_f32();
+    assert_eq!(MAX_AS_F32, 18446744000000000000.0_f32);
+
+    const MAX_AS_F64 : f64 = MAX.as_secs_f64();
+    assert_eq!(MAX_AS_F64, 18446744073709552000.0_f64);
+
+    const ONE_AS_F32 : f32 = ONE.div_duration_f32(ONE);
+    assert_eq!(ONE_AS_F32, 1.0_f32);
+
+    const ONE_AS_F64 : f64 = ONE.div_duration_f64(ONE);
+    assert_eq!(ONE_AS_F64, 1.0_f64);
+}
+
+fn main() {
+    duration();
+}