diff --git a/src/assert.rs b/src/assert.rs new file mode 100644 index 0000000..12ef751 --- /dev/null +++ b/src/assert.rs @@ -0,0 +1,67 @@ +use std::fmt::Debug; + +pub fn assert(v: T) -> Assert { + Assert { v } +} + +pub struct Assert { + v: T, +} + +impl Assert { + #[track_caller] + pub fn is_true(self) { + assert!(self.v); + } + #[track_caller] + pub fn is_false(self) { + assert!(!self.v); + } +} + +impl Assert { + #[track_caller] + pub fn equals(self, other: U) + where + T: PartialEq, + { + assert_eq!(self.v, other); + } + #[track_caller] + pub fn not_equals(self, other: U) + where + T: PartialEq, + { + assert_ne!(self.v, other); + } +} + +impl> Assert { + #[track_caller] + pub fn contains(self, other: &str) { + assert!(self.v.as_ref().contains(other), "pattern '{other}' not found in string: {}", self.v.as_ref()); + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn assert_bool() { + assert(true).is_true(); + assert(false).is_false(); + } + + #[test] + fn assert_equal() { + assert(1).equals(1); + assert(2).not_equals(1); + } + + #[test] + fn assert_str() { + assert("uwu owo").contains("uwu"); + assert("uwu owo".to_owned()).contains("uwu"); + } +} diff --git a/src/hashmaps/mod.rs b/src/hashmaps/mod.rs index 5726bf7..66379bb 100644 --- a/src/hashmaps/mod.rs +++ b/src/hashmaps/mod.rs @@ -71,7 +71,7 @@ mod tests { for count in [1, 10, 100, 1000, 10_000, 100_000] { test_many::(count, RandomState::new()); } - test_many::(5000, BuildHasherDefault::::default()); + test_many::(1000, BuildHasherDefault::::default()); } fn test_many(count: usize, h: H) { diff --git a/src/lib.rs b/src/lib.rs index cfa10ab..c976be9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,6 +10,7 @@ pub mod sendsync; pub mod thin_u128; pub mod unroll_int; pub mod unsized_clone; +pub mod assert; pub mod safe_extern { pub use pm::safe_extern;