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

36 lines
932 B
Rust
Raw Normal View History

struct Foo {
string: ~str
}
pub fn main() {
let x = ~[
Foo { string: ~"foo" },
Foo { string: ~"bar" },
Foo { string: ~"baz" }
];
match x {
[ref first, ..tail] => {
2013-03-28 20:39:09 -05:00
assert!(first.string == ~"foo");
assert_eq!(tail.len(), 2);
2013-03-28 20:39:09 -05:00
assert!(tail[0].string == ~"bar");
assert!(tail[1].string == ~"baz");
match tail {
2013-08-17 10:37:42 -05:00
[Foo { _ }, _, Foo { _ }, .. _tail] => {
::std::util::unreachable();
}
[Foo { string: ref a }, Foo { string: ref b }] => {
assert_eq!("bar", a.slice(0, a.len()));
assert_eq!("baz", b.slice(0, b.len()));
}
_ => {
::std::util::unreachable();
}
}
}
_ => {
::std::util::unreachable();
}
}
}