use len_constraints::{ slice::{ Fixed, Ranged, Relative }, type_math::{ Sub, _4, _8 } }; use std::convert::TryFrom; macro_rules! s { ($len:expr) => ([7; $len].as_ref()); } #[test] fn test_fixed() { Fixed::::try_from(s!(4)).unwrap(); Fixed::::try_from(s!(8)).unwrap(); } #[test] fn test_fixed_err() { Fixed::::try_from(s!(3)).unwrap_err(); Fixed::::try_from(s!(5)).unwrap_err(); Fixed::::try_from(s!(7)).unwrap_err(); Fixed::::try_from(s!(9)).unwrap_err(); } #[test] fn test_ranged() { Ranged::::try_from(s!(4)).unwrap(); Ranged::::try_from(s!(7)).unwrap(); } #[test] fn test_ranged_err() { Ranged::::try_from(s!(3)).unwrap_err(); Ranged::::try_from(s!(8)).unwrap_err(); } #[test] fn test_relative() { Relative::::from(s!(4)).slice(8).unwrap(); Relative::::from(s!(9)).slice(17).unwrap(); } #[test] fn test_relative_err() { Relative::::from(s!(0)).slice(3).unwrap_err(); Relative::::from(s!(3)).slice(8).unwrap_err(); Relative::::from(s!(9)).slice(16).unwrap_err(); }