rust/src/test/run-pass/vec-matching.rs

55 lines
1.1 KiB
Rust
Raw Normal View History

fn a() {
let x = [1];
match x {
[_, _, _, _, _, .._] => ::core::util::unreachable(),
[.._, _, _, _, _] => ::core::util::unreachable(),
[_, .._, _, _] => ::core::util::unreachable(),
[_, _] => ::core::util::unreachable(),
[a] => {
2013-03-28 20:39:09 -05:00
assert!(a == 1);
}
[] => ::core::util::unreachable()
}
}
fn b() {
let x = [1, 2, 3];
match x {
[a, b, ..c] => {
2013-03-28 20:39:09 -05:00
assert!(a == 1);
assert!(b == 2);
assert!(c == &[3]);
}
_ => fail!()
}
match x {
[..a, b, c] => {
2013-03-28 20:39:09 -05:00
assert!(a == &[1]);
assert!(b == 2);
assert!(c == 3);
}
_ => fail!()
}
match x {
[a, ..b, c] => {
2013-03-28 20:39:09 -05:00
assert!(a == 1);
assert!(b == &[2]);
assert!(c == 3);
}
_ => fail!()
}
match x {
[a, b, c] => {
2013-03-28 20:39:09 -05:00
assert!(a == 1);
assert!(b == 2);
assert!(c == 3);
}
_ => fail!()
}
}
pub fn main() {
a();
b();
}