use layout::{Compact, CompactBool, CompactVec, SoAIndex, SoAIndexMut, SOA};
#[derive(Clone, SOA)]
struct Row {
id: u32,
flag: CompactBool,
}
fn one() -> RowVec {
let mut v = RowVec::new();
v.push(Row {
id: 1,
flag: Compact(true),
});
v
}
#[test]
#[should_panic]
fn set_oob_panics() {
let mut v = one();
v.flag.set(3, Compact(false));
}
#[test]
#[should_panic]
fn slice_index_oob_panics() {
let v = one();
let _ = v.flag.as_slice().index(3);
}
#[test]
#[should_panic]
fn slice_index_mut_oob_panics() {
let mut v = one();
v.flag.as_mut_slice().index_mut(3).set(false);
}
#[test]
#[should_panic]
fn vec_index_mut_oob_panics() {
let mut v = one();
v.index_mut(50).flag.set(false);
}
#[test]
#[should_panic]
fn slice_mut_index_mut_oob_panics() {
let mut v = one();
v.as_mut_slice().index_mut(50).flag.set(false);
}
#[test]
#[should_panic]
fn slice_oob_range_panics() {
let v = one();
let _ = v.flag.slice(0..5);
}
#[test]
#[should_panic]
fn slice_mut_oob_range_panics() {
let mut v = one();
let _ = v.flag.slice_mut(0..5);
}
#[test]
#[should_panic]
fn drain_oob_range_panics() {
let mut v = one();
let _ = v.flag.drain(0..5);
}
#[test]
#[should_panic(expected = "splice range out of bounds")]
fn compactvec_splice_oob_range_is_rejected() {
let mut v = CompactVec::<bool>::new();
v.push(Compact(true)); let _: CompactVec<bool> =
v.splice(0..5, core::iter::empty::<Compact<bool>>());
}
#[test]
#[should_panic]
fn slice_index_range_to_inclusive_max_panics() {
let v = one();
let _ = SoAIndex::index(..=usize::MAX, v.flag.as_slice());
}
#[test]
#[should_panic]
fn slice_index_mut_range_to_inclusive_max_panics() {
let mut v = one();
let _ = SoAIndexMut::index_mut(..=usize::MAX, v.flag.as_mut_slice());
}
#[test]
fn slice_index_inclusive_in_bounds() {
let v = one();
let s = SoAIndex::index(0..=0, v.flag.as_slice());
assert_eq!(s.len(), 1);
}