Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub Wieczorek authored and graydon committed Dec 18, 2012
1 parent 6530fd3 commit 6c83fe4
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/test/compile-fail/alt-vec-illegal-tail-element-loan.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 8 additions & 0 deletions src/test/compile-fail/alt-vec-tail-move.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 22 additions & 0 deletions src/test/run-pass/vec-matching-autoslice.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 10 additions & 0 deletions src/test/run-pass/vec-matching-legal-tail-element-borrow.rs
Original file line number Diff line number Diff line change
@@ -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));
}
}

0 comments on commit 6c83fe4

Please sign in to comment.