From 5351b900c1c904e587a99590f474ac57c709c9e7 Mon Sep 17 00:00:00 2001 From: daxpedda Date: Mon, 29 Jan 2024 12:51:36 +0100 Subject: [PATCH] Add trait tests --- Cargo.toml | 3 +++ tests/traits.rs | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 tests/traits.rs diff --git a/Cargo.toml b/Cargo.toml index 52d602e..25a4ddd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,9 @@ version = "1.0.0" js-sys = "0.3.20" wasm-bindgen = { version = "0.2.70", default-features = false } +[dev-dependencies] +static_assertions = "1" + [target.'cfg(not(target_family = "wasm"))'.dev-dependencies] pollster = { version = "0.3", features = ["macro"] } diff --git a/tests/traits.rs b/tests/traits.rs new file mode 100644 index 0000000..dbc474e --- /dev/null +++ b/tests/traits.rs @@ -0,0 +1,24 @@ +use std::error::Error; +use std::fmt::{Debug, Display}; +use std::hash::Hash; +use std::ops::{Add, AddAssign, Sub, SubAssign}; +use std::panic::{RefUnwindSafe, UnwindSafe}; + +use static_assertions::{assert_impl_all, assert_not_impl_any}; +use web_time::{Duration, Instant, SystemTime, SystemTimeError}; + +#[cfg(target_family = "wasm")] +wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); + +#[cfg_attr(not(target_family = "wasm"), test)] +#[cfg_attr(target_family = "wasm", wasm_bindgen_test::wasm_bindgen_test)] +const fn basic() { + assert_impl_all!(Instant: Clone, Copy, Debug, Hash, Eq, PartialEq, Ord, PartialOrd, Send, Sync, Unpin, RefUnwindSafe, UnwindSafe); + assert_impl_all!(Instant: Add, AddAssign, Sub, SubAssign); + + assert_impl_all!(SystemTime: Clone, Copy, Debug, Hash, Eq, PartialEq, Ord, PartialOrd, Send, Sync, Unpin, RefUnwindSafe, UnwindSafe); + assert_impl_all!(SystemTime: Add, AddAssign, Sub, SubAssign); + + assert_impl_all!(SystemTimeError: Clone, Debug, Display, Error, Send, Sync, Unpin, RefUnwindSafe, UnwindSafe); + assert_not_impl_any!(SystemTimeError: Copy, Hash, Eq, PartialEq, Ord, PartialOrd); +}