diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/rust/instant/tests | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/instant/tests')
-rw-r--r-- | third_party/rust/instant/tests/wasm.rs | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/third_party/rust/instant/tests/wasm.rs b/third_party/rust/instant/tests/wasm.rs new file mode 100644 index 0000000000..7dacdc4f9e --- /dev/null +++ b/third_party/rust/instant/tests/wasm.rs @@ -0,0 +1,57 @@ +extern crate wasm_bindgen_test;
+
+use instant::{Instant, SystemTime};
+use std::time::Duration;
+use wasm_bindgen_test::*;
+
+wasm_bindgen_test_configure!(run_in_browser);
+// run these tests using: wasm-pack test --chrome --headless -- --features wasm-bindgen
+
+#[wasm_bindgen_test]
+fn test_instant_now() {
+ let now = Instant::now();
+ #[cfg(feature = "inaccurate")]
+ while now.elapsed().as_millis() == 0 {}
+ #[cfg(not(feature = "inaccurate"))]
+ assert!(now.elapsed().as_nanos() > 0);
+}
+
+#[wasm_bindgen_test]
+fn test_duration() {
+ let now = Instant::now();
+ let one_sec = Duration::from_secs(1);
+ assert!(now.elapsed() < one_sec);
+}
+
+// Duration::new will overflow when you have u64::MAX seconds and one billion nanoseconds.
+// <https://doc.rust-lang.org/std/time/struct.Duration.html#method.new>
+const ONE_BILLION: u32 = 1_000_000_000;
+
+#[wasm_bindgen_test]
+fn test_checked_add() {
+ let now = Instant::now();
+
+ assert!(now.checked_add(Duration::from_millis(1)).is_some());
+ assert_eq!(
+ None,
+ now.checked_add(Duration::new(u64::MAX, ONE_BILLION - 1))
+ );
+}
+
+#[wasm_bindgen_test]
+fn test_checked_sub() {
+ let now = Instant::now();
+
+ assert!(now.checked_sub(Duration::from_millis(1)).is_some());
+ assert!(now
+ .checked_sub(Duration::new(u64::MAX, ONE_BILLION - 1))
+ .is_none());
+}
+
+#[wasm_bindgen_test]
+fn test_system_time() {
+ assert!(SystemTime::UNIX_EPOCH
+ .duration_since(SystemTime::now())
+ .is_err());
+}
+
|