From af87a3594a9f852de0eb7fec7a2f2e7c5fdb4fe8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20RENAULT?= Date: Mon, 9 Jul 2018 14:50:54 +0200 Subject: [PATCH] Add a basic test to `Option::replace` --- src/libcore/tests/lib.rs | 1 + src/libcore/tests/option.rs | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/libcore/tests/lib.rs b/src/libcore/tests/lib.rs index 9d4a5213992..ca7db6e4639 100644 --- a/src/libcore/tests/lib.rs +++ b/src/libcore/tests/lib.rs @@ -44,6 +44,7 @@ #![feature(reverse_bits)] #![feature(iterator_find_map)] #![feature(slice_internals)] +#![feature(option_replace)] extern crate core; extern crate test; diff --git a/src/libcore/tests/option.rs b/src/libcore/tests/option.rs index 22109e28edd..bc3e61a4f54 100644 --- a/src/libcore/tests/option.rs +++ b/src/libcore/tests/option.rs @@ -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); +}