use std::cmp::{PartialEq, Eq, PartialOrd, Ord}; use std::hash::{DefaultHasher, Hash, Hasher}; use std::borrow::Borrow; use std::mem::size_of; use std::ops::Deref; use std::fmt::Debug; use std::sync::Arc; use std::rc::Rc; use our_string::{OurBytes, Comrade}; fn hash(t: &T) -> u64 { let mut s = DefaultHasher::new(); t.hash(&mut s); s.finish() } fn is_inline(v: &OurBytes) -> bool { let l = v.len(); let s = v.as_slice() as *const [u8] as *const () as usize; let v = v as *const OurBytes as *const () as usize; s >= v && s + l <= v + size_of::>() } #[test] fn test_sizes() { assert_eq!(size_of::>, { size_of::() - 2 }>>>(), size_of::()); assert_eq!(size_of::>, { size_of::() - 1 }>>(), size_of::()); assert_eq!(size_of::>, { size_of::() - 1 - size_of::() }>>(), size_of::() - size_of::()); assert_eq!(size_of::>, { size_of::() - 2 }>>>(), size_of::()); assert_eq!(size_of::>, { size_of::() - 1 }>>(), size_of::()); assert_eq!(size_of::>, { size_of::() - 1 - size_of::() }>>(), size_of::() - size_of::()); assert_eq!(size_of::, { size_of::() - 1 }>>(), size_of::()); assert_eq!(size_of::, { size_of::() - 1 }>>(), size_of::()); } #[test] fn test_traits() { macro_rules! assert_impl { ($t:ty : $($tr:tt)*) => {{ fn checker() {} checker::<$t>(); }}; } assert_impl!(OurBytes>, 8> : Hash + Clone + Debug + PartialEq + Eq + PartialOrd + Ord + Default + AsRef<[u8]> + Borrow<[u8]> + Deref + for<'a> From<&'a [u8]> + From>>); assert_impl!(OurBytes, 8> : Hash + Clone + Debug + PartialEq + Eq + PartialOrd + Ord + Default + AsRef<[u8]> + Borrow<[u8]> + Deref + for<'a> From<&'a [u8]> + From>); assert_impl!(OurBytes>, 8> : Send + Sync + Hash + Clone + Debug + PartialEq + Eq + PartialOrd + Ord + Default + AsRef<[u8]> + Borrow<[u8]> + Deref + for<'a> From<&'a [u8]> + From>>); assert_impl!(OurBytes, 8> : Send + Sync + Hash + Clone + Debug + PartialEq + Eq + PartialOrd + Ord + Default + AsRef<[u8]> + Borrow<[u8]> + Deref + for<'a> From<&'a [u8]> + From>); } #[test] fn test_clone() { let a = OurBytes::>, 5>::from([5u8, 2, 7, 5, 2, 5, 4, 1, 7, 5].as_slice()); let b = a.clone(); assert_eq!(a, b); assert_eq!(a.as_slice(), b.as_slice()); assert_eq!(a.as_slice() as *const [u8], b.as_slice() as *const [u8]); } #[cfg(not(miri))] proptest::proptest! { #[test] fn proptest_clone(s: Vec) { let a = OurBytes::>, 5>::from(s.as_slice()); let b = a.clone(); assert_eq!(a, b); assert_eq!(a.as_slice(), b.as_slice()); if a.len() > 5 { assert_eq!(a.as_slice() as *const [u8], b.as_slice() as *const [u8]); } } } #[test] fn test_new_default() { const X: OurBytes>, 10> = OurBytes::new(); const Y: OurBytes, 10> = OurBytes::new(); assert_eq!(X.len(), 0); assert_eq!(X.is_empty(), true); assert_eq!(X.as_slice().is_empty(), true); assert_eq!(Y.len(), 0); assert_eq!(Y.is_empty(), true); assert_eq!(Y.as_slice().is_empty(), true); assert_eq!(OurBytes::>, 10>::default().len(), 0); assert_eq!(OurBytes::>, 10>::default().is_empty(), true); assert_eq!(OurBytes::>, 10>::default().as_slice().is_empty(), true); assert_eq!(OurBytes::, 10>::default().len(), 0); assert_eq!(OurBytes::, 10>::default().is_empty(), true); assert_eq!(OurBytes::, 10>::default().as_slice().is_empty(), true); } #[test] fn test_from_slice_inlining() { assert_eq!(is_inline(&OurBytes::>, 10>::from(&[] as &[u8])), true); assert_eq!(is_inline(&OurBytes::>, 10>::from(&[4u8] as &[u8])), true); assert_eq!(is_inline(&OurBytes::>, 10>::from(&[4u8, 6] as &[u8])), true); assert_eq!(is_inline(&OurBytes::>, 10>::from(&[4u8, 6, 1] as &[u8])), true); assert_eq!(is_inline(&OurBytes::>, 10>::from(&[4u8, 6, 1, 84] as &[u8])), true); assert_eq!(is_inline(&OurBytes::>, 10>::from(&[4u8, 6, 1, 84, 255] as &[u8])), true); assert_eq!(is_inline(&OurBytes::>, 10>::from(&[4u8, 6, 1, 84, 255, 12] as &[u8])), true); assert_eq!(is_inline(&OurBytes::>, 10>::from(&[4u8, 6, 1, 84, 255, 12, 23, 98, 169, 23] as &[u8])), true); assert_eq!(is_inline(&OurBytes::>, 10>::from(&[4u8, 6, 1, 84, 255, 12, 23, 98, 169, 23, 45] as &[u8])), false); assert_eq!(is_inline(&OurBytes::>, 10>::from(&[4u8, 6, 1, 84, 255, 12, 23, 98, 169, 23, 45, 65] as &[u8])), false); assert_eq!(is_inline(&OurBytes::>, 10>::from(&[4u8, 6, 1, 84, 255, 12, 23, 98, 169, 23, 45, 65, 56, 23, 76, 45, 98, 23, 56] as &[u8])), false); assert_eq!(is_inline(&OurBytes::>, 4>::from(&[] as &[u8])), true); assert_eq!(is_inline(&OurBytes::>, 4>::from(&[4u8] as &[u8])), true); assert_eq!(is_inline(&OurBytes::>, 4>::from(&[4u8, 6] as &[u8])), true); assert_eq!(is_inline(&OurBytes::>, 4>::from(&[4u8, 6, 1] as &[u8])), true); assert_eq!(is_inline(&OurBytes::>, 4>::from(&[4u8, 6, 1, 84] as &[u8])), true); assert_eq!(is_inline(&OurBytes::>, 4>::from(&[4u8, 6, 1, 84, 255] as &[u8])), false); assert_eq!(is_inline(&OurBytes::>, 4>::from(&[4u8, 6, 1, 84, 255, 12] as &[u8])), false); assert_eq!(is_inline(&OurBytes::>, 4>::from(&[4u8, 6, 1, 84, 255, 12, 23, 98, 169, 23] as &[u8])), false); assert_eq!(is_inline(&OurBytes::>, 4>::from(&[4u8, 6, 1, 84, 255, 12, 23, 98, 169, 23, 45] as &[u8])), false); assert_eq!(is_inline(&OurBytes::>, 4>::from(&[4u8, 6, 1, 84, 255, 12, 23, 98, 169, 23, 45, 65] as &[u8])), false); assert_eq!(is_inline(&OurBytes::>, 4>::from(&[4u8, 6, 1, 84, 255, 12, 23, 98, 169, 23, 45, 65, 56, 23, 76, 45, 98, 23, 56] as &[u8])), false); } #[test] fn test_from_slice() { assert_eq!(&*OurBytes::>, 10>::from(&[] as &[u8]) as &[u8], &[] as &[u8]); assert_eq!(&*OurBytes::>, 10>::from(&[4u8] as &[u8]) as &[u8], &[4u8] as &[u8]); assert_eq!(&*OurBytes::>, 10>::from(&[4u8, 6] as &[u8]) as &[u8], &[4u8, 6] as &[u8]); assert_eq!(&*OurBytes::>, 10>::from(&[4u8, 6, 1] as &[u8]) as &[u8], &[4u8, 6, 1] as &[u8]); assert_eq!(&*OurBytes::>, 10>::from(&[4u8, 6, 1, 84] as &[u8]) as &[u8], &[4u8, 6, 1, 84] as &[u8]); assert_eq!(&*OurBytes::>, 10>::from(&[4u8, 6, 1, 84, 255] as &[u8]) as &[u8], &[4u8, 6, 1, 84, 255] as &[u8]); assert_eq!(&*OurBytes::>, 10>::from(&[4u8, 6, 1, 84, 255, 12] as &[u8]) as &[u8], &[4u8, 6, 1, 84, 255, 12] as &[u8]); assert_eq!(&*OurBytes::>, 10>::from(&[4u8, 6, 1, 84, 255, 12, 23, 98, 169, 23] as &[u8]) as &[u8], &[4u8, 6, 1, 84, 255, 12, 23, 98, 169, 23] as &[u8]); assert_eq!(&*OurBytes::>, 10>::from(&[4u8, 6, 1, 84, 255, 12, 23, 98, 169, 23, 45] as &[u8]) as &[u8], &[4u8, 6, 1, 84, 255, 12, 23, 98, 169, 23, 45] as &[u8]); assert_eq!(&*OurBytes::>, 10>::from(&[4u8, 6, 1, 84, 255, 12, 23, 98, 169, 23, 45, 65] as &[u8]) as &[u8], &[4u8, 6, 1, 84, 255, 12, 23, 98, 169, 23, 45, 65] as &[u8]); assert_eq!(&*OurBytes::>, 10>::from(&[4u8, 6, 1, 84, 255, 12, 23, 98, 169, 23, 45, 65, 56, 23, 76, 45, 98, 23, 56] as &[u8]) as &[u8], &[4u8, 6, 1, 84, 255, 12, 23, 98, 169, 23, 45, 65, 56, 23, 76, 45, 98, 23, 56] as &[u8]); assert_eq!(&*OurBytes::>, 4>::from(&[] as &[u8]) as &[u8], &[] as &[u8]); assert_eq!(&*OurBytes::>, 4>::from(&[4u8] as &[u8]) as &[u8], &[4u8] as &[u8]); assert_eq!(&*OurBytes::>, 4>::from(&[4u8, 6] as &[u8]) as &[u8], &[4u8, 6] as &[u8]); assert_eq!(&*OurBytes::>, 4>::from(&[4u8, 6, 1] as &[u8]) as &[u8], &[4u8, 6, 1] as &[u8]); assert_eq!(&*OurBytes::>, 4>::from(&[4u8, 6, 1, 84] as &[u8]) as &[u8], &[4u8, 6, 1, 84] as &[u8]); assert_eq!(&*OurBytes::>, 4>::from(&[4u8, 6, 1, 84, 255] as &[u8]) as &[u8], &[4u8, 6, 1, 84, 255] as &[u8]); assert_eq!(&*OurBytes::>, 4>::from(&[4u8, 6, 1, 84, 255, 12] as &[u8]) as &[u8], &[4u8, 6, 1, 84, 255, 12] as &[u8]); assert_eq!(&*OurBytes::>, 4>::from(&[4u8, 6, 1, 84, 255, 12, 23, 98, 169, 23] as &[u8]) as &[u8], &[4u8, 6, 1, 84, 255, 12, 23, 98, 169, 23] as &[u8]); assert_eq!(&*OurBytes::>, 4>::from(&[4u8, 6, 1, 84, 255, 12, 23, 98, 169, 23, 45] as &[u8]) as &[u8], &[4u8, 6, 1, 84, 255, 12, 23, 98, 169, 23, 45] as &[u8]); assert_eq!(&*OurBytes::>, 4>::from(&[4u8, 6, 1, 84, 255, 12, 23, 98, 169, 23, 45, 65] as &[u8]) as &[u8], &[4u8, 6, 1, 84, 255, 12, 23, 98, 169, 23, 45, 65] as &[u8]); assert_eq!(&*OurBytes::>, 4>::from(&[4u8, 6, 1, 84, 255, 12, 23, 98, 169, 23, 45, 65, 56, 23, 76, 45, 98, 23, 56] as &[u8]) as &[u8], &[4u8, 6, 1, 84, 255, 12, 23, 98, 169, 23, 45, 65, 56, 23, 76, 45, 98, 23, 56] as &[u8]); } #[cfg(not(miri))] proptest::proptest! { #[test] fn proptest_from_slice(s: Vec) { assert_eq!(&*OurBytes::>, 10>::from(s.as_slice()) as &[u8], s.as_slice()); assert_eq!(&*OurBytes::>, 10>::from(s.as_slice()) as &[u8], s.as_slice()); assert_eq!(&*OurBytes::, 10>::from(s.as_slice()) as &[u8], s.as_slice()); assert_eq!(&*OurBytes::, 10>::from(s.as_slice()) as &[u8], s.as_slice()); assert_eq!(OurBytes::>, 10>::from(s.as_slice()).as_slice() as &[u8], s.as_slice()); assert_eq!(OurBytes::>, 10>::from(s.as_slice()).as_slice() as &[u8], s.as_slice()); assert_eq!(OurBytes::, 10>::from(s.as_slice()).as_slice() as &[u8], s.as_slice()); assert_eq!(OurBytes::, 10>::from(s.as_slice()).as_slice() as &[u8], s.as_slice()); assert_eq!(OurBytes::>, 10>::from(s.as_slice()).as_ref() as &[u8], s.as_slice()); assert_eq!(OurBytes::>, 10>::from(s.as_slice()).as_ref() as &[u8], s.as_slice()); assert_eq!(OurBytes::, 10>::from(s.as_slice()).as_ref() as &[u8], s.as_slice()); assert_eq!(OurBytes::, 10>::from(s.as_slice()).as_ref() as &[u8], s.as_slice()); assert_eq!(<_ as AsRef<[u8]>>::as_ref(&OurBytes::>, 10>::from(s.as_slice())) as &[u8], s.as_slice()); assert_eq!(<_ as AsRef<[u8]>>::as_ref(&OurBytes::>, 10>::from(s.as_slice())) as &[u8], s.as_slice()); assert_eq!(<_ as AsRef<[u8]>>::as_ref(&OurBytes::, 10>::from(s.as_slice())) as &[u8], s.as_slice()); assert_eq!(<_ as AsRef<[u8]>>::as_ref(&OurBytes::, 10>::from(s.as_slice())) as &[u8], s.as_slice()); assert_eq!(OurBytes::>, 10>::from(s.as_slice()).borrow() as &[u8], s.as_slice()); assert_eq!(OurBytes::>, 10>::from(s.as_slice()).borrow() as &[u8], s.as_slice()); assert_eq!(OurBytes::, 10>::from(s.as_slice()).borrow() as &[u8], s.as_slice()); assert_eq!(OurBytes::, 10>::from(s.as_slice()).borrow() as &[u8], s.as_slice()); assert_eq!(<_ as Borrow<[u8]>>::borrow(&OurBytes::>, 10>::from(s.as_slice())) as &[u8], s.as_slice()); assert_eq!(<_ as Borrow<[u8]>>::borrow(&OurBytes::>, 10>::from(s.as_slice())) as &[u8], s.as_slice()); assert_eq!(<_ as Borrow<[u8]>>::borrow(&OurBytes::, 10>::from(s.as_slice())) as &[u8], s.as_slice()); assert_eq!(<_ as Borrow<[u8]>>::borrow(&OurBytes::, 10>::from(s.as_slice())) as &[u8], s.as_slice()); } } #[test] fn test_hash() { assert_eq!(hash(&OurBytes::>, 4>::from(&[] as &[u8])), hash(&[].as_slice() as &&[u8])); assert_eq!(hash(&OurBytes::>, 4>::from(&[7u8] as &[u8])), hash(&[7u8].as_slice())); assert_eq!(hash(&OurBytes::>, 4>::from(&[4u8, 6] as &[u8])), hash(&[4u8, 6].as_slice())); assert_eq!(hash(&OurBytes::>, 4>::from(&[4u8, 6, 7, 4, 5, 2, 4, 3, 2, 255, 160, 2] as &[u8])), hash(&[4u8, 6, 7, 4, 5, 2, 4, 3, 2, 255, 160, 2].as_slice())); } #[cfg(not(miri))] proptest::proptest! { #[test] fn proptest_hash(s: Vec) { assert_eq!(hash(&OurBytes::>, 4>::from(s.as_slice())), hash(&s.as_slice())); assert_eq!(hash(&OurBytes::, 4>::from(s.as_slice())), hash(&s.as_slice())); assert_eq!(hash(&OurBytes::>, 4>::from(s.as_slice())), hash(&s.as_slice())); assert_eq!(hash(&OurBytes::, 4>::from(s.as_slice())), hash(&s.as_slice())); } } #[test] fn test_from_comrade_inlining() { assert_eq!(is_inline(&OurBytes::>, 10>::from(Rc::new(vec![] as Vec))), false); assert_eq!(is_inline(&OurBytes::>, 10>::from(Rc::new(vec![4u8] as Vec))), false); assert_eq!(is_inline(&OurBytes::>, 10>::from(Rc::new(vec![4u8, 6] as Vec))), false); assert_eq!(is_inline(&OurBytes::>, 10>::from(Rc::new(vec![4u8, 6, 1] as Vec))), false); assert_eq!(is_inline(&OurBytes::>, 10>::from(Rc::new(vec![4u8, 6, 1, 84] as Vec))), false); assert_eq!(is_inline(&OurBytes::>, 10>::from(Rc::new(vec![4u8, 6, 1, 84, 255] as Vec))), false); assert_eq!(is_inline(&OurBytes::>, 10>::from(Rc::new(vec![4u8, 6, 1, 84, 255, 12] as Vec))), false); assert_eq!(is_inline(&OurBytes::>, 10>::from(Rc::new(vec![4u8, 6, 1, 84, 255, 12, 23, 98, 169, 23] as Vec))), false); assert_eq!(is_inline(&OurBytes::>, 10>::from(Rc::new(vec![4u8, 6, 1, 84, 255, 12, 23, 98, 169, 23, 45] as Vec))), false); assert_eq!(is_inline(&OurBytes::>, 10>::from(Rc::new(vec![4u8, 6, 1, 84, 255, 12, 23, 98, 169, 23, 45, 65] as Vec))), false); assert_eq!(is_inline(&OurBytes::>, 10>::from(Rc::new(vec![4u8, 6, 1, 84, 255, 12, 23, 98, 169, 23, 45, 65, 56, 23, 76, 45, 98, 23, 56] as Vec))), false); assert_eq!(is_inline(&OurBytes::>, 4>::from(Arc::new(vec![] as Vec))), false); assert_eq!(is_inline(&OurBytes::>, 4>::from(Arc::new(vec![4u8] as Vec))), false); assert_eq!(is_inline(&OurBytes::>, 4>::from(Arc::new(vec![4u8, 6] as Vec))), false); assert_eq!(is_inline(&OurBytes::>, 4>::from(Arc::new(vec![4u8, 6, 1] as Vec))), false); assert_eq!(is_inline(&OurBytes::>, 4>::from(Arc::new(vec![4u8, 6, 1, 84] as Vec))), false); assert_eq!(is_inline(&OurBytes::>, 4>::from(Arc::new(vec![4u8, 6, 1, 84, 255] as Vec))), false); assert_eq!(is_inline(&OurBytes::>, 4>::from(Arc::new(vec![4u8, 6, 1, 84, 255, 12] as Vec))), false); assert_eq!(is_inline(&OurBytes::>, 4>::from(Arc::new(vec![4u8, 6, 1, 84, 255, 12, 23, 98, 169, 23] as Vec))), false); assert_eq!(is_inline(&OurBytes::>, 4>::from(Arc::new(vec![4u8, 6, 1, 84, 255, 12, 23, 98, 169, 23, 45] as Vec))), false); assert_eq!(is_inline(&OurBytes::>, 4>::from(Arc::new(vec![4u8, 6, 1, 84, 255, 12, 23, 98, 169, 23, 45, 65] as Vec))), false); assert_eq!(is_inline(&OurBytes::>, 4>::from(Arc::new(vec![4u8, 6, 1, 84, 255, 12, 23, 98, 169, 23, 45, 65, 56, 23, 76, 45, 98, 23, 56] as Vec))), false); } #[test] fn test_from_comrade() { assert_eq!(&*OurBytes::>, 10>::from(Rc::new(vec![] as Vec)) as &[u8], &[] as &[u8]); assert_eq!(&*OurBytes::>, 10>::from(Rc::new(vec![4u8] as Vec)) as &[u8], &[4u8] as &[u8]); assert_eq!(&*OurBytes::>, 10>::from(Rc::new(vec![4u8, 6] as Vec)) as &[u8], &[4u8, 6] as &[u8]); assert_eq!(&*OurBytes::>, 10>::from(Rc::new(vec![4u8, 6, 1] as Vec)) as &[u8], &[4u8, 6, 1] as &[u8]); assert_eq!(&*OurBytes::>, 10>::from(Rc::new(vec![4u8, 6, 1, 84] as Vec)) as &[u8], &[4u8, 6, 1, 84] as &[u8]); assert_eq!(&*OurBytes::>, 10>::from(Rc::new(vec![4u8, 6, 1, 84, 255] as Vec)) as &[u8], &[4u8, 6, 1, 84, 255] as &[u8]); assert_eq!(&*OurBytes::>, 10>::from(Rc::new(vec![4u8, 6, 1, 84, 255, 12] as Vec)) as &[u8], &[4u8, 6, 1, 84, 255, 12] as &[u8]); assert_eq!(&*OurBytes::>, 10>::from(Rc::new(vec![4u8, 6, 1, 84, 255, 12, 23, 98, 169, 23] as Vec)) as &[u8], &[4u8, 6, 1, 84, 255, 12, 23, 98, 169, 23] as &[u8]); assert_eq!(&*OurBytes::>, 10>::from(Rc::new(vec![4u8, 6, 1, 84, 255, 12, 23, 98, 169, 23, 45] as Vec)) as &[u8], &[4u8, 6, 1, 84, 255, 12, 23, 98, 169, 23, 45] as &[u8]); assert_eq!(&*OurBytes::>, 10>::from(Rc::new(vec![4u8, 6, 1, 84, 255, 12, 23, 98, 169, 23, 45, 65] as Vec)) as &[u8], &[4u8, 6, 1, 84, 255, 12, 23, 98, 169, 23, 45, 65] as &[u8]); assert_eq!(&*OurBytes::>, 10>::from(Rc::new(vec![4u8, 6, 1, 84, 255, 12, 23, 98, 169, 23, 45, 65, 56, 23, 76, 45, 98, 23, 56] as Vec)) as &[u8], &[4u8, 6, 1, 84, 255, 12, 23, 98, 169, 23, 45, 65, 56, 23, 76, 45, 98, 23, 56] as &[u8]); assert_eq!(&*OurBytes::>, 4>::from(Arc::new(vec![] as Vec)) as &[u8], &[] as &[u8]); assert_eq!(&*OurBytes::>, 4>::from(Arc::new(vec![4u8] as Vec)) as &[u8], &[4u8] as &[u8]); assert_eq!(&*OurBytes::>, 4>::from(Arc::new(vec![4u8, 6] as Vec)) as &[u8], &[4u8, 6] as &[u8]); assert_eq!(&*OurBytes::>, 4>::from(Arc::new(vec![4u8, 6, 1] as Vec)) as &[u8], &[4u8, 6, 1] as &[u8]); assert_eq!(&*OurBytes::>, 4>::from(Arc::new(vec![4u8, 6, 1, 84] as Vec)) as &[u8], &[4u8, 6, 1, 84] as &[u8]); assert_eq!(&*OurBytes::>, 4>::from(Arc::new(vec![4u8, 6, 1, 84, 255] as Vec)) as &[u8], &[4u8, 6, 1, 84, 255] as &[u8]); assert_eq!(&*OurBytes::>, 4>::from(Arc::new(vec![4u8, 6, 1, 84, 255, 12] as Vec)) as &[u8], &[4u8, 6, 1, 84, 255, 12] as &[u8]); assert_eq!(&*OurBytes::>, 4>::from(Arc::new(vec![4u8, 6, 1, 84, 255, 12, 23, 98, 169, 23] as Vec)) as &[u8], &[4u8, 6, 1, 84, 255, 12, 23, 98, 169, 23] as &[u8]); assert_eq!(&*OurBytes::>, 4>::from(Arc::new(vec![4u8, 6, 1, 84, 255, 12, 23, 98, 169, 23, 45] as Vec)) as &[u8], &[4u8, 6, 1, 84, 255, 12, 23, 98, 169, 23, 45] as &[u8]); assert_eq!(&*OurBytes::>, 4>::from(Arc::new(vec![4u8, 6, 1, 84, 255, 12, 23, 98, 169, 23, 45, 65] as Vec)) as &[u8], &[4u8, 6, 1, 84, 255, 12, 23, 98, 169, 23, 45, 65] as &[u8]); assert_eq!(&*OurBytes::>, 4>::from(Arc::new(vec![4u8, 6, 1, 84, 255, 12, 23, 98, 169, 23, 45, 65, 56, 23, 76, 45, 98, 23, 56] as Vec)) as &[u8], &[4u8, 6, 1, 84, 255, 12, 23, 98, 169, 23, 45, 65, 56, 23, 76, 45, 98, 23, 56] as &[u8]); } #[cfg(not(miri))] proptest::proptest! { #[test] fn proptest_from_comrade(s: Vec) { assert_eq!(&*OurBytes::>, 10>::from(Rc::new(s.clone())) as &[u8], s.as_slice()); assert_eq!(&*OurBytes::>, 10>::from(Arc::new(s.clone())) as &[u8], s.as_slice()); assert_eq!(&*OurBytes::, 10>::from(Rc::from(s.as_slice())) as &[u8], s.as_slice()); assert_eq!(&*OurBytes::, 10>::from(Arc::from(s.as_slice())) as &[u8], s.as_slice()); } } #[test] fn test_debug() { assert_eq!(format!("{:?}", OurBytes::, 4>::from(&[1u8, 2, 7] as &[u8])), format!("{:?}", &[1u8, 2, 7])); assert_eq!(format!("{:?}", OurBytes::>, 4>::from(&[1u8, 2, 3, 4] as &[u8])), format!("{:?}", &[1u8, 2, 3, 4])); assert_eq!(format!("{:?}", OurBytes::>, 4>::from(&[1u8, 2, 3, 4, 9, 1, 3, 255] as &[u8])), format!("{:?}", &[1u8, 2, 3, 4, 9, 1, 3, 255])); } #[cfg(not(miri))] proptest::proptest! { #[test] fn proptest_debug(s: Vec) { assert_eq!(format!("{:?}", OurBytes::, 4>::from(Rc::from(s.as_slice()))), format!("{s:?}")); assert_eq!(format!("{:?}", OurBytes::, 4>::from(Arc::from(s.as_slice()))), format!("{s:?}")); } } #[test] fn test_comparison() { let a = [6u8, 2, 3, 9, 3].as_slice(); let a1 = OurBytes::>, 10>::from(a); let a2 = OurBytes::>, 3>::from(a); let a3 = Vec::from(a); let b = [7u8, 2, 7, 5].as_slice(); let b1 = OurBytes::, 7>::from(b); let b2 = OurBytes::, 2>::from(b); let b3 = Vec::from(b); assert_eq!(a1, a ); assert_eq!(a1, a1); assert_eq!(a1, a2); assert_eq!(a1, a3); assert_eq!(a2, a ); assert_eq!(a2, a1); assert_eq!(a2, a2); assert_eq!(a2, a3); assert_eq!(a, a1); assert_eq!(a, a2); assert_ne!(b1, a ); assert_ne!(b1, a1); assert_ne!(b1, a2); assert_ne!(b1, a3); assert_ne!(b2, a ); assert_ne!(b2, a1); assert_ne!(b2, a2); assert_ne!(b2, a3); assert_ne!(b, a1); assert_ne!(b, a2); assert_ne!(a1, b ); assert_ne!(a1, b1); assert_ne!(a1, b2); assert_ne!(a1, b3); assert_ne!(a2, b ); assert_ne!(a2, b1); assert_ne!(a2, b2); assert_ne!(a2, b3); assert_ne!(a, b1); assert_ne!(a, b2); assert_eq!(b1, b ); assert_eq!(b1, b1); assert_eq!(b1, b2); assert_eq!(b1, b3); assert_eq!(b2, b ); assert_eq!(b2, b1); assert_eq!(b2, b2); assert_eq!(b2, b3); assert_eq!(b, b1); assert_eq!(b, b2); assert_eq!(a1 <= a , true); assert_eq!(a1 <= a1, true); assert_eq!(a1 <= a2, true); assert_eq!(a1 <= a3, true); assert_eq!(a2 <= a , true); assert_eq!(a2 <= a1, true); assert_eq!(a2 <= a2, true); assert_eq!(a2 <= a3, true); assert_eq!(a <= a1, true); assert_eq!(a <= a2, true); assert_eq!(a1 >= a , true); assert_eq!(a1 >= a1, true); assert_eq!(a1 >= a2, true); assert_eq!(a1 >= a3, true); assert_eq!(a2 >= a , true); assert_eq!(a2 >= a1, true); assert_eq!(a2 >= a2, true); assert_eq!(a2 >= a3, true); assert_eq!(a >= a1, true); assert_eq!(a >= a2, true); assert_eq!(a1 < a , false); assert_eq!(a1 < a1, false); assert_eq!(a1 < a2, false); assert_eq!(a1 < a3, false); assert_eq!(a2 < a , false); assert_eq!(a2 < a1, false); assert_eq!(a2 < a2, false); assert_eq!(a2 < a3, false); assert_eq!(a < a1, false); assert_eq!(a < a2, false); assert_eq!(a1 > a , false); assert_eq!(a1 > a1, false); assert_eq!(a1 > a2, false); assert_eq!(a1 > a3, false); assert_eq!(a2 > a , false); assert_eq!(a2 > a1, false); assert_eq!(a2 > a2, false); assert_eq!(a2 > a3, false); assert_eq!(a > a1, false); assert_eq!(a > a2, false); assert_eq!(b1 <= a , false); assert_eq!(b1 <= a1, false); assert_eq!(b1 <= a2, false); assert_eq!(b1 <= a3, false); assert_eq!(b2 <= a , false); assert_eq!(b2 <= a1, false); assert_eq!(b2 <= a2, false); assert_eq!(b2 <= a3, false); assert_eq!(b <= a1, false); assert_eq!(b <= a2, false); assert_eq!(b1 >= a , true ); assert_eq!(b1 >= a1, true ); assert_eq!(b1 >= a2, true ); assert_eq!(b1 >= a3, true ); assert_eq!(b2 >= a , true ); assert_eq!(b2 >= a1, true ); assert_eq!(b2 >= a2, true ); assert_eq!(b2 >= a3, true ); assert_eq!(b >= a1, true ); assert_eq!(b >= a2, true ); assert_eq!(b1 < a , false); assert_eq!(b1 < a1, false); assert_eq!(b1 < a2, false); assert_eq!(b1 < a3, false); assert_eq!(b2 < a , false); assert_eq!(b2 < a1, false); assert_eq!(b2 < a2, false); assert_eq!(b2 < a3, false); assert_eq!(b < a1, false); assert_eq!(b < a2, false); assert_eq!(b1 > a , true ); assert_eq!(b1 > a1, true ); assert_eq!(b1 > a2, true ); assert_eq!(b1 > a3, true ); assert_eq!(b2 > a , true ); assert_eq!(b2 > a1, true ); assert_eq!(b2 > a2, true ); assert_eq!(b2 > a3, true ); assert_eq!(b > a1, true ); assert_eq!(b > a2, true ); } #[cfg(not(miri))] proptest::proptest! { #[test] fn proptest_comparison(a: Vec, b: Vec) { fn partial_cmp(a: &A, b: &B) -> Option where A: PartialOrd { a.partial_cmp(b) } fn cmp(a: &A, b: &A) -> core::cmp::Ordering where A: Ord { a.cmp(b) } assert_eq!(partial_cmp(&a.as_slice(), &OurBytes::, 4>::from(b.as_slice())), partial_cmp(&a, &b)); assert_eq!(partial_cmp(&OurBytes::, 4>::from(a.as_slice()), &b), partial_cmp(&a, &b)); assert_eq!(partial_cmp(&OurBytes::, 4>::from(a.as_slice()), &OurBytes::, 4>::from(b.as_slice())), partial_cmp(&a, &b)); assert_eq!(partial_cmp(&OurBytes::, 4>::from(a.as_slice()), &OurBytes::, 8>::from(b.as_slice())), partial_cmp(&a, &b)); assert_eq!(partial_cmp(&OurBytes::, 8>::from(a.as_slice()), &OurBytes::, 4>::from(b.as_slice())), partial_cmp(&a, &b)); assert_eq!(cmp(&OurBytes::, 4>::from(a.as_slice()), &OurBytes::, 4>::from(b.as_slice())), cmp(&a, &b)); } } #[test] fn test_index() { let a = OurBytes::>, 8>::from([5u8, 3, 7, 12, 174, 255, 34].as_slice()); assert_eq!(a[..], a.as_slice()[..]); assert_eq!(a[3..], a.as_slice()[3..]); assert_eq!(a[..7], a.as_slice()[..7]); assert_eq!(a[3..7], a.as_slice()[3..7]); assert_eq!(a[5], a.as_slice()[5]); assert_eq!(a[3], a.as_slice()[3]); assert_eq!(a[0], a.as_slice()[0]); } #[test] fn test_convert() { let a = OurBytes::, 8>::from([5u8, 1, 6, 3, 6].as_slice()); assert_eq!(is_inline(&a), true); let b: OurBytes, 5> = a.convert(); assert_eq!(is_inline(&b), true); let c: OurBytes, 10> = b.convert(); assert_eq!(is_inline(&c), true); let d: OurBytes, 4> = c.convert(); assert_eq!(is_inline(&d), false); let e: OurBytes, 10> = d.clone().convert(); assert_eq!(is_inline(&e), false); assert_eq!(d.as_slice().as_ptr(), e.as_slice().as_ptr()); }