Add a basic test to Option::replace

This commit is contained in:
Clément RENAULT 2018-07-09 14:50:54 +02:00
parent 6035534586
commit af87a3594a
No known key found for this signature in database
GPG key ID: 9F36890FFB823F85
2 changed files with 16 additions and 0 deletions

View file

@ -44,6 +44,7 @@
#![feature(reverse_bits)]
#![feature(iterator_find_map)]
#![feature(slice_internals)]
#![feature(option_replace)]
extern crate core;
extern crate test;

View file

@ -297,3 +297,18 @@ fn test_try() {
}
assert_eq!(try_option_err(), Err(NoneError));
}
#[test]
fn test_replace() {
let mut x = Some(2);
let old = x.replace(5);
assert_eq!(x, Some(5));
assert_eq!(old, Some(2));
let mut x = None;
let old = x.replace(3);
assert_eq!(x, Some(3));
assert_eq!(old, None);
}