Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
2807a1ce
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2807a1ce
编写于
2月 24, 2015
作者:
V
Vadim Petrochenkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use arrays instead of vectors in tests
上级
dccdde40
变更
41
隐藏空白更改
内联
并排
Showing
41 changed file
with
254 addition
and
267 deletion
+254
-267
src/doc/trpl/macros.md
src/doc/trpl/macros.md
+1
-1
src/libcollections/binary_heap.rs
src/libcollections/binary_heap.rs
+1
-1
src/libcollections/bit.rs
src/libcollections/bit.rs
+6
-6
src/libcollections/btree/map.rs
src/libcollections/btree/map.rs
+2
-2
src/libcollections/btree/set.rs
src/libcollections/btree/set.rs
+10
-10
src/libcollections/enum_set.rs
src/libcollections/enum_set.rs
+11
-11
src/libcollections/linked_list.rs
src/libcollections/linked_list.rs
+2
-2
src/libcollections/macros.rs
src/libcollections/macros.rs
+1
-1
src/libcollections/slice.rs
src/libcollections/slice.rs
+20
-20
src/libcollections/str.rs
src/libcollections/str.rs
+35
-35
src/libcollections/string.rs
src/libcollections/string.rs
+3
-3
src/libcollections/vec.rs
src/libcollections/vec.rs
+31
-31
src/libcollections/vec_deque.rs
src/libcollections/vec_deque.rs
+7
-7
src/libcollections/vec_map.rs
src/libcollections/vec_map.rs
+3
-3
src/libcore/iter.rs
src/libcore/iter.rs
+2
-2
src/libcore/option.rs
src/libcore/option.rs
+1
-1
src/libcore/result.rs
src/libcore/result.rs
+2
-2
src/libcoretest/iter.rs
src/libcoretest/iter.rs
+21
-32
src/libcoretest/mem.rs
src/libcoretest/mem.rs
+1
-1
src/libcoretest/nonzero.rs
src/libcoretest/nonzero.rs
+1
-1
src/libcoretest/ptr.rs
src/libcoretest/ptr.rs
+1
-1
src/libcoretest/str.rs
src/libcoretest/str.rs
+16
-16
src/librbml/io.rs
src/librbml/io.rs
+1
-1
src/librustc_driver/test.rs
src/librustc_driver/test.rs
+5
-5
src/libserialize/json.rs
src/libserialize/json.rs
+5
-5
src/libstd/old_io/extensions.rs
src/libstd/old_io/extensions.rs
+8
-8
src/libstd/old_io/mem.rs
src/libstd/old_io/mem.rs
+9
-9
src/libstd/old_io/result.rs
src/libstd/old_io/result.rs
+1
-1
src/libstd/old_io/util.rs
src/libstd/old_io/util.rs
+10
-10
src/libstd/sys/common/wtf8.rs
src/libstd/sys/common/wtf8.rs
+3
-3
src/libsyntax/ext/expand.rs
src/libsyntax/ext/expand.rs
+2
-4
src/libsyntax/ext/mtwt.rs
src/libsyntax/ext/mtwt.rs
+12
-12
src/libsyntax/util/small_vector.rs
src/libsyntax/util/small_vector.rs
+2
-2
src/libterm/terminfo/parm.rs
src/libterm/terminfo/parm.rs
+3
-3
src/test/run-pass/auto-ref-sliceable.rs
src/test/run-pass/auto-ref-sliceable.rs
+1
-1
src/test/run-pass/coerce-reborrow-mut-vec-arg.rs
src/test/run-pass/coerce-reborrow-mut-vec-arg.rs
+1
-1
src/test/run-pass/coerce-reborrow-mut-vec-rcvr.rs
src/test/run-pass/coerce-reborrow-mut-vec-rcvr.rs
+1
-1
src/test/run-pass/generic-static-methods.rs
src/test/run-pass/generic-static-methods.rs
+1
-1
src/test/run-pass/monad.rs
src/test/run-pass/monad.rs
+6
-6
src/test/run-pass/trait-generic.rs
src/test/run-pass/trait-generic.rs
+4
-4
src/test/run-pass/unboxed-closures-infer-upvar.rs
src/test/run-pass/unboxed-closures-infer-upvar.rs
+1
-1
未找到文件。
src/doc/trpl/macros.md
浏览文件 @
2807a1ce
...
...
@@ -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]);
# }
```
...
...
src/libcollections/binary_heap.rs
浏览文件 @
2807a1ce
...
...
@@ -480,7 +480,7 @@ pub fn into_vec(self) -> Vec<T> { self.data }
/// 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
();
...
...
src/libcollections/bit.rs
浏览文件 @
2807a1ce
...
...
@@ -640,13 +640,13 @@ pub fn any(&self) -> bool {
/// 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 @@ pub fn capacity(&self) -> usize {
/// 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 @@ fn test_from_bytes() {
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 @@ fn test_bit_set_iterator() {
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
();
...
...
src/libcollections/btree/map.rs
浏览文件 @
2807a1ce
...
...
@@ -1281,7 +1281,7 @@ pub fn into_iter(self) -> IntoIter<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 @@ fn first<A, B>((a, _): (A, B)) -> A { a }
/// 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
>
{
...
...
src/libcollections/btree/set.rs
浏览文件 @
2807a1ce
...
...
@@ -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 @@ pub fn iter(&self) -> Iter<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 @@ pub fn difference<'a>(&'a self, other: &'a BTreeSet<T>) -> Difference<'a, 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 @@ pub fn symmetric_difference<'a>(&'a self, other: &'a 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 @@ pub fn intersection<'a>(&'a self, other: &'a 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
()
...
...
src/libcollections/enum_set.rs
浏览文件 @
2807a1ce
...
...
@@ -428,19 +428,19 @@ fn test_iterator() {
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 @@ fn test_operators() {
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]
...
...
src/libcollections/linked_list.rs
浏览文件 @
2807a1ce
...
...
@@ -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 @@ fn test_insert_prev() {
}
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]
...
...
src/libcollections/macros.rs
浏览文件 @
2807a1ce
...
...
@@ -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
...
...
src/libcollections/slice.rs
浏览文件 @
2807a1ce
...
...
@@ -1779,10 +1779,10 @@ fn test_swap_remove() {
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 @@ fn test_dedup_shared() {
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 @@ fn test_concat() {
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!
[
1
i
],
vec!
[
2
,
3
]]
.connect
(
&
0
),
[
1
,
0
,
2
,
3
]);
assert_eq!
([
vec!
[
1
i
],
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 @@ fn test_remove() {
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]
...
...
src/libcollections/str.rs
浏览文件 @
2807a1ce
...
...
@@ -552,7 +552,7 @@ fn contains_char<'a, P: Pattern<'a>>(&'a self, pat: P) -> bool {
/// ```
/// 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 @@ fn char_indices(&self) -> CharIndices {
///
/// ```
/// 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 @@ fn split<'a, P: Pattern<'a>>(&'a self, pat: P) -> Split<'a, P> {
///
/// ```
/// 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 @@ fn splitn<'a, P: Pattern<'a>>(&'a self, count: usize, pat: P) -> SplitN<'a, P> {
///
/// ```
/// 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 @@ fn split_terminator<'a, P: Pattern<'a>>(&'a self, pat: P) -> SplitTerminator<'a,
///
/// ```
/// 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 @@ fn rsplitn<'a, P: Pattern<'a>>(&'a self, count: usize, pat: P) -> RSplitN<'a, P>
///
/// ```
/// 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 @@ fn match_indices<'a, P: Pattern<'a>>(&'a self, pat: P) -> MatchIndices<'a, P> {
///
/// ```
/// 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 @@ fn split_str<'a, P: Pattern<'a>>(&'a self, pat: P) -> SplitStr<'a, P> {
/// 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 @@ fn split_str<'a, P: Pattern<'a>>(&'a self, pat: P) -> SplitStr<'a, P> {
/// 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 @@ fn lines(&self) -> Lines {
/// 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 @@ fn lines(&self) -> Lines {
/// 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 @@ fn grapheme_indices(&self, is_extended: bool) -> GraphemeIndices {
/// 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 @@ fn test_splitn_char_iterator() {
let
data
=
"
\n
Märy häd ä little lämb
\n
Little lämb
\n
"
;
let
split
:
Vec
<&
str
>
=
data
.splitn
(
3
,
' '
)
.collect
();
assert_eq!
(
split
,
vec!
[
"
\n
Märy"
,
"häd"
,
"ä"
,
"little lämb
\n
Little lämb
\n
"
]);
assert_eq!
(
split
,
[
"
\n
Märy"
,
"häd"
,
"ä"
,
"little lämb
\n
Little lämb
\n
"
]);
let
split
:
Vec
<&
str
>
=
data
.splitn
(
3
,
|
c
:
char
|
c
==
' '
)
.collect
();
assert_eq!
(
split
,
vec!
[
"
\n
Märy"
,
"häd"
,
"ä"
,
"little lämb
\n
Little lämb
\n
"
]);
assert_eq!
(
split
,
[
"
\n
Märy"
,
"häd"
,
"ä"
,
"little lämb
\n
Little lämb
\n
"
]);
// Unicode
let
split
:
Vec
<&
str
>
=
data
.splitn
(
3
,
'ä'
)
.collect
();
assert_eq!
(
split
,
vec!
[
"
\n
M"
,
"ry h"
,
"d "
,
" little lämb
\n
Little lämb
\n
"
]);
assert_eq!
(
split
,
[
"
\n
M"
,
"ry h"
,
"d "
,
" little lämb
\n
Little lämb
\n
"
]);
let
split
:
Vec
<&
str
>
=
data
.splitn
(
3
,
|
c
:
char
|
c
==
'ä'
)
.collect
();
assert_eq!
(
split
,
vec!
[
"
\n
M"
,
"ry h"
,
"d "
,
" little lämb
\n
Little lämb
\n
"
]);
assert_eq!
(
split
,
[
"
\n
M"
,
"ry h"
,
"d "
,
" little lämb
\n
Little lämb
\n
"
]);
}
#[test]
...
...
@@ -2418,17 +2418,17 @@ fn test_split_char_iterator_no_trailing() {
let
data
=
"
\n
Märy häd ä little lämb
\n
Little 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
\t
Märy häd
\t
ä little lämb
\n
Little 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 @@ fn test_nfkc_chars() {
fn
test_lines
()
{
let
data
=
"
\n
Märy häd ä little lämb
\n\n
Little 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
=
"
\n
Märy häd ä little lämb
\n\n
Little 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]
...
...
src/libcollections/string.rs
浏览文件 @
2807a1ce
...
...
@@ -120,7 +120,7 @@ pub fn from_str(string: &str) -> 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 @@ pub unsafe fn from_utf8_unchecked(bytes: Vec<u8>) -> 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 @@ pub fn insert(&mut self, idx: usize, ch: char) {
/// 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");
...
...
src/libcollections/vec.rs
浏览文件 @
2807a1ce
...
...
@@ -93,7 +93,7 @@
/// 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 @@
/// ```
/// 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 @@ pub fn with_capacity(capacity: usize) -> 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 @@ pub fn into_boxed_slice(mut self) -> Box<[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 @@ pub unsafe fn set_len(&mut self, len: usize) {
/// 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 @@ pub fn swap_remove(&mut self, index: usize) -> 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 @@ pub fn insert(&mut self, index: usize, element: 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 @@ pub fn remove(&mut self, index: usize) -> 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 @@ pub fn retain<F>(&mut self, mut f: F) where F: FnMut(&T) -> bool {
/// ```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 @@ pub fn push(&mut self, value: 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 @@ pub fn pop(&mut self) -> Option<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 @@ pub fn map_in_place<U, F>(self, mut f: F) -> Vec<U> where F: FnMut(T) -> U {
/// ```
/// 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 @@ pub fn resize(&mut self, new_len: usize, value: 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 @@ fn test_split_at_mut() {
}
}
assert
!
(
values
==
vec!
[
2
,
3
,
5
,
6
,
7
]);
assert
_eq!
(
values
,
[
2
,
3
,
5
,
6
,
7
]);
}
#[test]
...
...
@@ -2147,7 +2147,7 @@ fn test_clone_from() {
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 @@ fn test_unsafe_ptrs() {
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 @@ fn test_move_items() {
for
i
in
vec
{
vec2
.push
(
i
);
}
assert
!
(
vec2
==
vec!
[
1
,
2
,
3
]);
assert
_eq!
(
vec2
,
[
1
,
2
,
3
]);
}
#[test]
...
...
@@ -2385,7 +2385,7 @@ fn test_move_items_reverse() {
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 @@ fn test_move_items_zero_sized() {
for
i
in
vec
{
vec2
.push
(
i
);
}
assert
!
(
vec2
==
vec!
[(),
(),
()]);
assert
_eq!
(
vec2
,
[(),
(),
()]);
}
#[test]
...
...
@@ -2443,16 +2443,16 @@ fn test_append() {
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]
...
...
src/libcollections/vec_deque.rs
浏览文件 @
2807a1ce
...
...
@@ -2105,7 +2105,7 @@ fn test_swap() {
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 @@ fn test_append() {
// 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
(),
[
1
,
2
,
3
,
4
,
5
,
6
]);
assert_eq!
(
b
.iter
()
.cloned
()
.collect
(),
[]);
// 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
(),
[
1
,
2
,
3
,
4
,
5
,
6
]);
assert_eq!
(
b
.iter
()
.cloned
()
.collect
(),
[]);
// 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
(),
[
1
,
2
,
3
,
4
,
5
,
6
]);
assert_eq!
(
a
.iter
()
.cloned
()
.collect
(),
[]);
}
}
src/libcollections/vec_map.rs
浏览文件 @
2807a1ce
...
...
@@ -308,7 +308,7 @@ pub fn iter_mut<'r>(&'r mut self) -> IterMut<'r, 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 @@ pub fn split_off(&mut self, at: usize) -> Self {
///
/// 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 @@ fn test_drain_iterator() {
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
);
}
...
...
src/libcore/iter.rs
浏览文件 @
2807a1ce
...
...
@@ -582,8 +582,8 @@ fn collect<B: FromIterator<Self::Item>>(self) -> B {
/// ```
/// 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"
)]
...
...
src/libcore/option.rs
浏览文件 @
2807a1ce
...
...
@@ -556,7 +556,7 @@ pub fn iter_mut(&mut self) -> IterMut<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();
...
...
src/libcore/result.rs
浏览文件 @
2807a1ce
...
...
@@ -548,11 +548,11 @@ pub fn iter_mut(&mut self) -> IterMut<T> {
/// ```
/// 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"
)]
...
...
src/libcoretest/iter.rs
浏览文件 @
2807a1ce
...
...
@@ -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
(
200
i
,
-
5
,
1
)
.collect
::
<
Vec
<
int
>>
(),
[]);
assert_eq!
(
range_step
(
200
i
,
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]
...
...
src/libcoretest/mem.rs
浏览文件 @
2807a1ce
...
...
@@ -103,7 +103,7 @@ impl Foo for int {}
}
unsafe
{
assert
!
(
vec!
[
76u8
]
==
transmute
::
<
_
,
Vec
<
u8
>>
(
"L"
.to_string
()));
assert
_eq!
([
76u8
],
transmute
::
<
_
,
Vec
<
u8
>>
(
"L"
.to_string
()));
}
}
...
...
src/libcoretest/nonzero.rs
浏览文件 @
2807a1ce
...
...
@@ -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])"
)
}
}
...
...
src/libcoretest/ptr.rs
浏览文件 @
2807a1ce
...
...
@@ -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
]);
}
}
...
...
src/libcoretest/str.rs
浏览文件 @
2807a1ce
...
...
@@ -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!
[
"
\n
Märy häd ä"
,
"little"
,
"lämb
\n
Little"
,
"lämb
\n
"
]);
assert_eq!
(
split
,
[
"
\n
Märy häd ä"
,
"little"
,
"lämb
\n
Little"
,
"lämb
\n
"
]);
let
mut
split
:
Vec
<&
str
>
=
data
.rsplitn
(
3
,
|
c
:
char
|
c
==
' '
)
.collect
();
split
.reverse
();
assert_eq!
(
split
,
vec!
[
"
\n
Märy häd ä"
,
"little"
,
"lämb
\n
Little"
,
"lämb
\n
"
]);
assert_eq!
(
split
,
[
"
\n
Märy häd ä"
,
"little"
,
"lämb
\n
Little"
,
"lämb
\n
"
]);
// Unicode
let
mut
split
:
Vec
<&
str
>
=
data
.rsplitn
(
3
,
'ä'
)
.collect
();
split
.reverse
();
assert_eq!
(
split
,
vec!
[
"
\n
Märy häd "
,
" little l"
,
"mb
\n
Little l"
,
"mb
\n
"
]);
assert_eq!
(
split
,
[
"
\n
Märy häd "
,
" little l"
,
"mb
\n
Little l"
,
"mb
\n
"
]);
let
mut
split
:
Vec
<&
str
>
=
data
.rsplitn
(
3
,
|
c
:
char
|
c
==
'ä'
)
.collect
();
split
.reverse
();
assert_eq!
(
split
,
vec!
[
"
\n
Märy häd "
,
" little l"
,
"mb
\n
Little l"
,
"mb
\n
"
]);
assert_eq!
(
split
,
[
"
\n
Märy häd "
,
" little l"
,
"mb
\n
Little l"
,
"mb
\n
"
]);
}
#[test]
...
...
@@ -90,33 +90,33 @@ fn test_split_char_iterator() {
let
data
=
"
\n
Märy häd ä little lämb
\n
Little lämb
\n
"
;
let
split
:
Vec
<&
str
>
=
data
.split
(
' '
)
.collect
();
assert_eq!
(
split
,
vec!
[
"
\n
Märy"
,
"häd"
,
"ä"
,
"little"
,
"lämb
\n
Little"
,
"lämb
\n
"
]);
assert_eq!
(
split
,
[
"
\n
Märy"
,
"häd"
,
"ä"
,
"little"
,
"lämb
\n
Little"
,
"lämb
\n
"
]);
let
mut
rsplit
:
Vec
<&
str
>
=
data
.split
(
' '
)
.rev
()
.collect
();
rsplit
.reverse
();
assert_eq!
(
rsplit
,
vec!
[
"
\n
Märy"
,
"häd"
,
"ä"
,
"little"
,
"lämb
\n
Little"
,
"lämb
\n
"
]);
assert_eq!
(
rsplit
,
[
"
\n
Märy"
,
"häd"
,
"ä"
,
"little"
,
"lämb
\n
Little"
,
"lämb
\n
"
]);
let
split
:
Vec
<&
str
>
=
data
.split
(|
c
:
char
|
c
==
' '
)
.collect
();
assert_eq!
(
split
,
vec!
[
"
\n
Märy"
,
"häd"
,
"ä"
,
"little"
,
"lämb
\n
Little"
,
"lämb
\n
"
]);
assert_eq!
(
split
,
[
"
\n
Märy"
,
"häd"
,
"ä"
,
"little"
,
"lämb
\n
Little"
,
"lämb
\n
"
]);
let
mut
rsplit
:
Vec
<&
str
>
=
data
.split
(|
c
:
char
|
c
==
' '
)
.rev
()
.collect
();
rsplit
.reverse
();
assert_eq!
(
rsplit
,
vec!
[
"
\n
Märy"
,
"häd"
,
"ä"
,
"little"
,
"lämb
\n
Little"
,
"lämb
\n
"
]);
assert_eq!
(
rsplit
,
[
"
\n
Märy"
,
"häd"
,
"ä"
,
"little"
,
"lämb
\n
Little"
,
"lämb
\n
"
]);
// Unicode
let
split
:
Vec
<&
str
>
=
data
.split
(
'ä'
)
.collect
();
assert_eq!
(
split
,
vec!
[
"
\n
M"
,
"ry h"
,
"d "
,
" little l"
,
"mb
\n
Little l"
,
"mb
\n
"
]);
assert_eq!
(
split
,
[
"
\n
M"
,
"ry h"
,
"d "
,
" little l"
,
"mb
\n
Little l"
,
"mb
\n
"
]);
let
mut
rsplit
:
Vec
<&
str
>
=
data
.split
(
'ä'
)
.rev
()
.collect
();
rsplit
.reverse
();
assert_eq!
(
rsplit
,
vec!
[
"
\n
M"
,
"ry h"
,
"d "
,
" little l"
,
"mb
\n
Little l"
,
"mb
\n
"
]);
assert_eq!
(
rsplit
,
[
"
\n
M"
,
"ry h"
,
"d "
,
" little l"
,
"mb
\n
Little l"
,
"mb
\n
"
]);
let
split
:
Vec
<&
str
>
=
data
.split
(|
c
:
char
|
c
==
'ä'
)
.collect
();
assert_eq!
(
split
,
vec!
[
"
\n
M"
,
"ry h"
,
"d "
,
" little l"
,
"mb
\n
Little l"
,
"mb
\n
"
]);
assert_eq!
(
split
,
[
"
\n
M"
,
"ry h"
,
"d "
,
" little l"
,
"mb
\n
Little l"
,
"mb
\n
"
]);
let
mut
rsplit
:
Vec
<&
str
>
=
data
.split
(|
c
:
char
|
c
==
'ä'
)
.rev
()
.collect
();
rsplit
.reverse
();
assert_eq!
(
rsplit
,
vec!
[
"
\n
M"
,
"ry h"
,
"d "
,
" little l"
,
"mb
\n
Little l"
,
"mb
\n
"
]);
assert_eq!
(
rsplit
,
[
"
\n
M"
,
"ry h"
,
"d "
,
" little l"
,
"mb
\n
Little 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
{
1
F4A9
}
'
]
.into_iter
())
.collect
::
<
Vec
<
u16
>>
(),
vec!
[
0xE9
,
0xD83D
,
0xDCA9
])
[
0xE9
,
0xD83D
,
0xDCA9
])
}
#[test]
...
...
src/librbml/io.rs
浏览文件 @
2807a1ce
...
...
@@ -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
>
,
...
...
src/librustc_driver/test.rs
浏览文件 @
2807a1ce
...
...
@@ -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
);
})
}
...
...
src/libserialize/json.rs
浏览文件 @
2807a1ce
...
...
@@ -3074,19 +3074,19 @@ fn test_read_array() {
#[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]
...
...
src/libstd/old_io/extensions.rs
浏览文件 @
2807a1ce
...
...
@@ -328,7 +328,7 @@ fn bytes_error() {
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 @@ fn read_bytes_partial() {
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 @@ fn push_at_least() {
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 @@ fn push_at_least_partial() {
};
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 @@ fn push_at_least_eof() {
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 @@ fn push_at_least_error() {
};
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 @@ fn read_to_end() {
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 @@ fn read_to_end_error() {
count
:
0
,
};
let
buf
=
reader
.read_to_end
()
.unwrap
();
assert
!
(
buf
==
vec!
(
10
,
11
)
);
assert
_eq!
(
buf
,
[
10
,
11
]
);
}
#[test]
...
...
src/libstd/old_io/mem.rs
浏览文件 @
2807a1ce
...
...
@@ -60,7 +60,7 @@ fn write_all(&mut self, buf: &[u8]) -> IoResult<()> {
/// 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 @@ fn write_all(&mut self, buf: &[u8]) -> IoResult<()> {
///
/// 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 @@ fn seek(&mut self, pos: i64, style: SeekStyle) -> IoResult<()> {
/// 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 @@ fn test_mem_reader() {
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 @@ fn test_slice_reader() {
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 @@ fn test_buf_reader() {
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
());
}
...
...
src/libstd/old_io/result.rs
浏览文件 @
2807a1ce
...
...
@@ -87,7 +87,7 @@ fn test_option_writer() {
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]
...
...
src/libstd/old_io/util.rs
浏览文件 @
2807a1ce
...
...
@@ -284,7 +284,7 @@ fn test_limit_reader_unlimited() {
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 @@ fn test_limit_reader_limited() {
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 @@ fn test_limit_reader_limit() {
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 @@ fn test_limit_reader_overlong_consume() {
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 @@ fn test_zero_reader() {
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 @@ fn test_chained_reader() {
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 @@ fn test_copy() {
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]
...
...
src/libstd/sys/common/wtf8.rs
浏览文件 @
2807a1ce
...
...
@@ -1202,11 +1202,11 @@ fn cp(string: &Wtf8Buf) -> Vec<Option<char>> {
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]
...
...
src/libsyntax/ext/expand.rs
浏览文件 @
2807a1ce
...
...
@@ -2028,7 +2028,7 @@ fn ident_renamer_test () {
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 @@ fn pat_ident_renamer_test () {
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
]
);
}
}
src/libsyntax/ext/mtwt.rs
浏览文件 @
2807a1ce
...
...
@@ -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 @@ fn test_marksof () {
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 @@ fn test_marksof () {
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 @@ fn test_marksof () {
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
]
);
}
}
...
...
src/libsyntax/util/small_vector.rs
浏览文件 @
2807a1ce
...
...
@@ -229,10 +229,10 @@ fn test_move_iter() {
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]
...
...
src/libterm/terminfo/parm.rs
浏览文件 @
2807a1ce
...
...
@@ -652,15 +652,15 @@ fn test_comparison_ops() {
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
]]
);
}
}
...
...
src/test/run-pass/auto-ref-sliceable.rs
浏览文件 @
2807a1ce
...
...
@@ -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
]
);
}
src/test/run-pass/coerce-reborrow-mut-vec-arg.rs
浏览文件 @
2807a1ce
...
...
@@ -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
]
);
}
src/test/run-pass/coerce-reborrow-mut-vec-rcvr.rs
浏览文件 @
2807a1ce
...
...
@@ -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
]
);
}
src/test/run-pass/generic-static-methods.rs
浏览文件 @
2807a1ce
...
...
@@ -24,5 +24,5 @@ fn map_<U, F>(x: &Vec<T> , mut f: F) -> Vec<U> where F: FnMut(&T) -> U {
}
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
]
);
}
src/test/run-pass/monad.rs
浏览文件 @
2807a1ce
...
...
@@ -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
()]
);
}
src/test/run-pass/trait-generic.rs
浏览文件 @
2807a1ce
...
...
@@ -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
()]
);
}
src/test/run-pass/unboxed-closures-infer-upvar.rs
浏览文件 @
2807a1ce
...
...
@@ -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
]);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录