#[path = "../src/test_utils.rs"]
mod utils;
use std::any::Any;
use trait_obj_list::DynList;
utils::for_each_list_type! {
#[test]
fn send<T>() {
let mut l = DynList::<dyn Any + Send, T>::new();
l.push(123i32);
l.push(456u64);
let th = std::thread::spawn(move || {
let mut it = l.iter();
let i1 = it.next().unwrap();
let i2 = it.next().unwrap();
assert!(it.next().is_none());
assert_eq!(i1.downcast_ref::<i32>().copied(), Some(123));
assert_eq!(i1.downcast_ref::<u64>().copied(), None);
assert_eq!(i2.downcast_ref::<u64>().copied(), Some(456));
assert_eq!(i2.downcast_ref::<i32>().copied(), None);
core::mem::drop(l);
});
th.join().unwrap();
}
#[test]
fn sync<T>() {
let mut l = DynList::<dyn Any + Send + Sync, T>::new();
l.push(123i32);
l.push(456u64);
let l = std::sync::Arc::new(l);
let l2 = l.clone();
let th = std::thread::spawn(move || {
let mut it = l.iter();
let i1 = it.next().unwrap();
let i2 = it.next().unwrap();
assert!(it.next().is_none());
assert_eq!(i1.downcast_ref::<i32>().copied(), Some(123));
assert_eq!(i1.downcast_ref::<u64>().copied(), None);
assert_eq!(i2.downcast_ref::<u64>().copied(), Some(456));
assert_eq!(i2.downcast_ref::<i32>().copied(), None);
core::mem::drop(l);
});
let mut it = l2.iter();
let i1 = it.next().unwrap();
let i2 = it.next().unwrap();
assert!(it.next().is_none());
assert_eq!(i1.downcast_ref::<i32>().copied(), Some(123));
assert_eq!(i1.downcast_ref::<u64>().copied(), None);
assert_eq!(i2.downcast_ref::<u64>().copied(), Some(456));
assert_eq!(i2.downcast_ref::<i32>().copied(), None);
core::mem::drop(l2);
th.join().unwrap();
}
}