Skip to content

Commit fcc4604

Browse files
committedDec 5, 2018
Add tests for Option::copied()
1 parent ab2cd60 commit fcc4604

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed
 

‎src/libcore/tests/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#![feature(box_syntax)]
1212
#![feature(cell_update)]
13+
#![feature(copied)]
1314
#![feature(core_private_bignum)]
1415
#![feature(core_private_diy_float)]
1516
#![feature(dec2flt)]

‎src/libcore/tests/option.rs

+21
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,27 @@ fn test_collect() {
248248
assert!(v == None);
249249
}
250250

251+
#[test]
252+
fn test_copied() {
253+
let val = 1;
254+
let val_ref = &val;
255+
let opt_none: Option<&'static u32> = None;
256+
let opt_ref = Some(&val);
257+
let opt_ref_ref = Some(&val_ref);
258+
259+
// None works
260+
assert_eq!(opt_none.clone(), None);
261+
assert_eq!(opt_none.copied(), None);
262+
263+
// Immutable ref works
264+
assert_eq!(opt_ref.clone(), Some(&val));
265+
assert_eq!(opt_ref.copied(), Some(1));
266+
267+
// Double Immutable ref works
268+
assert_eq!(opt_ref_ref.clone(), Some(&val_ref));
269+
assert_eq!(opt_ref_ref.clone().copied(), Some(&val));
270+
assert_eq!(opt_ref_ref.copied().copied(), Some(1));
271+
}
251272

252273
#[test]
253274
fn test_cloned() {

0 commit comments

Comments
 (0)
Please sign in to comment.