use std::thread; use cowstr::*; #[test] fn smoke() { let cow = CowStr::from("foo"); let thread = thread::spawn(move || { assert_eq!(cow, "foo"); }); thread.join().expect("success"); } #[test] fn mutate_return() { let mut cow = CowStr::from("foo"); let thread = thread::spawn(move || { assert_eq!(cow, "foo"); cow.as_mut_str().make_ascii_uppercase(); cow }); assert_eq!(thread.join().expect("success"), "FOO"); } #[test] fn mutate_clone_return() { let cow = CowStr::from("foo"); let mut cow_clone = cow.clone(); let thread = thread::spawn(move || { cow_clone.as_mut_str().make_ascii_uppercase(); cow_clone }); assert_eq!(thread.join().expect("success"), "FOO"); assert_eq!(cow, "foo"); } #[test] #[should_panic] #[allow(clippy::should_panic_without_expect)] fn double_guard_in_thread() { let cowstr = CowStr::with_capacity(100); let _guard = cowstr.guard().unwrap(); let thread = thread::spawn(move || { let _guard = cowstr.guard().unwrap(); }); assert!(thread.join().is_ok()); }