From 42271a537a7a833c7ed448297b48be3bbc98de8c Mon Sep 17 00:00:00 2001 From: Alexis Bourget Date: Sat, 3 Oct 2020 19:03:38 +0200 Subject: [PATCH] Move vec swap test --- library/alloc/tests/vec.rs | 14 +++++++++++++- src/test/ui/swap-2.rs | 14 -------------- 2 files changed, 13 insertions(+), 15 deletions(-) delete mode 100644 src/test/ui/swap-2.rs diff --git a/library/alloc/tests/vec.rs b/library/alloc/tests/vec.rs index ae7518bcad0..47ebe56f9fd 100644 --- a/library/alloc/tests/vec.rs +++ b/library/alloc/tests/vec.rs @@ -3,7 +3,7 @@ use std::collections::TryReserveError::*; use std::fmt::Debug; use std::iter::InPlaceIterable; -use std::mem::size_of; +use std::mem::{size_of, swap}; use std::ops::Bound::*; use std::panic::{catch_unwind, AssertUnwindSafe}; use std::rc::Rc; @@ -1942,3 +1942,15 @@ fn test_vec_macro_repeat() { let n = 3; assert_eq!(vec![el; n], vec![Box::new(1), Box::new(1), Box::new(1)]); } + +#[test] +fn test_vec_swap() { + let mut a: Vec = vec![0, 1, 2, 3, 4, 5, 6]; + a.swap(2, 4); + assert_eq!(a[2], 4); + assert_eq!(a[4], 2); + let mut n = 42; + swap(&mut n, &mut a[0]); + assert_eq!(a[0], 42); + assert_eq!(n, 0); +} diff --git a/src/test/ui/swap-2.rs b/src/test/ui/swap-2.rs deleted file mode 100644 index c8f298ec0e5..00000000000 --- a/src/test/ui/swap-2.rs +++ /dev/null @@ -1,14 +0,0 @@ -// run-pass - -use std::mem::swap; - -pub fn main() { - let mut a: Vec = vec![0, 1, 2, 3, 4, 5, 6]; - a.swap(2, 4); - assert_eq!(a[2], 4); - assert_eq!(a[4], 2); - let mut n = 42; - swap(&mut n, &mut a[0]); - assert_eq!(a[0], 42); - assert_eq!(n, 0); -}