Rollup merge of #22623 - petrochenkov:optest, r=alexcrichton

Tests often use `vec![1, 2, 3]` instead of shorter and faster `[1, 2, 3]`.
This patch removes a lot of unnecessary `vec!`s. Hopefully, the tests will compile and run a bit faster.
This commit is contained in:
Manish Goregaokar 2015-02-25 03:20:42 +05:30
commit 0e36a27ec3
41 changed files with 254 additions and 267 deletions

View File

@ -73,7 +73,7 @@ macro_rules! vec {
};
}
# fn main() {
# assert_eq!(&[1,2,3], &vec![1,2,3]);
# assert_eq!([1,2,3], vec![1,2,3]);
# }
```

View File

@ -480,7 +480,7 @@ impl<T: Ord> BinaryHeap<T> {
/// heap.push(3);
///
/// let vec = heap.into_sorted_vec();
/// assert_eq!(vec, vec![1, 2, 3, 4, 5, 6, 7]);
/// assert_eq!(vec, [1, 2, 3, 4, 5, 6, 7]);
/// ```
pub fn into_sorted_vec(mut self) -> Vec<T> {
let mut end = self.len();

View File

@ -640,13 +640,13 @@ impl BitVec {
/// let mut bv = BitVec::from_elem(3, true);
/// bv.set(1, false);
///
/// assert_eq!(bv.to_bytes(), vec!(0b10100000));
/// assert_eq!(bv.to_bytes(), [0b10100000]);
///
/// let mut bv = BitVec::from_elem(9, false);
/// bv.set(2, true);
/// bv.set(8, true);
///
/// assert_eq!(bv.to_bytes(), vec!(0b00100000, 0b10000000));
/// assert_eq!(bv.to_bytes(), [0b00100000, 0b10000000]);
/// ```
pub fn to_bytes(&self) -> Vec<u8> {
fn bit(bit_vec: &BitVec, byte: usize, bit: usize) -> u8 {
@ -806,7 +806,7 @@ impl BitVec {
/// let mut bv = BitVec::from_bytes(&[0b01001011]);
/// bv.grow(2, true);
/// assert_eq!(bv.len(), 10);
/// assert_eq!(bv.to_bytes(), vec!(0b01001011, 0b11000000));
/// assert_eq!(bv.to_bytes(), [0b01001011, 0b11000000]);
/// ```
pub fn grow(&mut self, n: usize, value: bool) {
// Note: we just bulk set all the bits in the last word in this fn in multiple places
@ -2285,12 +2285,12 @@ mod tests {
fn test_to_bytes() {
let mut bv = BitVec::from_elem(3, true);
bv.set(1, false);
assert_eq!(bv.to_bytes(), vec!(0b10100000));
assert_eq!(bv.to_bytes(), [0b10100000]);
let mut bv = BitVec::from_elem(9, false);
bv.set(2, true);
bv.set(8, true);
assert_eq!(bv.to_bytes(), vec!(0b00100000, 0b10000000));
assert_eq!(bv.to_bytes(), [0b00100000, 0b10000000]);
}
#[test]
@ -2675,7 +2675,7 @@ mod bit_set_test {
let bit_vec: BitSet = usizes.into_iter().collect();
let idxs: Vec<_> = bit_vec.iter().collect();
assert_eq!(idxs, vec![0, 2, 3]);
assert_eq!(idxs, [0, 2, 3]);
let long: BitSet = (0..10000).filter(|&n| n % 2 == 0).collect();
let real: Vec<_> = range_step(0, 10000, 2).collect();

View File

@ -1281,7 +1281,7 @@ impl<K, V> BTreeMap<K, V> {
/// a.insert(2, "b");
///
/// let keys: Vec<usize> = a.keys().cloned().collect();
/// assert_eq!(keys, vec![1,2,]);
/// assert_eq!(keys, [1, 2]);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn keys<'a>(&'a self) -> Keys<'a, K, V> {
@ -1303,7 +1303,7 @@ impl<K, V> BTreeMap<K, V> {
/// a.insert(2, "b");
///
/// let values: Vec<&str> = a.values().cloned().collect();
/// assert_eq!(values, vec!["a","b"]);
/// assert_eq!(values, ["a", "b"]);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn values<'a>(&'a self) -> Values<'a, K, V> {

View File

@ -121,7 +121,7 @@ impl<T> BTreeSet<T> {
/// }
///
/// let v: Vec<usize> = set.iter().cloned().collect();
/// assert_eq!(v, vec![1,2,3,4]);
/// assert_eq!(v, [1, 2, 3, 4]);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn iter(&self) -> Iter<T> {
@ -138,7 +138,7 @@ impl<T> BTreeSet<T> {
/// let set: BTreeSet<usize> = [1, 2, 3, 4].iter().cloned().collect();
///
/// let v: Vec<usize> = set.into_iter().collect();
/// assert_eq!(v, vec![1,2,3,4]);
/// assert_eq!(v, [1, 2, 3, 4]);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn into_iter(self) -> IntoIter<T> {
@ -197,7 +197,7 @@ impl<T: Ord> BTreeSet<T> {
/// b.insert(3);
///
/// let diff: Vec<usize> = a.difference(&b).cloned().collect();
/// assert_eq!(diff, vec![1]);
/// assert_eq!(diff, [1]);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn difference<'a>(&'a self, other: &'a BTreeSet<T>) -> Difference<'a, T> {
@ -220,7 +220,7 @@ impl<T: Ord> BTreeSet<T> {
/// b.insert(3);
///
/// let sym_diff: Vec<usize> = a.symmetric_difference(&b).cloned().collect();
/// assert_eq!(sym_diff, vec![1,3]);
/// assert_eq!(sym_diff, [1, 3]);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn symmetric_difference<'a>(&'a self, other: &'a BTreeSet<T>)
@ -244,7 +244,7 @@ impl<T: Ord> BTreeSet<T> {
/// b.insert(3);
///
/// let intersection: Vec<usize> = a.intersection(&b).cloned().collect();
/// assert_eq!(intersection, vec![2]);
/// assert_eq!(intersection, [2]);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn intersection<'a>(&'a self, other: &'a BTreeSet<T>)
@ -266,7 +266,7 @@ impl<T: Ord> BTreeSet<T> {
/// b.insert(2);
///
/// let union: Vec<usize> = a.union(&b).cloned().collect();
/// assert_eq!(union, vec![1,2]);
/// assert_eq!(union, [1, 2]);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn union<'a>(&'a self, other: &'a BTreeSet<T>) -> Union<'a, T> {
@ -534,7 +534,7 @@ impl<'a, 'b, T: Ord + Clone> Sub<&'b BTreeSet<T>> for &'a BTreeSet<T> {
///
/// let result = &a - &b;
/// let result_vec: Vec<_> = result.into_iter().collect();
/// assert_eq!(result_vec, vec![1, 2]);
/// assert_eq!(result_vec, [1, 2]);
/// ```
fn sub(self, rhs: &BTreeSet<T>) -> BTreeSet<T> {
self.difference(rhs).cloned().collect()
@ -557,7 +557,7 @@ impl<'a, 'b, T: Ord + Clone> BitXor<&'b BTreeSet<T>> for &'a BTreeSet<T> {
///
/// let result = &a ^ &b;
/// let result_vec: Vec<_> = result.into_iter().collect();
/// assert_eq!(result_vec, vec![1, 4]);
/// assert_eq!(result_vec, [1, 4]);
/// ```
fn bitxor(self, rhs: &BTreeSet<T>) -> BTreeSet<T> {
self.symmetric_difference(rhs).cloned().collect()
@ -580,7 +580,7 @@ impl<'a, 'b, T: Ord + Clone> BitAnd<&'b BTreeSet<T>> for &'a BTreeSet<T> {
///
/// let result = &a & &b;
/// let result_vec: Vec<_> = result.into_iter().collect();
/// assert_eq!(result_vec, vec![2, 3]);
/// assert_eq!(result_vec, [2, 3]);
/// ```
fn bitand(self, rhs: &BTreeSet<T>) -> BTreeSet<T> {
self.intersection(rhs).cloned().collect()
@ -603,7 +603,7 @@ impl<'a, 'b, T: Ord + Clone> BitOr<&'b BTreeSet<T>> for &'a BTreeSet<T> {
///
/// let result = &a | &b;
/// let result_vec: Vec<_> = result.into_iter().collect();
/// assert_eq!(result_vec, vec![1, 2, 3, 4, 5]);
/// assert_eq!(result_vec, [1, 2, 3, 4, 5]);
/// ```
fn bitor(self, rhs: &BTreeSet<T>) -> BTreeSet<T> {
self.union(rhs).cloned().collect()

View File

@ -428,19 +428,19 @@ mod test {
e1.insert(A);
let elems: ::vec::Vec<_> = e1.iter().collect();
assert_eq!(vec![A], elems);
assert_eq!([A], elems);
e1.insert(C);
let elems: ::vec::Vec<_> = e1.iter().collect();
assert_eq!(vec![A,C], elems);
assert_eq!([A,C], elems);
e1.insert(C);
let elems: ::vec::Vec<_> = e1.iter().collect();
assert_eq!(vec![A,C], elems);
assert_eq!([A,C], elems);
e1.insert(B);
let elems: ::vec::Vec<_> = e1.iter().collect();
assert_eq!(vec![A,B,C], elems);
assert_eq!([A,B,C], elems);
}
///////////////////////////////////////////////////////////////////////////
@ -458,35 +458,35 @@ mod test {
let e_union = e1 | e2;
let elems: ::vec::Vec<_> = e_union.iter().collect();
assert_eq!(vec![A,B,C], elems);
assert_eq!([A,B,C], elems);
let e_intersection = e1 & e2;
let elems: ::vec::Vec<_> = e_intersection.iter().collect();
assert_eq!(vec![C], elems);
assert_eq!([C], elems);
// Another way to express intersection
let e_intersection = e1 - (e1 - e2);
let elems: ::vec::Vec<_> = e_intersection.iter().collect();
assert_eq!(vec![C], elems);
assert_eq!([C], elems);
let e_subtract = e1 - e2;
let elems: ::vec::Vec<_> = e_subtract.iter().collect();
assert_eq!(vec![A], elems);
assert_eq!([A], elems);
// Bitwise XOR of two sets, aka symmetric difference
let e_symmetric_diff = e1 ^ e2;
let elems: ::vec::Vec<_> = e_symmetric_diff.iter().collect();
assert_eq!(vec![A,B], elems);
assert_eq!([A,B], elems);
// Another way to express symmetric difference
let e_symmetric_diff = (e1 - e2) | (e2 - e1);
let elems: ::vec::Vec<_> = e_symmetric_diff.iter().collect();
assert_eq!(vec![A,B], elems);
assert_eq!([A,B], elems);
// Yet another way to express symmetric difference
let e_symmetric_diff = (e1 | e2) - (e1 & e2);
let elems: ::vec::Vec<_> = e_symmetric_diff.iter().collect();
assert_eq!(vec![A,B], elems);
assert_eq!([A,B], elems);
}
#[test]

View File

@ -777,7 +777,7 @@ impl<'a, A> IterMut<'a, A> {
/// }
/// {
/// let vec: Vec<_> = list.into_iter().collect();
/// assert_eq!(vec, vec![1, 2, 3, 4]);
/// assert_eq!(vec, [1, 2, 3, 4]);
/// }
/// ```
#[inline]
@ -1273,7 +1273,7 @@ mod tests {
}
check_links(&m);
assert_eq!(m.len(), 3 + len * 2);
assert_eq!(m.into_iter().collect::<Vec<_>>(), vec![-2,0,1,2,3,4,5,6,7,8,9,0,1]);
assert_eq!(m.into_iter().collect::<Vec<_>>(), [-2,0,1,2,3,4,5,6,7,8,9,0,1]);
}
#[test]

View File

@ -26,7 +26,7 @@
///
/// ```
/// let v = vec![1; 3];
/// assert_eq!(v, vec![1, 1, 1]);
/// assert_eq!(v, [1, 1, 1]);
/// ```
///
/// Note that unlike array expressions this syntax supports all elements

View File

@ -1779,10 +1779,10 @@ mod tests {
let mut v = vec![1, 2, 3, 4, 5];
let mut e = v.swap_remove(0);
assert_eq!(e, 1);
assert_eq!(v, vec![5, 2, 3, 4]);
assert_eq!(v, [5, 2, 3, 4]);
e = v.swap_remove(3);
assert_eq!(e, 4);
assert_eq!(v, vec![5, 2, 3]);
assert_eq!(v, [5, 2, 3]);
}
#[test]
@ -1890,7 +1890,7 @@ mod tests {
fn test_retain() {
let mut v = vec![1, 2, 3, 4, 5];
v.retain(is_odd);
assert_eq!(v, vec![1, 3, 5]);
assert_eq!(v, [1, 3, 5]);
}
#[test]
@ -2159,45 +2159,45 @@ mod tests {
let v: [Vec<i32>; 0] = [];
let c = v.concat();
assert_eq!(c, []);
let d = [vec![1], vec![2,3]].concat();
assert_eq!(d, vec![1, 2, 3]);
let d = [vec![1], vec![2, 3]].concat();
assert_eq!(d, [1, 2, 3]);
let v: &[&[_]] = &[&[1], &[2, 3]];
assert_eq!(v.connect(&0), vec![1, 0, 2, 3]);
assert_eq!(v.connect(&0), [1, 0, 2, 3]);
let v: &[&[_]] = &[&[1], &[2], &[3]];
assert_eq!(v.connect(&0), vec![1, 0, 2, 0, 3]);
assert_eq!(v.connect(&0), [1, 0, 2, 0, 3]);
}
#[test]
fn test_connect() {
let v: [Vec<i32>; 0] = [];
assert_eq!(v.connect(&0), vec![]);
assert_eq!([vec![1], vec![2, 3]].connect(&0), vec![1, 0, 2, 3]);
assert_eq!([vec![1], vec![2], vec![3]].connect(&0), vec![1, 0, 2, 0, 3]);
assert_eq!(v.connect(&0), []);
assert_eq!([vec![1i], vec![2, 3]].connect(&0), [1, 0, 2, 3]);
assert_eq!([vec![1i], vec![2], vec![3]].connect(&0), [1, 0, 2, 0, 3]);
let v: [&[_]; 2] = [&[1], &[2, 3]];
assert_eq!(v.connect(&0), vec![1, 0, 2, 3]);
assert_eq!(v.connect(&0), [1, 0, 2, 3]);
let v: [&[_]; 3] = [&[1], &[2], &[3]];
assert_eq!(v.connect(&0), vec![1, 0, 2, 0, 3]);
assert_eq!(v.connect(&0), [1, 0, 2, 0, 3]);
}
#[test]
fn test_insert() {
let mut a = vec![1, 2, 4];
a.insert(2, 3);
assert_eq!(a, vec![1, 2, 3, 4]);
assert_eq!(a, [1, 2, 3, 4]);
let mut a = vec![1, 2, 3];
a.insert(0, 0);
assert_eq!(a, vec![0, 1, 2, 3]);
assert_eq!(a, [0, 1, 2, 3]);
let mut a = vec![1, 2, 3];
a.insert(3, 4);
assert_eq!(a, vec![1, 2, 3, 4]);
assert_eq!(a, [1, 2, 3, 4]);
let mut a = vec![];
a.insert(0, 1);
assert_eq!(a, vec![1]);
assert_eq!(a, [1]);
}
#[test]
@ -2212,16 +2212,16 @@ mod tests {
let mut a = vec![1, 2, 3, 4];
assert_eq!(a.remove(2), 3);
assert_eq!(a, vec![1, 2, 4]);
assert_eq!(a, [1, 2, 4]);
assert_eq!(a.remove(2), 4);
assert_eq!(a, vec![1, 2]);
assert_eq!(a, [1, 2]);
assert_eq!(a.remove(0), 1);
assert_eq!(a, vec![2]);
assert_eq!(a, [2]);
assert_eq!(a.remove(0), 2);
assert_eq!(a, vec![]);
assert_eq!(a, []);
}
#[test]

View File

@ -552,7 +552,7 @@ pub trait StrExt: Index<RangeFull, Output = str> {
/// ```
/// let v: Vec<char> = "abc åäö".chars().collect();
///
/// assert_eq!(v, vec!['a', 'b', 'c', ' ', 'å', 'ä', 'ö']);
/// assert_eq!(v, ['a', 'b', 'c', ' ', 'å', 'ä', 'ö']);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
fn chars(&self) -> Chars {
@ -600,20 +600,20 @@ pub trait StrExt: Index<RangeFull, Output = str> {
///
/// ```
/// let v: Vec<&str> = "Mary had a little lamb".split(' ').collect();
/// assert_eq!(v, vec!["Mary", "had", "a", "little", "lamb"]);
/// assert_eq!(v, ["Mary", "had", "a", "little", "lamb"]);
///
/// let v: Vec<&str> = "".split('X').collect();
/// assert_eq!(v, vec![""]);
/// assert_eq!(v, [""]);
/// ```
///
/// More complex patterns with a lambda:
///
/// ```
/// let v: Vec<&str> = "abc1def2ghi".split(|c: char| c.is_numeric()).collect();
/// assert_eq!(v, vec!["abc", "def", "ghi"]);
/// assert_eq!(v, ["abc", "def", "ghi"]);
///
/// let v: Vec<&str> = "lionXXtigerXleopard".split('X').collect();
/// assert_eq!(v, vec!["lion", "", "tiger", "leopard"]);
/// assert_eq!(v, ["lion", "", "tiger", "leopard"]);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
fn split<'a, P: Pattern<'a>>(&'a self, pat: P) -> Split<'a, P> {
@ -632,23 +632,23 @@ pub trait StrExt: Index<RangeFull, Output = str> {
///
/// ```
/// let v: Vec<&str> = "Mary had a little lambda".splitn(2, ' ').collect();
/// assert_eq!(v, vec!["Mary", "had", "a little lambda"]);
/// assert_eq!(v, ["Mary", "had", "a little lambda"]);
///
/// let v: Vec<&str> = "lionXXtigerXleopard".splitn(2, 'X').collect();
/// assert_eq!(v, vec!["lion", "", "tigerXleopard"]);
/// assert_eq!(v, ["lion", "", "tigerXleopard"]);
///
/// let v: Vec<&str> = "abcXdef".splitn(0, 'X').collect();
/// assert_eq!(v, vec!["abcXdef"]);
/// assert_eq!(v, ["abcXdef"]);
///
/// let v: Vec<&str> = "".splitn(1, 'X').collect();
/// assert_eq!(v, vec![""]);
/// assert_eq!(v, [""]);
/// ```
///
/// More complex patterns with a lambda:
///
/// ```
/// let v: Vec<&str> = "abc1def2ghi".splitn(1, |c: char| c.is_numeric()).collect();
/// assert_eq!(v, vec!["abc", "def2ghi"]);
/// assert_eq!(v, ["abc", "def2ghi"]);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
fn splitn<'a, P: Pattern<'a>>(&'a self, count: usize, pat: P) -> SplitN<'a, P> {
@ -669,17 +669,17 @@ pub trait StrExt: Index<RangeFull, Output = str> {
///
/// ```
/// let v: Vec<&str> = "A.B.".split_terminator('.').collect();
/// assert_eq!(v, vec!["A", "B"]);
/// assert_eq!(v, ["A", "B"]);
///
/// let v: Vec<&str> = "A..B..".split_terminator('.').collect();
/// assert_eq!(v, vec!["A", "", "B", ""]);
/// assert_eq!(v, ["A", "", "B", ""]);
/// ```
///
/// More complex patterns with a lambda:
///
/// ```
/// let v: Vec<&str> = "abc1def2ghi3".split_terminator(|c: char| c.is_numeric()).collect();
/// assert_eq!(v, vec!["abc", "def", "ghi"]);
/// assert_eq!(v, ["abc", "def", "ghi"]);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
fn split_terminator<'a, P: Pattern<'a>>(&'a self, pat: P) -> SplitTerminator<'a, P> {
@ -699,17 +699,17 @@ pub trait StrExt: Index<RangeFull, Output = str> {
///
/// ```
/// let v: Vec<&str> = "Mary had a little lamb".rsplitn(2, ' ').collect();
/// assert_eq!(v, vec!["lamb", "little", "Mary had a"]);
/// assert_eq!(v, ["lamb", "little", "Mary had a"]);
///
/// let v: Vec<&str> = "lionXXtigerXleopard".rsplitn(2, 'X').collect();
/// assert_eq!(v, vec!["leopard", "tiger", "lionX"]);
/// assert_eq!(v, ["leopard", "tiger", "lionX"]);
/// ```
///
/// More complex patterns with a lambda:
///
/// ```
/// let v: Vec<&str> = "abc1def2ghi".rsplitn(1, |c: char| c.is_numeric()).collect();
/// assert_eq!(v, vec!["ghi", "abc1def"]);
/// assert_eq!(v, ["ghi", "abc1def"]);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
fn rsplitn<'a, P: Pattern<'a>>(&'a self, count: usize, pat: P) -> RSplitN<'a, P> {
@ -727,13 +727,13 @@ pub trait StrExt: Index<RangeFull, Output = str> {
///
/// ```
/// let v: Vec<(usize, usize)> = "abcXXXabcYYYabc".match_indices("abc").collect();
/// assert_eq!(v, vec![(0,3), (6,9), (12,15)]);
/// assert_eq!(v, [(0,3), (6,9), (12,15)]);
///
/// let v: Vec<(usize, usize)> = "1abcabc2".match_indices("abc").collect();
/// assert_eq!(v, vec![(1,4), (4,7)]);
/// assert_eq!(v, [(1,4), (4,7)]);
///
/// let v: Vec<(usize, usize)> = "ababa".match_indices("aba").collect();
/// assert_eq!(v, vec![(0, 3)]); // only the first `aba`
/// assert_eq!(v, [(0, 3)]); // only the first `aba`
/// ```
#[unstable(feature = "collections",
reason = "might have its iterator type changed")]
@ -749,10 +749,10 @@ pub trait StrExt: Index<RangeFull, Output = str> {
///
/// ```
/// let v: Vec<&str> = "abcXXXabcYYYabc".split_str("abc").collect();
/// assert_eq!(v, vec!["", "XXX", "YYY", ""]);
/// assert_eq!(v, ["", "XXX", "YYY", ""]);
///
/// let v: Vec<&str> = "1abcabc2".split_str("abc").collect();
/// assert_eq!(v, vec!["1", "", "2"]);
/// assert_eq!(v, ["1", "", "2"]);
/// ```
#[unstable(feature = "collections")]
#[deprecated(since = "1.0.0", reason = "use `split()` with a `&str`")]
@ -770,7 +770,7 @@ pub trait StrExt: Index<RangeFull, Output = str> {
/// let four_lines = "foo\nbar\n\nbaz";
/// let v: Vec<&str> = four_lines.lines().collect();
///
/// assert_eq!(v, vec!["foo", "bar", "", "baz"]);
/// assert_eq!(v, ["foo", "bar", "", "baz"]);
/// ```
///
/// Leaving off the trailing character:
@ -779,7 +779,7 @@ pub trait StrExt: Index<RangeFull, Output = str> {
/// let four_lines = "foo\nbar\n\nbaz\n";
/// let v: Vec<&str> = four_lines.lines().collect();
///
/// assert_eq!(v, vec!["foo", "bar", "", "baz"]);
/// assert_eq!(v, ["foo", "bar", "", "baz"]);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
fn lines(&self) -> Lines {
@ -796,7 +796,7 @@ pub trait StrExt: Index<RangeFull, Output = str> {
/// let four_lines = "foo\r\nbar\n\r\nbaz";
/// let v: Vec<&str> = four_lines.lines_any().collect();
///
/// assert_eq!(v, vec!["foo", "bar", "", "baz"]);
/// assert_eq!(v, ["foo", "bar", "", "baz"]);
/// ```
///
/// Leaving off the trailing character:
@ -805,7 +805,7 @@ pub trait StrExt: Index<RangeFull, Output = str> {
/// let four_lines = "foo\r\nbar\n\r\nbaz\n";
/// let v: Vec<&str> = four_lines.lines_any().collect();
///
/// assert_eq!(v, vec!["foo", "bar", "", "baz"]);
/// assert_eq!(v, ["foo", "bar", "", "baz"]);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
fn lines_any(&self) -> LinesAny {
@ -1441,7 +1441,7 @@ pub trait StrExt: Index<RangeFull, Output = str> {
/// let some_words = " Mary had\ta little \n\t lamb";
/// let v: Vec<&str> = some_words.words().collect();
///
/// assert_eq!(v, vec!["Mary", "had", "a", "little", "lamb"]);
/// assert_eq!(v, ["Mary", "had", "a", "little", "lamb"]);
/// ```
#[unstable(feature = "str_words",
reason = "the precise algorithm to use is unclear")]
@ -2400,17 +2400,17 @@ mod tests {
let data = "\nMäry häd ä little lämb\nLittle lämb\n";
let split: Vec<&str> = data.splitn(3, ' ').collect();
assert_eq!(split, vec!["\nMäry", "häd", "ä", "little lämb\nLittle lämb\n"]);
assert_eq!(split, ["\nMäry", "häd", "ä", "little lämb\nLittle lämb\n"]);
let split: Vec<&str> = data.splitn(3, |c: char| c == ' ').collect();
assert_eq!(split, vec!["\nMäry", "häd", "ä", "little lämb\nLittle lämb\n"]);
assert_eq!(split, ["\nMäry", "häd", "ä", "little lämb\nLittle lämb\n"]);
// Unicode
let split: Vec<&str> = data.splitn(3, 'ä').collect();
assert_eq!(split, vec!["\nM", "ry h", "d ", " little lämb\nLittle lämb\n"]);
assert_eq!(split, ["\nM", "ry h", "d ", " little lämb\nLittle lämb\n"]);
let split: Vec<&str> = data.splitn(3, |c: char| c == 'ä').collect();
assert_eq!(split, vec!["\nM", "ry h", "d ", " little lämb\nLittle lämb\n"]);
assert_eq!(split, ["\nM", "ry h", "d ", " little lämb\nLittle lämb\n"]);
}
#[test]
@ -2418,17 +2418,17 @@ mod tests {
let data = "\nMäry häd ä little lämb\nLittle lämb\n";
let split: Vec<&str> = data.split('\n').collect();
assert_eq!(split, vec!["", "Märy häd ä little lämb", "Little lämb", ""]);
assert_eq!(split, ["", "Märy häd ä little lämb", "Little lämb", ""]);
let split: Vec<&str> = data.split_terminator('\n').collect();
assert_eq!(split, vec!["", "Märy häd ä little lämb", "Little lämb"]);
assert_eq!(split, ["", "Märy häd ä little lämb", "Little lämb"]);
}
#[test]
fn test_words() {
let data = "\n \tMäry häd\tä little lämb\nLittle lämb\n";
let words: Vec<&str> = data.words().collect();
assert_eq!(words, vec!["Märy", "häd", "ä", "little", "lämb", "Little", "lämb"])
assert_eq!(words, ["Märy", "häd", "ä", "little", "lämb", "Little", "lämb"])
}
#[test]
@ -2513,11 +2513,11 @@ mod tests {
fn test_lines() {
let data = "\nMäry häd ä little lämb\n\nLittle lämb\n";
let lines: Vec<&str> = data.lines().collect();
assert_eq!(lines, vec!["", "Märy häd ä little lämb", "", "Little lämb"]);
assert_eq!(lines, ["", "Märy häd ä little lämb", "", "Little lämb"]);
let data = "\nMäry häd ä little lämb\n\nLittle lämb"; // no trailing \n
let lines: Vec<&str> = data.lines().collect();
assert_eq!(lines, vec!["", "Märy häd ä little lämb", "", "Little lämb"]);
assert_eq!(lines, ["", "Märy häd ä little lämb", "", "Little lämb"]);
}
#[test]

View File

@ -120,7 +120,7 @@ impl String {
/// let invalid_vec = vec![240, 144, 128];
/// let s = String::from_utf8(invalid_vec).err().unwrap();
/// assert_eq!(s.utf8_error(), Utf8Error::TooShort);
/// assert_eq!(s.into_bytes(), vec![240, 144, 128]);
/// assert_eq!(s.into_bytes(), [240, 144, 128]);
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
@ -340,7 +340,7 @@ impl String {
/// ```
/// let s = String::from_str("hello");
/// let bytes = s.into_bytes();
/// assert_eq!(bytes, vec![104, 101, 108, 108, 111]);
/// assert_eq!(bytes, [104, 101, 108, 108, 111]);
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
@ -619,7 +619,7 @@ impl String {
/// let mut s = String::from_str("hello");
/// unsafe {
/// let vec = s.as_mut_vec();
/// assert!(vec == &mut vec![104, 101, 108, 108, 111]);
/// assert!(vec == &[104, 101, 108, 108, 111]);
/// vec.reverse();
/// }
/// assert_eq!(s.as_slice(), "olleh");

View File

@ -93,7 +93,7 @@ use borrow::{Cow, IntoCow};
/// for x in vec.iter() {
/// println!("{}", x);
/// }
/// assert_eq!(vec, vec![7, 1, 2, 3]);
/// assert_eq!(vec, [7, 1, 2, 3]);
/// ```
///
/// The `vec!` macro is provided to make initialization more convenient:
@ -101,7 +101,7 @@ use borrow::{Cow, IntoCow};
/// ```
/// let mut vec = vec![1, 2, 3];
/// vec.push(4);
/// assert_eq!(vec, vec![1, 2, 3, 4]);
/// assert_eq!(vec, [1, 2, 3, 4]);
/// ```
///
/// Use a `Vec<T>` as an efficient stack:
@ -242,7 +242,7 @@ impl<T> Vec<T> {
///
/// // Put everything back together into a Vec
/// let rebuilt = Vec::from_raw_parts(p, len, cap);
/// assert_eq!(rebuilt, vec![4, 5, 6]);
/// assert_eq!(rebuilt, [4, 5, 6]);
/// }
/// }
/// ```
@ -404,7 +404,7 @@ impl<T> Vec<T> {
/// ```
/// let mut vec = vec![1, 2, 3, 4];
/// vec.truncate(2);
/// assert_eq!(vec, vec![1, 2]);
/// assert_eq!(vec, [1, 2]);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn truncate(&mut self, len: usize) {
@ -505,10 +505,10 @@ impl<T> Vec<T> {
/// let mut v = vec!["foo", "bar", "baz", "qux"];
///
/// assert_eq!(v.swap_remove(1), "bar");
/// assert_eq!(v, vec!["foo", "qux", "baz"]);
/// assert_eq!(v, ["foo", "qux", "baz"]);
///
/// assert_eq!(v.swap_remove(0), "foo");
/// assert_eq!(v, vec!["baz", "qux"]);
/// assert_eq!(v, ["baz", "qux"]);
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
@ -531,9 +531,9 @@ impl<T> Vec<T> {
/// ```
/// let mut vec = vec![1, 2, 3];
/// vec.insert(1, 4);
/// assert_eq!(vec, vec![1, 4, 2, 3]);
/// assert_eq!(vec, [1, 4, 2, 3]);
/// vec.insert(4, 5);
/// assert_eq!(vec, vec![1, 4, 2, 3, 5]);
/// assert_eq!(vec, [1, 4, 2, 3, 5]);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn insert(&mut self, index: usize, element: T) {
@ -569,7 +569,7 @@ impl<T> Vec<T> {
/// ```
/// let mut v = vec![1, 2, 3];
/// assert_eq!(v.remove(1), 2);
/// assert_eq!(v, vec![1, 3]);
/// assert_eq!(v, [1, 3]);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn remove(&mut self, index: usize) -> T {
@ -603,7 +603,7 @@ impl<T> Vec<T> {
/// ```
/// let mut vec = vec![1, 2, 3, 4];
/// vec.retain(|&x| x%2 == 0);
/// assert_eq!(vec, vec![2, 4]);
/// assert_eq!(vec, [2, 4]);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn retain<F>(&mut self, mut f: F) where F: FnMut(&T) -> bool {
@ -636,7 +636,7 @@ impl<T> Vec<T> {
/// ```rust
/// let mut vec = vec!(1, 2);
/// vec.push(3);
/// assert_eq!(vec, vec!(1, 2, 3));
/// assert_eq!(vec, [1, 2, 3]);
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
@ -674,7 +674,7 @@ impl<T> Vec<T> {
/// ```rust
/// let mut vec = vec![1, 2, 3];
/// assert_eq!(vec.pop(), Some(3));
/// assert_eq!(vec, vec![1, 2]);
/// assert_eq!(vec, [1, 2]);
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
@ -701,8 +701,8 @@ impl<T> Vec<T> {
/// let mut vec = vec![1, 2, 3];
/// let mut vec2 = vec![4, 5, 6];
/// vec.append(&mut vec2);
/// assert_eq!(vec, vec![1, 2, 3, 4, 5, 6]);
/// assert_eq!(vec2, vec![]);
/// assert_eq!(vec, [1, 2, 3, 4, 5, 6]);
/// assert_eq!(vec2, []);
/// ```
#[inline]
#[unstable(feature = "collections",
@ -1019,8 +1019,8 @@ impl<T> Vec<T> {
/// ```
/// let mut vec = vec![1,2,3];
/// let vec2 = vec.split_off(1);
/// assert_eq!(vec, vec![1]);
/// assert_eq!(vec2, vec![2, 3]);
/// assert_eq!(vec, [1]);
/// assert_eq!(vec2, [2, 3]);
/// ```
#[inline]
#[unstable(feature = "collections",
@ -1057,11 +1057,11 @@ impl<T: Clone> Vec<T> {
/// ```
/// let mut vec = vec!["hello"];
/// vec.resize(3, "world");
/// assert_eq!(vec, vec!["hello", "world", "world"]);
/// assert_eq!(vec, ["hello", "world", "world"]);
///
/// let mut vec = vec![1, 2, 3, 4];
/// vec.resize(2, 0);
/// assert_eq!(vec, vec![1, 2]);
/// assert_eq!(vec, [1, 2]);
/// ```
#[unstable(feature = "collections",
reason = "matches collection reform specification; waiting for dust to settle")]
@ -1085,7 +1085,7 @@ impl<T: Clone> Vec<T> {
/// ```
/// let mut vec = vec![1];
/// vec.push_all(&[2, 3, 4]);
/// assert_eq!(vec, vec![1, 2, 3, 4]);
/// assert_eq!(vec, [1, 2, 3, 4]);
/// ```
#[inline]
#[unstable(feature = "collections",
@ -1121,7 +1121,7 @@ impl<T: PartialEq> Vec<T> {
///
/// vec.dedup();
///
/// assert_eq!(vec, vec![1, 2, 3, 2]);
/// assert_eq!(vec, [1, 2, 3, 2]);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn dedup(&mut self) {
@ -2105,7 +2105,7 @@ mod tests {
}
}
assert!(values == vec![2, 3, 5, 6, 7]);
assert_eq!(values, [2, 3, 5, 6, 7]);
}
#[test]
@ -2147,7 +2147,7 @@ mod tests {
fn test_retain() {
let mut vec = vec![1, 2, 3, 4];
vec.retain(|&x| x % 2 == 0);
assert!(vec == vec![2, 4]);
assert_eq!(vec, [2, 4]);
}
#[test]
@ -2207,13 +2207,13 @@ mod tests {
let a = [1, 2, 3];
let ptr = a.as_ptr();
let b = Vec::from_raw_buf(ptr, 3);
assert_eq!(b, vec![1, 2, 3]);
assert_eq!(b, [1, 2, 3]);
// Test on-heap copy-from-buf.
let c = vec![1, 2, 3, 4, 5];
let ptr = c.as_ptr();
let d = Vec::from_raw_buf(ptr, 5);
assert_eq!(d, vec![1, 2, 3, 4, 5]);
assert_eq!(d, [1, 2, 3, 4, 5]);
}
}
@ -2375,7 +2375,7 @@ mod tests {
for i in vec {
vec2.push(i);
}
assert!(vec2 == vec![1, 2, 3]);
assert_eq!(vec2, [1, 2, 3]);
}
#[test]
@ -2385,7 +2385,7 @@ mod tests {
for i in vec.into_iter().rev() {
vec2.push(i);
}
assert!(vec2 == vec![3, 2, 1]);
assert_eq!(vec2, [3, 2, 1]);
}
#[test]
@ -2395,7 +2395,7 @@ mod tests {
for i in vec {
vec2.push(i);
}
assert!(vec2 == vec![(), (), ()]);
assert_eq!(vec2, [(), (), ()]);
}
#[test]
@ -2443,16 +2443,16 @@ mod tests {
let mut vec = vec![1, 2, 3];
let mut vec2 = vec![4, 5, 6];
vec.append(&mut vec2);
assert_eq!(vec, vec![1, 2, 3, 4, 5, 6]);
assert_eq!(vec2, vec![]);
assert_eq!(vec, [1, 2, 3, 4, 5, 6]);
assert_eq!(vec2, []);
}
#[test]
fn test_split_off() {
let mut vec = vec![1, 2, 3, 4, 5, 6];
let vec2 = vec.split_off(4);
assert_eq!(vec, vec![1, 2, 3, 4]);
assert_eq!(vec2, vec![5, 6]);
assert_eq!(vec, [1, 2, 3, 4]);
assert_eq!(vec2, [5, 6]);
}
#[bench]

View File

@ -2105,7 +2105,7 @@ mod tests {
let mut d: VecDeque<_> = (0..5).collect();
d.pop_front();
d.swap(0, 3);
assert_eq!(d.iter().cloned().collect::<Vec<_>>(), vec!(4, 2, 3, 1));
assert_eq!(d.iter().cloned().collect::<Vec<_>>(), [4, 2, 3, 1]);
}
#[test]
@ -2868,17 +2868,17 @@ mod tests {
// normal append
a.append(&mut b);
assert_eq!(a.iter().cloned().collect(), vec![1, 2, 3, 4, 5, 6]);
assert_eq!(b.iter().cloned().collect(), vec![]);
assert_eq!(a.iter().cloned().collect::<Vec<_>>(), [1, 2, 3, 4, 5, 6]);
assert_eq!(b.iter().cloned().collect::<Vec<_>>(), []);
// append nothing to something
a.append(&mut b);
assert_eq!(a.iter().cloned().collect(), vec![1, 2, 3, 4, 5, 6]);
assert_eq!(b.iter().cloned().collect(), vec![]);
assert_eq!(a.iter().cloned().collect::<Vec<_>>(), [1, 2, 3, 4, 5, 6]);
assert_eq!(b.iter().cloned().collect::<Vec<_>>(), []);
// append something to nothing
b.append(&mut a);
assert_eq!(b.iter().cloned().collect(), vec![1, 2, 3, 4, 5, 6]);
assert_eq!(a.iter().cloned().collect(), vec![]);
assert_eq!(b.iter().cloned().collect::<Vec<_>>(), [1, 2, 3, 4, 5, 6]);
assert_eq!(a.iter().cloned().collect::<Vec<_>>(), []);
}
}

View File

@ -308,7 +308,7 @@ impl<V> VecMap<V> {
///
/// let vec: Vec<(usize, &str)> = map.into_iter().collect();
///
/// assert_eq!(vec, vec![(1, "a"), (2, "b"), (3, "c")]);
/// assert_eq!(vec, [(1, "a"), (2, "b"), (3, "c")]);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn into_iter(self) -> IntoIter<V> {
@ -425,7 +425,7 @@ impl<V> VecMap<V> {
///
/// let vec: Vec<(usize, &str)> = map.drain().collect();
///
/// assert_eq!(vec, vec![(1, "a"), (2, "b"), (3, "c")]);
/// assert_eq!(vec, [(1, "a"), (2, "b"), (3, "c")]);
/// ```
#[unstable(feature = "collections",
reason = "matches collection reform specification, waiting for dust to settle")]
@ -1226,7 +1226,7 @@ mod test_map {
let vec: Vec<_> = map.drain().collect();
assert_eq!(vec, vec![(1, "a"), (2, "b"), (3, "c")]);
assert_eq!(vec, [(1, "a"), (2, "b"), (3, "c")]);
assert_eq!(map.len(), 0);
}

View File

@ -582,8 +582,8 @@ pub trait IteratorExt: Iterator + Sized {
/// ```
/// let vec = vec![1, 2, 3, 4];
/// let (even, odd): (Vec<_>, Vec<_>) = vec.into_iter().partition(|&n| n % 2 == 0);
/// assert_eq!(even, vec![2, 4]);
/// assert_eq!(odd, vec![1, 3]);
/// assert_eq!(even, [2, 4]);
/// assert_eq!(odd, [1, 3]);
/// ```
#[unstable(feature = "core",
reason = "recently added as part of collections reform")]

View File

@ -556,7 +556,7 @@ impl<T> Option<T> {
/// ```
/// let x = Some("string");
/// let v: Vec<&str> = x.into_iter().collect();
/// assert_eq!(v, vec!["string"]);
/// assert_eq!(v, ["string"]);
///
/// let x = None;
/// let v: Vec<&str> = x.into_iter().collect();

View File

@ -548,11 +548,11 @@ impl<T, E> Result<T, E> {
/// ```
/// let x: Result<u32, &str> = Ok(5);
/// let v: Vec<u32> = x.into_iter().collect();
/// assert_eq!(v, vec![5]);
/// assert_eq!(v, [5]);
///
/// let x: Result<u32, &str> = Err("nothing!");
/// let v: Vec<u32> = x.into_iter().collect();
/// assert_eq!(v, vec![]);
/// assert_eq!(v, []);
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]

View File

@ -74,7 +74,7 @@ fn test_multi_iter() {
fn test_counter_from_iter() {
let it = count(0, 5).take(10);
let xs: Vec<int> = FromIterator::from_iter(it);
assert!(xs == vec![0, 5, 10, 15, 20, 25, 30, 35, 40, 45]);
assert_eq!(xs, [0, 5, 10, 15, 20, 25, 30, 35, 40, 45]);
}
#[test]
@ -104,7 +104,7 @@ fn test_iterator_chain() {
fn test_filter_map() {
let it = count(0, 1).take(10)
.filter_map(|x| if x % 2 == 0 { Some(x*x) } else { None });
assert!(it.collect::<Vec<uint>>() == vec![0*0, 2*2, 4*4, 6*6, 8*8]);
assert_eq!(it.collect::<Vec<uint>>(), [0*0, 2*2, 4*4, 6*6, 8*8]);
}
#[test]
@ -730,12 +730,12 @@ fn test_random_access_cycle() {
#[test]
fn test_double_ended_range() {
assert!((11..14).rev().collect::<Vec<_>>() == vec![13, 12, 11]);
assert_eq!((11..14).rev().collect::<Vec<_>>(), [13, 12, 11]);
for _ in (10..0).rev() {
panic!("unreachable");
}
assert!((11..14).rev().collect::<Vec<_>>() == vec![13, 12, 11]);
assert_eq!((11..14).rev().collect::<Vec<_>>(), [13, 12, 11]);
for _ in (10..0).rev() {
panic!("unreachable");
}
@ -743,10 +743,9 @@ fn test_double_ended_range() {
#[test]
fn test_range() {
assert!((0..5).collect::<Vec<_>>() == vec![0, 1, 2, 3, 4]);
assert!((-10..-1).collect::<Vec<_>>() ==
vec![-10, -9, -8, -7, -6, -5, -4, -3, -2]);
assert!((0..5).rev().collect::<Vec<_>>() == vec![4, 3, 2, 1, 0]);
assert_eq!((0..5).collect::<Vec<_>>(), [0, 1, 2, 3, 4]);
assert_eq!((-10..-1).collect::<Vec<_>>(), [-10, -9, -8, -7, -6, -5, -4, -3, -2]);
assert_eq!((0..5).rev().collect::<Vec<_>>(), [4, 3, 2, 1, 0]);
assert_eq!((200..-5).count(), 0);
assert_eq!((200..-5).rev().count(), 0);
assert_eq!((200..200).count(), 0);
@ -767,38 +766,28 @@ fn test_range_inclusive() {
vec![5, 4, 3, 2, 1, 0]);
assert_eq!(range_inclusive(200, -5).count(), 0);
assert_eq!(range_inclusive(200, -5).rev().count(), 0);
assert!(range_inclusive(200, 200).collect::<Vec<int>>() == vec![200]);
assert!(range_inclusive(200, 200).rev().collect::<Vec<int>>() == vec![200]);
assert_eq!(range_inclusive(200, 200).collect::<Vec<int>>(), [200]);
assert_eq!(range_inclusive(200, 200).rev().collect::<Vec<int>>(), [200]);
}
#[test]
fn test_range_step() {
assert!(range_step(0, 20, 5).collect::<Vec<int>>() ==
vec![0, 5, 10, 15]);
assert!(range_step(20, 0, -5).collect::<Vec<int>>() ==
vec![20, 15, 10, 5]);
assert!(range_step(20, 0, -6).collect::<Vec<int>>() ==
vec![20, 14, 8, 2]);
assert!(range_step(200u8, 255, 50).collect::<Vec<u8>>() ==
vec![200u8, 250]);
assert!(range_step(200, -5, 1).collect::<Vec<int>>() == vec![]);
assert!(range_step(200, 200, 1).collect::<Vec<int>>() == vec![]);
assert_eq!(range_step(0, 20, 5).collect::<Vec<int>>(), [0, 5, 10, 15]);
assert_eq!(range_step(20, 0, -5).collect::<Vec<int>>(), [20, 15, 10, 5]);
assert_eq!(range_step(20, 0, -6).collect::<Vec<int>>(), [20, 14, 8, 2]);
assert_eq!(range_step(200u8, 255, 50).collect::<Vec<u8>>(), [200u8, 250]);
assert_eq!(range_step(200i, -5, 1).collect::<Vec<int>>(), []);
assert_eq!(range_step(200i, 200, 1).collect::<Vec<int>>(), []);
}
#[test]
fn test_range_step_inclusive() {
assert!(range_step_inclusive(0, 20, 5).collect::<Vec<int>>() ==
vec![0, 5, 10, 15, 20]);
assert!(range_step_inclusive(20, 0, -5).collect::<Vec<int>>() ==
vec![20, 15, 10, 5, 0]);
assert!(range_step_inclusive(20, 0, -6).collect::<Vec<int>>() ==
vec![20, 14, 8, 2]);
assert!(range_step_inclusive(200u8, 255, 50).collect::<Vec<u8>>() ==
vec![200u8, 250]);
assert!(range_step_inclusive(200, -5, 1).collect::<Vec<int>>() ==
vec![]);
assert!(range_step_inclusive(200, 200, 1).collect::<Vec<int>>() ==
vec![200]);
assert_eq!(range_step_inclusive(0, 20, 5).collect::<Vec<int>>(), [0, 5, 10, 15, 20]);
assert_eq!(range_step_inclusive(20, 0, -5).collect::<Vec<int>>(), [20, 15, 10, 5, 0]);
assert_eq!(range_step_inclusive(20, 0, -6).collect::<Vec<int>>(), [20, 14, 8, 2]);
assert_eq!(range_step_inclusive(200u8, 255, 50).collect::<Vec<u8>>(), [200u8, 250]);
assert_eq!(range_step_inclusive(200, -5, 1).collect::<Vec<int>>(), []);
assert_eq!(range_step_inclusive(200, 200, 1).collect::<Vec<int>>(), [200]);
}
#[test]

View File

@ -103,7 +103,7 @@ fn test_transmute() {
}
unsafe {
assert!(vec![76u8] == transmute::<_, Vec<u8>>("L".to_string()));
assert_eq!([76u8], transmute::<_, Vec<u8>>("L".to_string()));
}
}

View File

@ -54,7 +54,7 @@ fn test_match_option_empty_vec() {
fn test_match_option_vec() {
let a = Some(vec![1, 2, 3, 4]);
match a {
Some(v) => assert_eq!(v, vec![1, 2, 3, 4]),
Some(v) => assert_eq!(v, [1, 2, 3, 4]),
None => panic!("unexpected None while matching on Some(vec![1, 2, 3, 4])")
}
}

View File

@ -156,7 +156,7 @@ fn test_ptr_subtraction() {
m_ptr = m_ptr.offset(-1);
}
assert!(xs_mut == vec![0,2,4,6,8,10,12,14,16,18]);
assert_eq!(xs_mut, [0,2,4,6,8,10,12,14,16,18]);
}
}

View File

@ -22,7 +22,7 @@ fn test_pattern_deref_forward() {
fn test_empty_match_indices() {
let data = "aä中!";
let vec: Vec<_> = data.match_indices("").collect();
assert_eq!(vec, vec![(0, 0), (1, 1), (3, 3), (6, 6), (7, 7)]);
assert_eq!(vec, [(0, 0), (1, 1), (3, 3), (6, 6), (7, 7)]);
}
#[test]
@ -69,20 +69,20 @@ fn test_rsplitn_char_iterator() {
let mut split: Vec<&str> = data.rsplitn(3, ' ').collect();
split.reverse();
assert_eq!(split, vec!["\nMäry häd ä", "little", "lämb\nLittle", "lämb\n"]);
assert_eq!(split, ["\nMäry häd ä", "little", "lämb\nLittle", "lämb\n"]);
let mut split: Vec<&str> = data.rsplitn(3, |c: char| c == ' ').collect();
split.reverse();
assert_eq!(split, vec!["\nMäry häd ä", "little", "lämb\nLittle", "lämb\n"]);
assert_eq!(split, ["\nMäry häd ä", "little", "lämb\nLittle", "lämb\n"]);
// Unicode
let mut split: Vec<&str> = data.rsplitn(3, 'ä').collect();
split.reverse();
assert_eq!(split, vec!["\nMäry häd ", " little l", "mb\nLittle l", "mb\n"]);
assert_eq!(split, ["\nMäry häd ", " little l", "mb\nLittle l", "mb\n"]);
let mut split: Vec<&str> = data.rsplitn(3, |c: char| c == 'ä').collect();
split.reverse();
assert_eq!(split, vec!["\nMäry häd ", " little l", "mb\nLittle l", "mb\n"]);
assert_eq!(split, ["\nMäry häd ", " little l", "mb\nLittle l", "mb\n"]);
}
#[test]
@ -90,33 +90,33 @@ fn test_split_char_iterator() {
let data = "\nMäry häd ä little lämb\nLittle lämb\n";
let split: Vec<&str> = data.split(' ').collect();
assert_eq!( split, vec!["\nMäry", "häd", "ä", "little", "lämb\nLittle", "lämb\n"]);
assert_eq!( split, ["\nMäry", "häd", "ä", "little", "lämb\nLittle", "lämb\n"]);
let mut rsplit: Vec<&str> = data.split(' ').rev().collect();
rsplit.reverse();
assert_eq!(rsplit, vec!["\nMäry", "häd", "ä", "little", "lämb\nLittle", "lämb\n"]);
assert_eq!(rsplit, ["\nMäry", "häd", "ä", "little", "lämb\nLittle", "lämb\n"]);
let split: Vec<&str> = data.split(|c: char| c == ' ').collect();
assert_eq!( split, vec!["\nMäry", "häd", "ä", "little", "lämb\nLittle", "lämb\n"]);
assert_eq!( split, ["\nMäry", "häd", "ä", "little", "lämb\nLittle", "lämb\n"]);
let mut rsplit: Vec<&str> = data.split(|c: char| c == ' ').rev().collect();
rsplit.reverse();
assert_eq!(rsplit, vec!["\nMäry", "häd", "ä", "little", "lämb\nLittle", "lämb\n"]);
assert_eq!(rsplit, ["\nMäry", "häd", "ä", "little", "lämb\nLittle", "lämb\n"]);
// Unicode
let split: Vec<&str> = data.split('ä').collect();
assert_eq!( split, vec!["\nM", "ry h", "d ", " little l", "mb\nLittle l", "mb\n"]);
assert_eq!( split, ["\nM", "ry h", "d ", " little l", "mb\nLittle l", "mb\n"]);
let mut rsplit: Vec<&str> = data.split('ä').rev().collect();
rsplit.reverse();
assert_eq!(rsplit, vec!["\nM", "ry h", "d ", " little l", "mb\nLittle l", "mb\n"]);
assert_eq!(rsplit, ["\nM", "ry h", "d ", " little l", "mb\nLittle l", "mb\n"]);
let split: Vec<&str> = data.split(|c: char| c == 'ä').collect();
assert_eq!( split, vec!["\nM", "ry h", "d ", " little l", "mb\nLittle l", "mb\n"]);
assert_eq!( split, ["\nM", "ry h", "d ", " little l", "mb\nLittle l", "mb\n"]);
let mut rsplit: Vec<&str> = data.split(|c: char| c == 'ä').rev().collect();
rsplit.reverse();
assert_eq!(rsplit, vec!["\nM", "ry h", "d ", " little l", "mb\nLittle l", "mb\n"]);
assert_eq!(rsplit, ["\nM", "ry h", "d ", " little l", "mb\nLittle l", "mb\n"]);
}
#[test]
@ -125,18 +125,18 @@ fn test_rev_split_char_iterator_no_trailing() {
let mut split: Vec<&str> = data.split('\n').rev().collect();
split.reverse();
assert_eq!(split, vec!["", "Märy häd ä little lämb", "Little lämb", ""]);
assert_eq!(split, ["", "Märy häd ä little lämb", "Little lämb", ""]);
let mut split: Vec<&str> = data.split_terminator('\n').rev().collect();
split.reverse();
assert_eq!(split, vec!["", "Märy häd ä little lämb", "Little lämb"]);
assert_eq!(split, ["", "Märy häd ä little lämb", "Little lämb"]);
}
#[test]
fn test_utf16_code_units() {
use unicode::str::Utf16Encoder;
assert_eq!(Utf16Encoder::new(vec!['é', '\u{1F4A9}'].into_iter()).collect::<Vec<u16>>(),
vec![0xE9, 0xD83D, 0xDCA9])
[0xE9, 0xD83D, 0xDCA9])
}
#[test]

View File

@ -45,7 +45,7 @@ fn combine(seek: SeekStyle, cur: uint, end: uint, offset: i64) -> IoResult<u64>
/// let mut w = SeekableMemWriter::new();
/// w.write(&[0, 1, 2]);
///
/// assert_eq!(w.unwrap(), vec!(0, 1, 2));
/// assert_eq!(w.unwrap(), [0, 1, 2]);
/// ```
pub struct SeekableMemWriter {
buf: Vec<u8>,

View File

@ -806,11 +806,11 @@ fn walk_ty() {
let tup2_ty = ty::mk_tup(tcx, vec!(tup1_ty, tup1_ty, uint_ty));
let uniq_ty = ty::mk_uniq(tcx, tup2_ty);
let walked: Vec<_> = uniq_ty.walk().collect();
assert_eq!(vec!(uniq_ty,
tup2_ty,
tup1_ty, int_ty, uint_ty, int_ty, uint_ty,
tup1_ty, int_ty, uint_ty, int_ty, uint_ty,
uint_ty),
assert_eq!([uniq_ty,
tup2_ty,
tup1_ty, int_ty, uint_ty, int_ty, uint_ty,
tup1_ty, int_ty, uint_ty, int_ty, uint_ty,
uint_ty],
walked);
})
}

View File

@ -3074,19 +3074,19 @@ mod tests {
#[test]
fn test_decode_array() {
let v: Vec<()> = super::decode("[]").unwrap();
assert_eq!(v, vec![]);
assert_eq!(v, []);
let v: Vec<()> = super::decode("[null]").unwrap();
assert_eq!(v, vec![()]);
assert_eq!(v, [()]);
let v: Vec<bool> = super::decode("[true]").unwrap();
assert_eq!(v, vec![true]);
assert_eq!(v, [true]);
let v: Vec<int> = super::decode("[3, 1]").unwrap();
assert_eq!(v, vec![3, 1]);
assert_eq!(v, [3, 1]);
let v: Vec<Vec<uint>> = super::decode("[[3], [1, 2]]").unwrap();
assert_eq!(v, vec![vec![3], vec![1, 2]]);
assert_eq!(v, [vec![3], vec![1, 2]]);
}
#[test]

View File

@ -328,7 +328,7 @@ mod test {
fn read_bytes() {
let mut reader = MemReader::new(vec!(10, 11, 12, 13));
let bytes = reader.read_exact(4).unwrap();
assert!(bytes == vec!(10, 11, 12, 13));
assert_eq!(bytes, [10, 11, 12, 13]);
}
#[test]
@ -337,7 +337,7 @@ mod test {
count: 0,
};
let bytes = reader.read_exact(4).unwrap();
assert!(bytes == vec!(10, 11, 12, 13));
assert_eq!(bytes, [10, 11, 12, 13]);
}
#[test]
@ -351,7 +351,7 @@ mod test {
let mut reader = MemReader::new(vec![10, 11, 12, 13]);
let mut buf = vec![8, 9];
assert!(reader.push_at_least(4, 4, &mut buf).is_ok());
assert!(buf == vec![8, 9, 10, 11, 12, 13]);
assert_eq!(buf, [8, 9, 10, 11, 12, 13]);
}
#[test]
@ -361,7 +361,7 @@ mod test {
};
let mut buf = vec![8, 9];
assert!(reader.push_at_least(4, 4, &mut buf).is_ok());
assert!(buf == vec![8, 9, 10, 11, 12, 13]);
assert_eq!(buf, [8, 9, 10, 11, 12, 13]);
}
#[test]
@ -369,7 +369,7 @@ mod test {
let mut reader = MemReader::new(vec![10, 11]);
let mut buf = vec![8, 9];
assert!(reader.push_at_least(4, 4, &mut buf).is_err());
assert!(buf == vec![8, 9, 10, 11]);
assert_eq!(buf, [8, 9, 10, 11]);
}
#[test]
@ -379,7 +379,7 @@ mod test {
};
let mut buf = vec![8, 9];
assert!(reader.push_at_least(4, 4, &mut buf).is_err());
assert!(buf == vec![8, 9, 10]);
assert_eq!(buf, [8, 9, 10]);
}
#[test]
@ -388,7 +388,7 @@ mod test {
count: 0,
};
let buf = reader.read_to_end().unwrap();
assert!(buf == vec!(10, 11, 12, 13));
assert_eq!(buf, [10, 11, 12, 13]);
}
#[test]
@ -398,7 +398,7 @@ mod test {
count: 0,
};
let buf = reader.read_to_end().unwrap();
assert!(buf == vec!(10, 11));
assert_eq!(buf, [10, 11]);
}
#[test]

View File

@ -60,7 +60,7 @@ impl Writer for Vec<u8> {
/// let mut w = MemWriter::new();
/// w.write(&[0, 1, 2]);
///
/// assert_eq!(w.into_inner(), vec!(0, 1, 2));
/// assert_eq!(w.into_inner(), [0, 1, 2]);
/// ```
#[unstable(feature = "io")]
#[deprecated(since = "1.0.0",
@ -118,7 +118,7 @@ impl Writer for MemWriter {
///
/// let mut r = MemReader::new(vec!(0, 1, 2));
///
/// assert_eq!(r.read_to_end().unwrap(), vec!(0, 1, 2));
/// assert_eq!(r.read_to_end().unwrap(), [0, 1, 2]);
/// ```
pub struct MemReader {
buf: Vec<u8>,
@ -321,7 +321,7 @@ impl<'a> Seek for BufWriter<'a> {
/// let buf = [0, 1, 2, 3];
/// let mut r = BufReader::new(&buf);
///
/// assert_eq!(r.read_to_end().unwrap(), vec![0, 1, 2, 3]);
/// assert_eq!(r.read_to_end().unwrap(), [0, 1, 2, 3]);
/// ```
pub struct BufReader<'a> {
buf: &'a [u8],
@ -504,8 +504,8 @@ mod test {
assert_eq!(&buf[..3], b);
assert!(reader.read(&mut buf).is_err());
let mut reader = MemReader::new(vec!(0, 1, 2, 3, 4, 5, 6, 7));
assert_eq!(reader.read_until(3).unwrap(), vec!(0, 1, 2, 3));
assert_eq!(reader.read_until(3).unwrap(), vec!(4, 5, 6, 7));
assert_eq!(reader.read_until(3).unwrap(), [0, 1, 2, 3]);
assert_eq!(reader.read_until(3).unwrap(), [4, 5, 6, 7]);
assert!(reader.read(&mut buf).is_err());
}
@ -530,8 +530,8 @@ mod test {
assert_eq!(&buf[..3], b);
assert!(reader.read(&mut buf).is_err());
let mut reader = &mut &*in_buf;
assert_eq!(reader.read_until(3).unwrap(), vec!(0, 1, 2, 3));
assert_eq!(reader.read_until(3).unwrap(), vec!(4, 5, 6, 7));
assert_eq!(reader.read_until(3).unwrap(), [0, 1, 2, 3]);
assert_eq!(reader.read_until(3).unwrap(), [4, 5, 6, 7]);
assert!(reader.read(&mut buf).is_err());
}
@ -557,8 +557,8 @@ mod test {
assert_eq!(&buf[..3], b);
assert!(reader.read(&mut buf).is_err());
let mut reader = BufReader::new(&in_buf);
assert_eq!(reader.read_until(3).unwrap(), vec!(0, 1, 2, 3));
assert_eq!(reader.read_until(3).unwrap(), vec!(4, 5, 6, 7));
assert_eq!(reader.read_until(3).unwrap(), [0, 1, 2, 3]);
assert_eq!(reader.read_until(3).unwrap(), [4, 5, 6, 7]);
assert!(reader.read(&mut buf).is_err());
}

View File

@ -87,7 +87,7 @@ mod test {
let mut writer: old_io::IoResult<Vec<u8>> = Ok(Vec::new());
writer.write_all(&[0, 1, 2]).unwrap();
writer.flush().unwrap();
assert_eq!(writer.unwrap(), vec!(0, 1, 2));
assert_eq!(writer.unwrap(), [0, 1, 2]);
}
#[test]

View File

@ -284,7 +284,7 @@ mod test {
let mut r = MemReader::new(vec!(0, 1, 2));
{
let mut r = LimitReader::new(r.by_ref(), 4);
assert_eq!(vec!(0, 1, 2), r.read_to_end().unwrap());
assert_eq!([0, 1, 2], r.read_to_end().unwrap());
}
}
@ -293,9 +293,9 @@ mod test {
let mut r = MemReader::new(vec!(0, 1, 2));
{
let mut r = LimitReader::new(r.by_ref(), 2);
assert_eq!(vec!(0, 1), r.read_to_end().unwrap());
assert_eq!([0, 1], r.read_to_end().unwrap());
}
assert_eq!(vec!(2), r.read_to_end().unwrap());
assert_eq!([2], r.read_to_end().unwrap());
}
#[test]
@ -305,7 +305,7 @@ mod test {
assert_eq!(3, r.limit());
assert_eq!(0, r.read_byte().unwrap());
assert_eq!(2, r.limit());
assert_eq!(vec!(1, 2), r.read_to_end().unwrap());
assert_eq!([1, 2], r.read_to_end().unwrap());
assert_eq!(0, r.limit());
}
@ -314,7 +314,7 @@ mod test {
let mut r = MemReader::new(vec![0, 1, 2, 3, 4, 5]);
let mut r = LimitReader::new(r.by_ref(), 1);
r.consume(2);
assert_eq!(vec![], r.read_to_end().unwrap());
assert_eq!([], r.read_to_end().unwrap());
}
#[test]
@ -330,7 +330,7 @@ mod test {
let mut s = ZeroReader;
let mut buf = vec![1, 2, 3];
assert_eq!(s.read(&mut buf), Ok(3));
assert_eq!(vec![0, 0, 0], buf);
assert_eq!([0, 0, 0], buf);
}
#[test]
@ -373,16 +373,16 @@ mod test {
let rs = vec!(MemReader::new(vec!(0, 1)), MemReader::new(vec!()),
MemReader::new(vec!(2, 3)));
let mut r = ChainedReader::new(rs.into_iter());
assert_eq!(vec!(0, 1, 2, 3), r.read_to_end().unwrap());
assert_eq!([0, 1, 2, 3], r.read_to_end().unwrap());
}
#[test]
fn test_tee_reader() {
let mut r = TeeReader::new(MemReader::new(vec!(0, 1, 2)),
Vec::new());
assert_eq!(vec!(0, 1, 2), r.read_to_end().unwrap());
assert_eq!([0, 1, 2], r.read_to_end().unwrap());
let (_, w) = r.into_inner();
assert_eq!(vec!(0, 1, 2), w);
assert_eq!([0, 1, 2], w);
}
#[test]
@ -390,7 +390,7 @@ mod test {
let mut r = MemReader::new(vec!(0, 1, 2, 3, 4));
let mut w = Vec::new();
copy(&mut r, &mut w).unwrap();
assert_eq!(vec!(0, 1, 2, 3, 4), w);
assert_eq!([0, 1, 2, 3, 4], w);
}
#[test]

View File

@ -1202,11 +1202,11 @@ mod tests {
string.code_points().map(|c| c.to_char()).collect::<Vec<_>>()
}
let mut string = Wtf8Buf::from_str("é ");
assert_eq!(cp(&string), vec![Some('é'), Some(' ')]);
assert_eq!(cp(&string), [Some('é'), Some(' ')]);
string.push(c(0xD83D));
assert_eq!(cp(&string), vec![Some('é'), Some(' '), None]);
assert_eq!(cp(&string), [Some('é'), Some(' '), None]);
string.push(c(0xDCA9));
assert_eq!(cp(&string), vec![Some('é'), Some(' '), Some('💩')]);
assert_eq!(cp(&string), [Some('é'), Some(' '), Some('💩')]);
}
#[test]

View File

@ -2028,7 +2028,7 @@ foo_module!();
let renamed_crate = renamer.fold_crate(the_crate);
let idents = crate_idents(&renamed_crate);
let resolved : Vec<ast::Name> = idents.iter().map(|id| mtwt::resolve(*id)).collect();
assert_eq!(resolved,vec!(f_ident.name,Name(16),int_ident.name,Name(16),Name(16),Name(16)));
assert_eq!(resolved, [f_ident.name,Name(16),int_ident.name,Name(16),Name(16),Name(16)]);
}
// test the PatIdentRenamer; only PatIdents get renamed
@ -2044,8 +2044,6 @@ foo_module!();
let idents = crate_idents(&renamed_crate);
let resolved : Vec<ast::Name> = idents.iter().map(|id| mtwt::resolve(*id)).collect();
let x_name = x_ident.name;
assert_eq!(resolved,vec!(f_ident.name,Name(16),int_ident.name,Name(16),x_name,x_name));
assert_eq!(resolved, [f_ident.name,Name(16),int_ident.name,Name(16),x_name,x_name]);
}
}

View File

@ -288,19 +288,19 @@ mod tests {
fn xorpush_test () {
let mut s = Vec::new();
xor_push(&mut s, 14);
assert_eq!(s.clone(), vec!(14));
assert_eq!(s.clone(), [14]);
xor_push(&mut s, 14);
assert_eq!(s.clone(), Vec::new());
assert_eq!(s.clone(), []);
xor_push(&mut s, 14);
assert_eq!(s.clone(), vec!(14));
assert_eq!(s.clone(), [14]);
xor_push(&mut s, 15);
assert_eq!(s.clone(), vec!(14, 15));
assert_eq!(s.clone(), [14, 15]);
xor_push(&mut s, 16);
assert_eq!(s.clone(), vec!(14, 15, 16));
assert_eq!(s.clone(), [14, 15, 16]);
xor_push(&mut s, 16);
assert_eq!(s.clone(), vec!(14, 15));
assert_eq!(s.clone(), [14, 15]);
xor_push(&mut s, 15);
assert_eq!(s.clone(), vec!(14));
assert_eq!(s.clone(), [14]);
}
fn id(n: u32, s: SyntaxContext) -> Ident {
@ -389,13 +389,13 @@ mod tests {
assert_eq!(marksof_internal (EMPTY_CTXT,stopname,&t),Vec::new());
// FIXME #5074: ANF'd to dodge nested calls
{ let ans = unfold_marks(vec!(4,98),EMPTY_CTXT,&mut t);
assert_eq! (marksof_internal (ans,stopname,&t),vec!(4,98));}
assert_eq! (marksof_internal (ans,stopname,&t), [4, 98]);}
// does xoring work?
{ let ans = unfold_marks(vec!(5,5,16),EMPTY_CTXT,&mut t);
assert_eq! (marksof_internal (ans,stopname,&t), vec!(16));}
assert_eq! (marksof_internal (ans,stopname,&t), [16]);}
// does nested xoring work?
{ let ans = unfold_marks(vec!(5,10,10,5,16),EMPTY_CTXT,&mut t);
assert_eq! (marksof_internal (ans, stopname,&t), vec!(16));}
assert_eq! (marksof_internal (ans, stopname,&t), [16]);}
// rename where stop doesn't match:
{ let chain = vec!(M(9),
R(id(name1.usize() as u32,
@ -403,7 +403,7 @@ mod tests {
Name(100101102)),
M(14));
let ans = unfold_test_sc(chain,EMPTY_CTXT,&mut t);
assert_eq! (marksof_internal (ans, stopname, &t), vec!(9,14));}
assert_eq! (marksof_internal (ans, stopname, &t), [9, 14]);}
// rename where stop does match
{ let name1sc = apply_mark_internal(4, EMPTY_CTXT, &mut t);
let chain = vec!(M(9),
@ -411,7 +411,7 @@ mod tests {
stopname),
M(14));
let ans = unfold_test_sc(chain,EMPTY_CTXT,&mut t);
assert_eq! (marksof_internal (ans, stopname, &t), vec!(9)); }
assert_eq! (marksof_internal (ans, stopname, &t), [9]); }
}

View File

@ -229,10 +229,10 @@ mod test {
assert_eq!(Vec::new(), v);
let v = SmallVector::one(1);
assert_eq!(vec![1], v.into_iter().collect::<Vec<_>>());
assert_eq!([1], v.into_iter().collect::<Vec<_>>());
let v = SmallVector::many(vec![1, 2, 3]);
assert_eq!(vec!(1, 2, 3), v.into_iter().collect::<Vec<_>>());
assert_eq!([1, 2, 3], v.into_iter().collect::<Vec<_>>());
}
#[test]

View File

@ -652,15 +652,15 @@ mod test {
let s = format!("%{{1}}%{{2}}%{}%d", op);
let res = expand(s.as_bytes(), &[], &mut Variables::new());
assert!(res.is_ok(), res.err().unwrap());
assert_eq!(res.unwrap(), vec!(b'0' + bs[0]));
assert_eq!(res.unwrap(), [b'0' + bs[0]]);
let s = format!("%{{1}}%{{1}}%{}%d", op);
let res = expand(s.as_bytes(), &[], &mut Variables::new());
assert!(res.is_ok(), res.err().unwrap());
assert_eq!(res.unwrap(), vec!(b'0' + bs[1]));
assert_eq!(res.unwrap(), [b'0' + bs[1]]);
let s = format!("%{{2}}%{{1}}%{}%d", op);
let res = expand(s.as_bytes(), &[], &mut Variables::new());
assert!(res.is_ok(), res.err().unwrap());
assert_eq!(res.unwrap(), vec!(b'0' + bs[2]));
assert_eq!(res.unwrap(), [b'0' + bs[2]]);
}
}

View File

@ -23,5 +23,5 @@ pub fn main() {
let mut v = vec!(1);
v.push_val(2);
v.push_val(3);
assert_eq!(v, vec!(1, 2, 3));
assert_eq!(v, [1, 2, 3]);
}

View File

@ -22,5 +22,5 @@ fn bar(v: &mut [uint]) {
pub fn main() {
let mut the_vec = vec!(1, 2, 3, 100);
bar(&mut the_vec);
assert_eq!(the_vec, vec!(100, 3, 2, 1));
assert_eq!(the_vec, [100, 3, 2, 1]);
}

View File

@ -18,5 +18,5 @@ fn bar(v: &mut [uint]) {
pub fn main() {
let mut the_vec = vec!(1, 2, 3, 100);
bar(&mut the_vec);
assert_eq!(the_vec, vec!(100, 3, 2, 1));
assert_eq!(the_vec, [100, 3, 2, 1]);
}

View File

@ -24,5 +24,5 @@ impl<T> vec_utils<T> for Vec<T> {
}
pub fn main() {
assert_eq!(vec_utils::map_(&vec!(1,2,3), |&x| x+1), vec!(2,3,4));
assert_eq!(vec_utils::map_(&vec!(1,2,3), |&x| x+1), [2,3,4]);
}

View File

@ -44,11 +44,11 @@ fn transform(x: Option<int>) -> Option<String> {
pub fn main() {
assert_eq!(transform(Some(10)), Some("11".to_string()));
assert_eq!(transform(None), None);
assert!((vec!("hi".to_string()))
assert_eq!((vec!("hi".to_string()))
.bind(|x| vec!(x.clone(), format!("{}!", x)) )
.bind(|x| vec!(x.clone(), format!("{}?", x)) ) ==
vec!("hi".to_string(),
"hi?".to_string(),
"hi!".to_string(),
"hi!?".to_string()));
.bind(|x| vec!(x.clone(), format!("{}?", x)) ),
["hi".to_string(),
"hi?".to_string(),
"hi!".to_string(),
"hi!?".to_string()]);
}

View File

@ -44,9 +44,9 @@ fn bar<U:to_str,T:map<U>>(x: T) -> Vec<String> {
}
pub fn main() {
assert_eq!(foo(vec!(1)), vec!("hi".to_string()));
assert_eq!(bar::<int, Vec<int> >(vec!(4, 5)), vec!("4".to_string(), "5".to_string()));
assert_eq!(foo(vec!(1)), ["hi".to_string()]);
assert_eq!(bar::<int, Vec<int> >(vec!(4, 5)), ["4".to_string(), "5".to_string()]);
assert_eq!(bar::<String, Vec<String> >(vec!("x".to_string(), "y".to_string())),
vec!("x".to_string(), "y".to_string()));
assert_eq!(bar::<(), Vec<()>>(vec!(())), vec!("()".to_string()));
["x".to_string(), "y".to_string()]);
assert_eq!(bar::<(), Vec<()>>(vec!(())), ["()".to_string()]);
}

View File

@ -18,5 +18,5 @@ fn f<F: FnMut()>(mut f: F) {
fn main() {
let mut v: Vec<_> = vec![];
f(|| v.push(0));
assert_eq!(v, vec![0]);
assert_eq!(v, [0]);
}