| extern crate wasm_bindgen_test; |
| use wasm_bindgen_test::*; |
| wasm_bindgen_test_configure!(run_in_browser); |
| // run these tests using: wasm-pack test --chrome --headless -- --features wasm-bindgen |
| let now = Instant::now(); |
| #[cfg(feature = "inaccurate")] |
| while now.elapsed().as_millis() == 0 {} |
| #[cfg(not(feature = "inaccurate"))] |
| assert!(now.elapsed().as_nanos() > 0); |
| 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; |
| let now = Instant::now(); |
| assert!(now.checked_add(Duration::from_millis(1)).is_some()); |
| now.checked_add(Duration::new(u64::MAX, ONE_BILLION - 1)) |
| let now = Instant::now(); |
| assert!(now.checked_sub(Duration::from_millis(1)).is_some()); |
| .checked_sub(Duration::new(u64::MAX, ONE_BILLION - 1)) |