Add tests for Option::copied()

This commit is contained in:
Konrad Borowski 2018-12-05 14:52:23 +01:00
parent ab2cd6070e
commit fcc46040a9
2 changed files with 22 additions and 0 deletions

View File

@ -10,6 +10,7 @@
#![feature(box_syntax)] #![feature(box_syntax)]
#![feature(cell_update)] #![feature(cell_update)]
#![feature(copied)]
#![feature(core_private_bignum)] #![feature(core_private_bignum)]
#![feature(core_private_diy_float)] #![feature(core_private_diy_float)]
#![feature(dec2flt)] #![feature(dec2flt)]

View File

@ -248,6 +248,27 @@ fn test_collect() {
assert!(v == None); assert!(v == None);
} }
#[test]
fn test_copied() {
let val = 1;
let val_ref = &val;
let opt_none: Option<&'static u32> = None;
let opt_ref = Some(&val);
let opt_ref_ref = Some(&val_ref);
// None works
assert_eq!(opt_none.clone(), None);
assert_eq!(opt_none.copied(), None);
// Immutable ref works
assert_eq!(opt_ref.clone(), Some(&val));
assert_eq!(opt_ref.copied(), Some(1));
// Double Immutable ref works
assert_eq!(opt_ref_ref.clone(), Some(&val_ref));
assert_eq!(opt_ref_ref.clone().copied(), Some(&val));
assert_eq!(opt_ref_ref.copied().copied(), Some(1));
}
#[test] #[test]
fn test_cloned() { fn test_cloned() {