Skip to content

Commit

Permalink
Add trait tests
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpedda committed Jan 29, 2024
1 parent 848ca47 commit 5351b90
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }

Expand Down
24 changes: 24 additions & 0 deletions tests/traits.rs
Original file line number Diff line number Diff line change
@@ -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<Duration>, AddAssign<Duration>, Sub<Duration>, SubAssign<Duration>);

assert_impl_all!(SystemTime: Clone, Copy, Debug, Hash, Eq, PartialEq, Ord, PartialOrd, Send, Sync, Unpin, RefUnwindSafe, UnwindSafe);
assert_impl_all!(SystemTime: Add<Duration>, AddAssign<Duration>, Sub<Duration>, SubAssign<Duration>);

assert_impl_all!(SystemTimeError: Clone, Debug, Display, Error, Send, Sync, Unpin, RefUnwindSafe, UnwindSafe);
assert_not_impl_any!(SystemTimeError: Copy, Hash, Eq, PartialEq, Ord, PartialOrd);
}

0 comments on commit 5351b90

Please sign in to comment.