use core::sync::atomic::AtomicU8;
use core::sync::atomic::Ordering;
use enclose::enc;
#[test]
fn clone_count_operations() {
static CHECK_COUNT_OPERATIONS: AtomicU8 = AtomicU8::new(0);
struct CleverType;
impl Clone for CleverType {
#[inline]
fn clone(&self) -> Self {
let _del = CHECK_COUNT_OPERATIONS.fetch_add(1, Ordering::SeqCst);
CleverType
}
}
let data = CleverType;
assert_eq!(CHECK_COUNT_OPERATIONS.load(Ordering::SeqCst), 0); enc!((data => d) || {
assert_eq!(CHECK_COUNT_OPERATIONS.load(Ordering::SeqCst), 1);
std::thread::spawn(enc!((d,) move || {
assert_eq!(CHECK_COUNT_OPERATIONS.load(Ordering::SeqCst), 2);
enc!((d) || {
enc!((d => _d, d => _d2) move || {
})();
})();
assert_eq!(CHECK_COUNT_OPERATIONS.load(Ordering::SeqCst), 5);
})).join().unwrap();
})();
let _manclone = data.clone();
assert_eq!(CHECK_COUNT_OPERATIONS.load(Ordering::SeqCst), 6);
}