Add more tests
This commit is contained in:
parent
6530fd3401
commit
6c83fe4c24
4 changed files with 53 additions and 0 deletions
13
src/test/compile-fail/alt-vec-illegal-tail-element-loan.rs
Normal file
13
src/test/compile-fail/alt-vec-illegal-tail-element-loan.rs
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
fn a() -> &int {
|
||||||
|
let vec = [1, 2, 3, 4];
|
||||||
|
let tail = match vec {
|
||||||
|
[a, ..tail] => &tail[0], //~ ERROR illegal borrow
|
||||||
|
_ => fail ~"foo"
|
||||||
|
};
|
||||||
|
move tail
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let fifth = a();
|
||||||
|
io::println(fmt!("%d", *fifth));
|
||||||
|
}
|
8
src/test/compile-fail/alt-vec-tail-move.rs
Normal file
8
src/test/compile-fail/alt-vec-tail-move.rs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
fn main() {
|
||||||
|
let a = [mut 1, 2, 3, 4];
|
||||||
|
let _ = match a {
|
||||||
|
[1, 2, ..move tail] => tail,
|
||||||
|
_ => core::util::unreachable()
|
||||||
|
};
|
||||||
|
a[0] = 0; //~ ERROR: use of moved variable
|
||||||
|
}
|
22
src/test/run-pass/vec-matching-autoslice.rs
Normal file
22
src/test/run-pass/vec-matching-autoslice.rs
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
fn main() {
|
||||||
|
let x = @[1, 2, 3];
|
||||||
|
match x {
|
||||||
|
[2, .._] => core::util::unreachable(),
|
||||||
|
[1, ..tail] => {
|
||||||
|
assert tail == [2, 3];
|
||||||
|
}
|
||||||
|
[_] => core::util::unreachable(),
|
||||||
|
[] => core::util::unreachable()
|
||||||
|
}
|
||||||
|
|
||||||
|
let y = (~[(1, true), (2, false)], 0.5);
|
||||||
|
match y {
|
||||||
|
([_, _, _], 0.5) => core::util::unreachable(),
|
||||||
|
([(1, a), (b, false), ..tail], _) => {
|
||||||
|
assert a == true;
|
||||||
|
assert b == 2;
|
||||||
|
assert tail.is_empty();
|
||||||
|
}
|
||||||
|
([..tail], _) => core::util::unreachable()
|
||||||
|
}
|
||||||
|
}
|
10
src/test/run-pass/vec-matching-legal-tail-element-borrow.rs
Normal file
10
src/test/run-pass/vec-matching-legal-tail-element-borrow.rs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
fn main() {
|
||||||
|
let x = &[1, 2, 3, 4, 5];
|
||||||
|
if !x.is_empty() {
|
||||||
|
let el = match x {
|
||||||
|
[1, ..ref tail] => &tail[0],
|
||||||
|
_ => core::util::unreachable()
|
||||||
|
};
|
||||||
|
io::println(fmt!("%d", *el));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue