rust/src/test/run-pass/vec-matching.rs
Alex Crichton daf5f5a4d1 Drop the '2' suffix from logging macros
Who doesn't like a massive renaming?
2013-10-22 08:09:56 -07:00

76 lines
1.3 KiB
Rust

fn a() {
let x = ~[1];
match x {
[_, _, _, _, _, .._] => fail!(),
[.._, _, _, _, _] => fail!(),
[_, .._, _, _] => fail!(),
[_, _] => fail!(),
[a] => {
assert_eq!(a, 1);
}
[] => fail!()
}
}
fn b() {
let x = ~[1, 2, 3];
match x {
[a, b, ..c] => {
assert_eq!(a, 1);
assert_eq!(b, 2);
assert_eq!(c, &[3]);
}
_ => fail!()
}
match x {
[..a, b, c] => {
assert_eq!(a, &[1]);
assert_eq!(b, 2);
assert_eq!(c, 3);
}
_ => fail!()
}
match x {
[a, ..b, c] => {
assert_eq!(a, 1);
assert_eq!(b, &[2]);
assert_eq!(c, 3);
}
_ => fail!()
}
match x {
[a, b, c] => {
assert_eq!(a, 1);
assert_eq!(b, 2);
assert_eq!(c, 3);
}
_ => fail!()
}
}
fn c() {
let x = [1];
match x {
[2, .. _] => fail!(),
[.. _] => ()
}
}
fn d() {
let x = [1, 2, 3];
let branch = match x {
[1, 1, .. _] => 0,
[1, 2, 3, .. _] => 1,
[1, 2, .. _] => 2,
_ => 3
};
assert_eq!(branch, 1);
}
pub fn main() {
a();
b();
c();
d();
}