1
Fork 0

Auto merge of #33795 - srinivasreddy:lib_coll_test, r=nrc

run rustfmt on libcollections test module
This commit is contained in:
bors 2016-05-27 11:51:53 -07:00
commit 17b6261cc4
7 changed files with 435 additions and 398 deletions

View file

@ -9,7 +9,7 @@
// except according to those terms.
use std::collections::BTreeMap;
use std::collections::Bound::{Excluded, Included, Unbounded, self};
use std::collections::Bound::{self, Excluded, Included, Unbounded};
use std::collections::btree_map::Entry::{Occupied, Vacant};
use std::rc::Rc;
@ -81,7 +81,9 @@ fn test_iter() {
// Forwards
let mut map: BTreeMap<_, _> = (0..size).map(|i| (i, i)).collect();
fn test<T>(size: usize, mut iter: T) where T: Iterator<Item=(usize, usize)> {
fn test<T>(size: usize, mut iter: T)
where T: Iterator<Item = (usize, usize)>
{
for i in 0..size {
assert_eq!(iter.size_hint(), (size - i, Some(size - i)));
assert_eq!(iter.next().unwrap(), (i, i));
@ -101,7 +103,9 @@ fn test_iter_rev() {
// Forwards
let mut map: BTreeMap<_, _> = (0..size).map(|i| (i, i)).collect();
fn test<T>(size: usize, mut iter: T) where T: Iterator<Item=(usize, usize)> {
fn test<T>(size: usize, mut iter: T)
where T: Iterator<Item = (usize, usize)>
{
for i in 0..size {
assert_eq!(iter.size_hint(), (size - i, Some(size - i)));
assert_eq!(iter.next().unwrap(), (size - i - 1, size - i - 1));
@ -125,8 +129,7 @@ fn test_values_mut() {
}
let values: Vec<String> = a.values().cloned().collect();
assert_eq!(values, [String::from("hello!"),
String::from("goodbye!")]);
assert_eq!(values, [String::from("hello!"), String::from("goodbye!")]);
}
#[test]
@ -137,7 +140,8 @@ fn test_iter_mixed() {
let mut map: BTreeMap<_, _> = (0..size).map(|i| (i, i)).collect();
fn test<T>(size: usize, mut iter: T)
where T: Iterator<Item=(usize, usize)> + DoubleEndedIterator {
where T: Iterator<Item = (usize, usize)> + DoubleEndedIterator
{
for i in 0..size / 4 {
assert_eq!(iter.size_hint(), (size - i * 2, Some(size - i * 2)));
assert_eq!(iter.next().unwrap(), (i, i));
@ -341,17 +345,23 @@ fn test_bad_zst() {
struct Bad;
impl PartialEq for Bad {
fn eq(&self, _: &Self) -> bool { false }
fn eq(&self, _: &Self) -> bool {
false
}
}
impl Eq for Bad {}
impl PartialOrd for Bad {
fn partial_cmp(&self, _: &Self) -> Option<Ordering> { Some(Ordering::Less) }
fn partial_cmp(&self, _: &Self) -> Option<Ordering> {
Some(Ordering::Less)
}
}
impl Ord for Bad {
fn cmp(&self, _: &Self) -> Ordering { Ordering::Less }
fn cmp(&self, _: &Self) -> Ordering {
Ordering::Less
}
}
let mut m = BTreeMap::new();
@ -398,16 +408,36 @@ fn test_clone() {
fn test_variance() {
use std::collections::btree_map::{Iter, IntoIter, Range, Keys, Values};
fn map_key<'new>(v: BTreeMap<&'static str, ()>) -> BTreeMap<&'new str, ()> { v }
fn map_val<'new>(v: BTreeMap<(), &'static str>) -> BTreeMap<(), &'new str> { v }
fn iter_key<'a, 'new>(v: Iter<'a, &'static str, ()>) -> Iter<'a, &'new str, ()> { v }
fn iter_val<'a, 'new>(v: Iter<'a, (), &'static str>) -> Iter<'a, (), &'new str> { v }
fn into_iter_key<'new>(v: IntoIter<&'static str, ()>) -> IntoIter<&'new str, ()> { v }
fn into_iter_val<'new>(v: IntoIter<(), &'static str>) -> IntoIter<(), &'new str> { v }
fn range_key<'a, 'new>(v: Range<'a, &'static str, ()>) -> Range<'a, &'new str, ()> { v }
fn range_val<'a, 'new>(v: Range<'a, (), &'static str>) -> Range<'a, (), &'new str> { v }
fn keys<'a, 'new>(v: Keys<'a, &'static str, ()>) -> Keys<'a, &'new str, ()> { v }
fn vals<'a, 'new>(v: Values<'a, (), &'static str>) -> Values<'a, (), &'new str> { v }
fn map_key<'new>(v: BTreeMap<&'static str, ()>) -> BTreeMap<&'new str, ()> {
v
}
fn map_val<'new>(v: BTreeMap<(), &'static str>) -> BTreeMap<(), &'new str> {
v
}
fn iter_key<'a, 'new>(v: Iter<'a, &'static str, ()>) -> Iter<'a, &'new str, ()> {
v
}
fn iter_val<'a, 'new>(v: Iter<'a, (), &'static str>) -> Iter<'a, (), &'new str> {
v
}
fn into_iter_key<'new>(v: IntoIter<&'static str, ()>) -> IntoIter<&'new str, ()> {
v
}
fn into_iter_val<'new>(v: IntoIter<(), &'static str>) -> IntoIter<(), &'new str> {
v
}
fn range_key<'a, 'new>(v: Range<'a, &'static str, ()>) -> Range<'a, &'new str, ()> {
v
}
fn range_val<'a, 'new>(v: Range<'a, (), &'static str>) -> Range<'a, (), &'new str> {
v
}
fn keys<'a, 'new>(v: Keys<'a, &'static str, ()>) -> Keys<'a, &'new str, ()> {
v
}
fn vals<'a, 'new>(v: Values<'a, (), &'static str>) -> Values<'a, (), &'new str> {
v
}
}
#[test]
@ -440,7 +470,7 @@ fn test_vacant_entry_key() {
Vacant(e) => {
assert_eq!(key, *e.key());
e.insert(value.clone());
},
}
}
assert_eq!(a.len(), 1);
assert_eq!(a[key], value);

View file

@ -17,7 +17,9 @@ use self::Foo::*;
#[derive(Copy, Clone, PartialEq, Debug)]
#[repr(usize)]
enum Foo {
A, B, C
A,
B,
C,
}
impl CLike for Foo {

View file

@ -317,7 +317,8 @@ fn test_show() {
assert_eq!(format!("{:?}", list), "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]");
let list: LinkedList<_> = vec!["just", "one", "test", "more"].iter().cloned().collect();
assert_eq!(format!("{:?}", list), "[\"just\", \"one\", \"test\", \"more\"]");
assert_eq!(format!("{:?}", list),
"[\"just\", \"one\", \"test\", \"more\"]");
}
#[test]

View file

@ -13,9 +13,13 @@ use std::mem;
use std::__rand::{Rng, thread_rng};
use std::rc::Rc;
fn square(n: usize) -> usize { n * n }
fn square(n: usize) -> usize {
n * n
}
fn is_odd(n: &usize) -> bool { *n % 2 == 1 }
fn is_odd(n: &usize) -> bool {
*n % 2 == 1
}
#[test]
fn test_from_fn() {
@ -336,10 +340,8 @@ fn test_dedup_unique() {
v1.dedup();
let mut v2: Vec<Box<_>> = vec![box 1, box 2, box 3, box 3];
v2.dedup();
/*
* If the boxed pointers were leaked or otherwise misused, valgrind
* and/or rt should raise errors.
*/
// If the boxed pointers were leaked or otherwise misused, valgrind
// and/or rt should raise errors.
}
#[test]
@ -350,10 +352,8 @@ fn test_dedup_shared() {
v1.dedup();
let mut v2: Vec<Box<_>> = vec![box 1, box 2, box 3, box 3];
v2.dedup();
/*
* If the pointers were leaked or otherwise misused, valgrind and/or
* rt should raise errors.
*/
// If the pointers were leaked or otherwise misused, valgrind and/or
// rt should raise errors.
}
#[test]
@ -460,11 +460,13 @@ fn test_sort_stability() {
// the second item represents which occurrence of that
// number this element is, i.e. the second elements
// will occur in sorted order.
let mut v: Vec<_> = (0..len).map(|_| {
let mut v: Vec<_> = (0..len)
.map(|_| {
let n = thread_rng().gen::<usize>() % 10;
counts[n] += 1;
(n, counts[n])
}).collect();
})
.collect();
// only sort on the first element, so an unstable sort
// may mix up the counts.
@ -688,13 +690,15 @@ fn test_mut_rev_iterator() {
#[test]
fn test_move_iterator() {
let xs = vec![1, 2, 3, 4, 5];
assert_eq!(xs.into_iter().fold(0, |a: usize, b: usize| 10*a + b), 12345);
assert_eq!(xs.into_iter().fold(0, |a: usize, b: usize| 10 * a + b),
12345);
}
#[test]
fn test_move_rev_iterator() {
let xs = vec![1, 2, 3, 4, 5];
assert_eq!(xs.into_iter().rev().fold(0, |a: usize, b: usize| 10*a + b), 54321);
assert_eq!(xs.into_iter().rev().fold(0, |a: usize, b: usize| 10 * a + b),
54321);
}
#[test]
@ -702,20 +706,15 @@ fn test_splitator() {
let xs = &[1, 2, 3, 4, 5];
let splits: &[&[_]] = &[&[1], &[3], &[5]];
assert_eq!(xs.split(|x| *x % 2 == 0).collect::<Vec<_>>(),
splits);
assert_eq!(xs.split(|x| *x % 2 == 0).collect::<Vec<_>>(), splits);
let splits: &[&[_]] = &[&[], &[2, 3, 4, 5]];
assert_eq!(xs.split(|x| *x == 1).collect::<Vec<_>>(),
splits);
assert_eq!(xs.split(|x| *x == 1).collect::<Vec<_>>(), splits);
let splits: &[&[_]] = &[&[1, 2, 3, 4], &[]];
assert_eq!(xs.split(|x| *x == 5).collect::<Vec<_>>(),
splits);
assert_eq!(xs.split(|x| *x == 5).collect::<Vec<_>>(), splits);
let splits: &[&[_]] = &[&[1, 2, 3, 4, 5]];
assert_eq!(xs.split(|x| *x == 10).collect::<Vec<_>>(),
splits);
assert_eq!(xs.split(|x| *x == 10).collect::<Vec<_>>(), splits);
let splits: &[&[_]] = &[&[], &[], &[], &[], &[], &[]];
assert_eq!(xs.split(|_| true).collect::<Vec<&[i32]>>(),
splits);
assert_eq!(xs.split(|_| true).collect::<Vec<&[i32]>>(), splits);
let xs: &[i32] = &[];
let splits: &[&[i32]] = &[&[]];
@ -727,14 +726,11 @@ fn test_splitnator() {
let xs = &[1, 2, 3, 4, 5];
let splits: &[&[_]] = &[&[1, 2, 3, 4, 5]];
assert_eq!(xs.splitn(1, |x| *x % 2 == 0).collect::<Vec<_>>(),
splits);
assert_eq!(xs.splitn(1, |x| *x % 2 == 0).collect::<Vec<_>>(), splits);
let splits: &[&[_]] = &[&[1], &[3, 4, 5]];
assert_eq!(xs.splitn(2, |x| *x % 2 == 0).collect::<Vec<_>>(),
splits);
assert_eq!(xs.splitn(2, |x| *x % 2 == 0).collect::<Vec<_>>(), splits);
let splits: &[&[_]] = &[&[], &[], &[], &[4, 5]];
assert_eq!(xs.splitn(4, |_| true).collect::<Vec<_>>(),
splits);
assert_eq!(xs.splitn(4, |_| true).collect::<Vec<_>>(), splits);
let xs: &[i32] = &[];
let splits: &[&[i32]] = &[&[]];
@ -752,13 +748,11 @@ fn test_splitnator_mut() {
assert_eq!(xs.splitn_mut(2, |x| *x % 2 == 0).collect::<Vec<_>>(),
splits);
let splits: &[&mut [_]] = &[&mut [], &mut [], &mut [], &mut [4, 5]];
assert_eq!(xs.splitn_mut(4, |_| true).collect::<Vec<_>>(),
splits);
assert_eq!(xs.splitn_mut(4, |_| true).collect::<Vec<_>>(), splits);
let xs: &mut [i32] = &mut [];
let splits: &[&mut [i32]] = &[&mut []];
assert_eq!(xs.splitn_mut(2, |x| *x == 5).collect::<Vec<_>>(),
splits);
assert_eq!(xs.splitn_mut(2, |x| *x == 5).collect::<Vec<_>>(), splits);
}
#[test]
@ -766,17 +760,13 @@ fn test_rsplitator() {
let xs = &[1, 2, 3, 4, 5];
let splits: &[&[_]] = &[&[5], &[3], &[1]];
assert_eq!(xs.split(|x| *x % 2 == 0).rev().collect::<Vec<_>>(),
splits);
assert_eq!(xs.split(|x| *x % 2 == 0).rev().collect::<Vec<_>>(), splits);
let splits: &[&[_]] = &[&[2, 3, 4, 5], &[]];
assert_eq!(xs.split(|x| *x == 1).rev().collect::<Vec<_>>(),
splits);
assert_eq!(xs.split(|x| *x == 1).rev().collect::<Vec<_>>(), splits);
let splits: &[&[_]] = &[&[], &[1, 2, 3, 4]];
assert_eq!(xs.split(|x| *x == 5).rev().collect::<Vec<_>>(),
splits);
assert_eq!(xs.split(|x| *x == 5).rev().collect::<Vec<_>>(), splits);
let splits: &[&[_]] = &[&[1, 2, 3, 4, 5]];
assert_eq!(xs.split(|x| *x == 10).rev().collect::<Vec<_>>(),
splits);
assert_eq!(xs.split(|x| *x == 10).rev().collect::<Vec<_>>(), splits);
let xs: &[i32] = &[];
let splits: &[&[i32]] = &[&[]];
@ -788,14 +778,11 @@ fn test_rsplitnator() {
let xs = &[1, 2, 3, 4, 5];
let splits: &[&[_]] = &[&[1, 2, 3, 4, 5]];
assert_eq!(xs.rsplitn(1, |x| *x % 2 == 0).collect::<Vec<_>>(),
splits);
assert_eq!(xs.rsplitn(1, |x| *x % 2 == 0).collect::<Vec<_>>(), splits);
let splits: &[&[_]] = &[&[5], &[1, 2, 3]];
assert_eq!(xs.rsplitn(2, |x| *x % 2 == 0).collect::<Vec<_>>(),
splits);
assert_eq!(xs.rsplitn(2, |x| *x % 2 == 0).collect::<Vec<_>>(), splits);
let splits: &[&[_]] = &[&[], &[], &[], &[1, 2]];
assert_eq!(xs.rsplitn(4, |_| true).collect::<Vec<_>>(),
splits);
assert_eq!(xs.rsplitn(4, |_| true).collect::<Vec<_>>(), splits);
let xs: &[i32] = &[];
let splits: &[&[i32]] = &[&[]];
@ -869,8 +856,7 @@ fn test_show() {
test_show_vec!(empty, "[]");
test_show_vec!(vec![1], "[1]");
test_show_vec!(vec![1, 2, 3], "[1, 2, 3]");
test_show_vec!(vec![vec![], vec![1], vec![1, 1]],
"[[], [1], [1, 1]]");
test_show_vec!(vec![vec![], vec![1], vec![1, 1]], "[[], [1], [1, 1]]");
let empty_mut: &mut [i32] = &mut [];
test_show_vec!(empty_mut, "[]");
@ -1119,7 +1105,7 @@ fn test_box_slice_clone_panics() {
struct Canary {
count: Arc<AtomicUsize>,
panics: bool
panics: bool,
}
impl Drop for Canary {
@ -1130,27 +1116,37 @@ fn test_box_slice_clone_panics() {
impl Clone for Canary {
fn clone(&self) -> Self {
if self.panics { panic!() }
if self.panics {
panic!()
}
Canary {
count: self.count.clone(),
panics: self.panics
panics: self.panics,
}
}
}
let drop_count = Arc::new(AtomicUsize::new(0));
let canary = Canary { count: drop_count.clone(), panics: false };
let panic = Canary { count: drop_count.clone(), panics: true };
let canary = Canary {
count: drop_count.clone(),
panics: false,
};
let panic = Canary {
count: drop_count.clone(),
panics: true,
};
spawn(move || {
// When xs is dropped, +5.
let xs = vec![canary.clone(), canary.clone(), canary.clone(),
panic, canary].into_boxed_slice();
let xs = vec![canary.clone(), canary.clone(), canary.clone(), panic, canary]
.into_boxed_slice();
// When panic is cloned, +3.
xs.clone();
}).join().unwrap_err();
})
.join()
.unwrap_err();
// Total = 8
assert_eq!(drop_count.load(Ordering::SeqCst), 8);
@ -1198,7 +1194,9 @@ mod bench {
sum += *x;
}
// sum == 11806, to stop dead code elimination.
if sum == 0 {panic!()}
if sum == 0 {
panic!()
}
})
}
@ -1217,8 +1215,7 @@ mod bench {
#[bench]
fn concat(b: &mut Bencher) {
let xss: Vec<Vec<i32>> =
(0..100).map(|i| (0..i).collect()).collect();
let xss: Vec<Vec<i32>> = (0..100).map(|i| (0..i).collect()).collect();
b.iter(|| {
xss.concat();
});
@ -1226,11 +1223,8 @@ mod bench {
#[bench]
fn join(b: &mut Bencher) {
let xss: Vec<Vec<i32>> =
(0..100).map(|i| (0..i).collect()).collect();
b.iter(|| {
xss.join(&0)
});
let xss: Vec<Vec<i32>> = (0..100).map(|i| (0..i).collect()).collect();
b.iter(|| xss.join(&0));
}
#[bench]
@ -1245,17 +1239,13 @@ mod bench {
#[bench]
fn starts_with_same_vector(b: &mut Bencher) {
let vec: Vec<_> = (0..100).collect();
b.iter(|| {
vec.starts_with(&vec)
})
b.iter(|| vec.starts_with(&vec))
}
#[bench]
fn starts_with_single_element(b: &mut Bencher) {
let vec: Vec<_> = vec![0];
b.iter(|| {
vec.starts_with(&vec)
})
b.iter(|| vec.starts_with(&vec))
}
#[bench]
@ -1263,25 +1253,19 @@ mod bench {
let vec: Vec<_> = (0..100).collect();
let mut match_vec: Vec<_> = (0..99).collect();
match_vec.push(0);
b.iter(|| {
vec.starts_with(&match_vec)
})
b.iter(|| vec.starts_with(&match_vec))
}
#[bench]
fn ends_with_same_vector(b: &mut Bencher) {
let vec: Vec<_> = (0..100).collect();
b.iter(|| {
vec.ends_with(&vec)
})
b.iter(|| vec.ends_with(&vec))
}
#[bench]
fn ends_with_single_element(b: &mut Bencher) {
let vec: Vec<_> = vec![0];
b.iter(|| {
vec.ends_with(&vec)
})
b.iter(|| vec.ends_with(&vec))
}
#[bench]
@ -1289,24 +1273,18 @@ mod bench {
let vec: Vec<_> = (0..100).collect();
let mut match_vec: Vec<_> = (0..100).collect();
match_vec[0] = 200;
b.iter(|| {
vec.starts_with(&match_vec)
})
b.iter(|| vec.starts_with(&match_vec))
}
#[bench]
fn contains_last_element(b: &mut Bencher) {
let vec: Vec<_> = (0..100).collect();
b.iter(|| {
vec.contains(&99)
})
b.iter(|| vec.contains(&99))
}
#[bench]
fn zero_1kb_from_elem(b: &mut Bencher) {
b.iter(|| {
vec![0u8; 1024]
});
b.iter(|| vec![0u8; 1024]);
}
#[bench]
@ -1356,8 +1334,7 @@ mod bench {
let mut v = vec![(0, 0); 30];
for _ in 0..100 {
let l = v.len();
v.insert(rng.gen::<usize>() % (l + 1),
(1, 1));
v.insert(rng.gen::<usize>() % (l + 1), (1, 1));
}
})
}
@ -1418,7 +1395,8 @@ mod bench {
fn sort_big_random_small(b: &mut Bencher) {
let mut rng = thread_rng();
b.iter(|| {
let mut v = rng.gen_iter::<BigSortable>().take(5)
let mut v = rng.gen_iter::<BigSortable>()
.take(5)
.collect::<Vec<BigSortable>>();
v.sort();
});
@ -1429,7 +1407,8 @@ mod bench {
fn sort_big_random_medium(b: &mut Bencher) {
let mut rng = thread_rng();
b.iter(|| {
let mut v = rng.gen_iter::<BigSortable>().take(100)
let mut v = rng.gen_iter::<BigSortable>()
.take(100)
.collect::<Vec<BigSortable>>();
v.sort();
});
@ -1440,7 +1419,8 @@ mod bench {
fn sort_big_random_large(b: &mut Bencher) {
let mut rng = thread_rng();
b.iter(|| {
let mut v = rng.gen_iter::<BigSortable>().take(10000)
let mut v = rng.gen_iter::<BigSortable>()
.take(10000)
.collect::<Vec<BigSortable>>();
v.sort();
});

View file

@ -44,8 +44,7 @@ fn test_unsized_to_string() {
#[test]
fn test_from_utf8() {
let xs = b"hello".to_vec();
assert_eq!(String::from_utf8(xs).unwrap(),
String::from("hello"));
assert_eq!(String::from_utf8(xs).unwrap(), String::from("hello"));
let xs = "ศไทย中华Việt Nam".as_bytes().to_vec();
assert_eq!(String::from_utf8(xs).unwrap(),
@ -87,56 +86,40 @@ fn test_from_utf8_lossy() {
String::from("\u{FFFD}foo\u{FFFD}bar\u{FFFD}\u{FFFD}baz").into_cow());
let xs = b"\xF0\x80\x80\x80foo\xF0\x90\x80\x80bar";
assert_eq!(String::from_utf8_lossy(xs), String::from("\u{FFFD}\u{FFFD}\u{FFFD}\u{FFFD}\
foo\u{10000}bar").into_cow());
assert_eq!(String::from_utf8_lossy(xs),
String::from("\u{FFFD}\u{FFFD}\u{FFFD}\u{FFFD}foo\u{10000}bar").into_cow());
// surrogates
let xs = b"\xED\xA0\x80foo\xED\xBF\xBFbar";
assert_eq!(String::from_utf8_lossy(xs), String::from("\u{FFFD}\u{FFFD}\u{FFFD}foo\
\u{FFFD}\u{FFFD}\u{FFFD}bar").into_cow());
assert_eq!(String::from_utf8_lossy(xs),
String::from("\u{FFFD}\u{FFFD}\u{FFFD}foo\u{FFFD}\u{FFFD}\u{FFFD}bar").into_cow());
}
#[test]
fn test_from_utf16() {
let pairs =
[(String::from("𐍅𐌿𐌻𐍆𐌹𐌻𐌰\n"),
vec![0xd800, 0xdf45, 0xd800, 0xdf3f,
0xd800, 0xdf3b, 0xd800, 0xdf46,
0xd800, 0xdf39, 0xd800, 0xdf3b,
0xd800, 0xdf30, 0x000a]),
let pairs = [(String::from("𐍅𐌿𐌻𐍆𐌹𐌻𐌰\n"),
vec![0xd800, 0xdf45, 0xd800, 0xdf3f, 0xd800, 0xdf3b, 0xd800, 0xdf46, 0xd800,
0xdf39, 0xd800, 0xdf3b, 0xd800, 0xdf30, 0x000a]),
(String::from("𐐒𐑉𐐮𐑀𐐲𐑋 𐐏𐐲𐑍\n"),
vec![0xd801, 0xdc12, 0xd801,
0xdc49, 0xd801, 0xdc2e, 0xd801,
0xdc40, 0xd801, 0xdc32, 0xd801,
0xdc4b, 0x0020, 0xd801, 0xdc0f,
0xd801, 0xdc32, 0xd801, 0xdc4d,
0x000a]),
vec![0xd801, 0xdc12, 0xd801, 0xdc49, 0xd801, 0xdc2e, 0xd801, 0xdc40, 0xd801,
0xdc32, 0xd801, 0xdc4b, 0x0020, 0xd801, 0xdc0f, 0xd801, 0xdc32, 0xd801,
0xdc4d, 0x000a]),
(String::from("𐌀𐌖𐌋𐌄𐌑𐌉·𐌌𐌄𐌕𐌄𐌋𐌉𐌑\n"),
vec![0xd800, 0xdf00, 0xd800, 0xdf16,
0xd800, 0xdf0b, 0xd800, 0xdf04,
0xd800, 0xdf11, 0xd800, 0xdf09,
0x00b7, 0xd800, 0xdf0c, 0xd800,
0xdf04, 0xd800, 0xdf15, 0xd800,
0xdf04, 0xd800, 0xdf0b, 0xd800,
0xdf09, 0xd800, 0xdf11, 0x000a ]),
vec![0xd800, 0xdf00, 0xd800, 0xdf16, 0xd800, 0xdf0b, 0xd800, 0xdf04, 0xd800,
0xdf11, 0xd800, 0xdf09, 0x00b7, 0xd800, 0xdf0c, 0xd800, 0xdf04, 0xd800,
0xdf15, 0xd800, 0xdf04, 0xd800, 0xdf0b, 0xd800, 0xdf09, 0xd800, 0xdf11,
0x000a]),
(String::from("𐒋𐒘𐒈𐒑𐒛𐒒 𐒕𐒓 𐒈𐒚𐒍 𐒏𐒜𐒒𐒖𐒆 𐒕𐒆\n"),
vec![0xd801, 0xdc8b, 0xd801, 0xdc98,
0xd801, 0xdc88, 0xd801, 0xdc91,
0xd801, 0xdc9b, 0xd801, 0xdc92,
0x0020, 0xd801, 0xdc95, 0xd801,
0xdc93, 0x0020, 0xd801, 0xdc88,
0xd801, 0xdc9a, 0xd801, 0xdc8d,
0x0020, 0xd801, 0xdc8f, 0xd801,
0xdc9c, 0xd801, 0xdc92, 0xd801,
0xdc96, 0xd801, 0xdc86, 0x0020,
0xd801, 0xdc95, 0xd801, 0xdc86,
0x000a ]),
vec![0xd801, 0xdc8b, 0xd801, 0xdc98, 0xd801, 0xdc88, 0xd801, 0xdc91, 0xd801,
0xdc9b, 0xd801, 0xdc92, 0x0020, 0xd801, 0xdc95, 0xd801, 0xdc93, 0x0020,
0xd801, 0xdc88, 0xd801, 0xdc9a, 0xd801, 0xdc8d, 0x0020, 0xd801, 0xdc8f,
0xd801, 0xdc9c, 0xd801, 0xdc92, 0xd801, 0xdc96, 0xd801, 0xdc86, 0x0020,
0xd801, 0xdc95, 0xd801, 0xdc86, 0x000a]),
// Issue #12318, even-numbered non-BMP planes
(String::from("\u{20000}"),
vec![0xD840, 0xDC00])];
(String::from("\u{20000}"), vec![0xD840, 0xDC00])];
for p in &pairs {
let (s, u) = (*p).clone();
@ -173,13 +156,15 @@ fn test_utf16_invalid() {
fn test_from_utf16_lossy() {
// completely positive cases tested above.
// lead + eof
assert_eq!(String::from_utf16_lossy(&[0xD800]), String::from("\u{FFFD}"));
assert_eq!(String::from_utf16_lossy(&[0xD800]),
String::from("\u{FFFD}"));
// lead + lead
assert_eq!(String::from_utf16_lossy(&[0xD800, 0xD800]),
String::from("\u{FFFD}\u{FFFD}"));
// isolated trail
assert_eq!(String::from_utf16_lossy(&[0x0061, 0xDC00]), String::from("a\u{FFFD}"));
assert_eq!(String::from_utf16_lossy(&[0x0061, 0xDC00]),
String::from("a\u{FFFD}"));
// general
assert_eq!(String::from_utf16_lossy(&[0xD800, 0xd801, 0xdc8b, 0xD800]),
@ -288,7 +273,8 @@ fn remove() {
assert_eq!(s, "ไทย中华Vit Nam; foobar");
}
#[test] #[should_panic]
#[test]
#[should_panic]
fn remove_bad() {
"".to_string().remove(1);
}
@ -302,8 +288,16 @@ fn insert() {
assert_eq!(s, "ệfooยbar");
}
#[test] #[should_panic] fn insert_bad1() { "".to_string().insert(1, 't'); }
#[test] #[should_panic] fn insert_bad2() { "".to_string().insert(1, 't'); }
#[test]
#[should_panic]
fn insert_bad1() {
"".to_string().insert(1, 't');
}
#[test]
#[should_panic]
fn insert_bad2() {
"".to_string().insert(1, 't');
}
#[test]
fn test_slicing() {
@ -331,8 +325,7 @@ fn test_vectors() {
assert_eq!(format!("{:?}", x), "[]");
assert_eq!(format!("{:?}", vec![1]), "[1]");
assert_eq!(format!("{:?}", vec![1, 2, 3]), "[1, 2, 3]");
assert!(format!("{:?}", vec![vec![], vec![1], vec![1, 1]]) ==
"[[], [1], [1, 1]]");
assert!(format!("{:?}", vec![vec![], vec![1], vec![1, 1]]) == "[[], [1], [1, 1]]");
}
#[test]
@ -390,9 +383,7 @@ fn test_into_boxed_str() {
#[bench]
fn bench_with_capacity(b: &mut Bencher) {
b.iter(|| {
String::with_capacity(100)
});
b.iter(|| String::with_capacity(100));
}
#[bench]
@ -495,25 +486,19 @@ fn bench_exact_size_shrink_to_fit(b: &mut Bencher) {
fn bench_from_str(b: &mut Bencher) {
let s = "Hello there, the quick brown fox jumped over the lazy dog! \
Lorem ipsum dolor sit amet, consectetur. ";
b.iter(|| {
String::from(s)
})
b.iter(|| String::from(s))
}
#[bench]
fn bench_from(b: &mut Bencher) {
let s = "Hello there, the quick brown fox jumped over the lazy dog! \
Lorem ipsum dolor sit amet, consectetur. ";
b.iter(|| {
String::from(s)
})
b.iter(|| String::from(s))
}
#[bench]
fn bench_to_string(b: &mut Bencher) {
let s = "Hello there, the quick brown fox jumped over the lazy dog! \
Lorem ipsum dolor sit amet, consectetur. ";
b.iter(|| {
s.to_string()
})
b.iter(|| s.to_string())
}

View file

@ -15,7 +15,7 @@ use std::mem::size_of;
use test::Bencher;
struct DropCounter<'a> {
count: &'a mut u32
count: &'a mut u32,
}
impl<'a> Drop for DropCounter<'a> {
@ -33,14 +33,14 @@ fn test_small_vec_struct() {
fn test_double_drop() {
struct TwoVec<T> {
x: Vec<T>,
y: Vec<T>
y: Vec<T>,
}
let (mut count_x, mut count_y) = (0, 0);
{
let mut tv = TwoVec {
x: Vec::new(),
y: Vec::new()
y: Vec::new(),
};
tv.x.push(DropCounter { count: &mut count_x });
tv.y.push(DropCounter { count: &mut count_y });
@ -85,12 +85,16 @@ fn test_extend() {
let mut w = Vec::new();
v.extend(0..3);
for i in 0..3 { w.push(i) }
for i in 0..3 {
w.push(i)
}
assert_eq!(v, w);
v.extend(3..10);
for i in 3..10 { w.push(i) }
for i in 3..10 {
w.push(i)
}
assert_eq!(v, w);
@ -169,7 +173,7 @@ fn test_split_at_mut() {
#[test]
fn test_clone() {
let v: Vec<i32> = vec![];
let w = vec!(1, 2, 3);
let w = vec![1, 2, 3];
assert_eq!(v, v.clone());
@ -181,9 +185,9 @@ fn test_clone() {
#[test]
fn test_clone_from() {
let mut v = vec!();
let three: Vec<Box<_>> = vec!(box 1, box 2, box 3);
let two: Vec<Box<_>> = vec!(box 4, box 5);
let mut v = vec![];
let three: Vec<Box<_>> = vec![box 1, box 2, box 3];
let two: Vec<Box<_>> = vec![box 4, box 5];
// zero, long
v.clone_from(&three);
assert_eq!(v, three);
@ -235,16 +239,22 @@ fn zero_sized_values() {
assert_eq!(v.iter_mut().count(), 4);
for &mut () in &mut v {}
unsafe { v.set_len(0); }
unsafe {
v.set_len(0);
}
assert_eq!(v.iter_mut().count(), 0);
}
#[test]
fn test_partition() {
assert_eq!(vec![].into_iter().partition(|x: &i32| *x < 3), (vec![], vec![]));
assert_eq!(vec![1, 2, 3].into_iter().partition(|x| *x < 4), (vec![1, 2, 3], vec![]));
assert_eq!(vec![1, 2, 3].into_iter().partition(|x| *x < 2), (vec![1], vec![2, 3]));
assert_eq!(vec![1, 2, 3].into_iter().partition(|x| *x < 0), (vec![], vec![1, 2, 3]));
assert_eq!(vec![].into_iter().partition(|x: &i32| *x < 3),
(vec![], vec![]));
assert_eq!(vec![1, 2, 3].into_iter().partition(|x| *x < 4),
(vec![1, 2, 3], vec![]));
assert_eq!(vec![1, 2, 3].into_iter().partition(|x| *x < 2),
(vec![1], vec![2, 3]));
assert_eq!(vec![1, 2, 3].into_iter().partition(|x| *x < 0),
(vec![], vec![1, 2, 3]));
}
#[test]
@ -264,7 +274,9 @@ fn test_vec_truncate_drop() {
struct Elem(i32);
impl Drop for Elem {
fn drop(&mut self) {
unsafe { drops += 1; }
unsafe {
drops += 1;
}
}
}

View file

@ -186,7 +186,7 @@ enum Taggypar<T> {
struct RecCy {
x: i32,
y: i32,
t: Taggy
t: Taggy,
}
#[test]
@ -209,10 +209,26 @@ fn test_param_taggypar() {
#[test]
fn test_param_reccy() {
let reccy1 = RecCy { x: 1, y: 2, t: One(1) };
let reccy2 = RecCy { x: 345, y: 2, t: Two(1, 2) };
let reccy3 = RecCy { x: 1, y: 777, t: Three(1, 2, 3) };
let reccy4 = RecCy { x: 19, y: 252, t: Two(17, 42) };
let reccy1 = RecCy {
x: 1,
y: 2,
t: One(1),
};
let reccy2 = RecCy {
x: 345,
y: 2,
t: Two(1, 2),
};
let reccy3 = RecCy {
x: 1,
y: 777,
t: Three(1, 2, 3),
};
let reccy4 = RecCy {
x: 19,
y: 252,
t: Two(17, 42),
};
test_parameterized::<RecCy>(reccy1, reccy2, reccy3, reccy4);
}
@ -318,7 +334,10 @@ fn test_iter() {
loop {
match it.next() {
None => break,
_ => { len -= 1; assert_eq!(it.size_hint(), (len, Some(len))) }
_ => {
len -= 1;
assert_eq!(it.size_hint(), (len, Some(len)))
}
}
}
}
@ -532,7 +551,7 @@ fn test_drain() {
#[test]
fn test_from_iter() {
let v = vec!(1,2,3,4,5,6,7);
let v = vec![1, 2, 3, 4, 5, 6, 7];
let deq: VecDeque<_> = v.iter().cloned().collect();
let u: Vec<_> = deq.iter().cloned().collect();
assert_eq!(u, v);
@ -665,10 +684,12 @@ fn test_show() {
let ringbuf: VecDeque<_> = (0..10).collect();
assert_eq!(format!("{:?}", ringbuf), "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]");
let ringbuf: VecDeque<_> = vec!["just", "one", "test", "more"].iter()
let ringbuf: VecDeque<_> = vec!["just", "one", "test", "more"]
.iter()
.cloned()
.collect();
assert_eq!(format!("{:?}", ringbuf), "[\"just\", \"one\", \"test\", \"more\"]");
assert_eq!(format!("{:?}", ringbuf),
"[\"just\", \"one\", \"test\", \"more\"]");
}
#[test]
@ -677,7 +698,9 @@ fn test_drop() {
struct Elem;
impl Drop for Elem {
fn drop(&mut self) {
unsafe { drops += 1; }
unsafe {
drops += 1;
}
}
}
@ -697,7 +720,9 @@ fn test_drop_with_pop() {
struct Elem;
impl Drop for Elem {
fn drop(&mut self) {
unsafe { drops += 1; }
unsafe {
drops += 1;
}
}
}
@ -721,7 +746,9 @@ fn test_drop_clear() {
struct Elem;
impl Drop for Elem {
fn drop(&mut self) {
unsafe { drops += 1; }
unsafe {
drops += 1;
}
}
}
@ -822,7 +849,7 @@ fn test_get_mut() {
match ring.get_mut(1) {
Some(x) => *x = -1,
None => ()
None => (),
};
assert_eq!(ring.get_mut(0), Some(&mut 0));