]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/vec-matching.rs
Merge branch 'match' of https://github.com/msullivan/rust into rollup
[rust.git] / src / test / run-pass / vec-matching.rs
1 fn a() {
2     let x = ~[1];
3     match x {
4         [_, _, _, _, _, .._] => fail!(),
5         [.._, _, _, _, _] => fail!(),
6         [_, .._, _, _] => fail!(),
7         [_, _] => fail!(),
8         [a] => {
9             assert_eq!(a, 1);
10         }
11         [] => fail!()
12     }
13 }
14
15 fn b() {
16     let x = ~[1, 2, 3];
17     match x {
18         [a, b, ..c] => {
19             assert_eq!(a, 1);
20             assert_eq!(b, 2);
21             assert_eq!(c, &[3]);
22         }
23         _ => fail!()
24     }
25     match x {
26         [..a, b, c] => {
27             assert_eq!(a, &[1]);
28             assert_eq!(b, 2);
29             assert_eq!(c, 3);
30         }
31         _ => fail!()
32     }
33     match x {
34         [a, ..b, c] => {
35             assert_eq!(a, 1);
36             assert_eq!(b, &[2]);
37             assert_eq!(c, 3);
38         }
39         _ => fail!()
40     }
41     match x {
42         [a, b, c] => {
43             assert_eq!(a, 1);
44             assert_eq!(b, 2);
45             assert_eq!(c, 3);
46         }
47         _ => fail!()
48     }
49 }
50
51 fn c() {
52     let x = [1];
53     match x {
54         [2, .. _] => fail!(),
55         [.. _] => ()
56     }
57 }
58
59 fn d() {
60     let x = [1, 2, 3];
61     let branch = match x {
62         [1, 1, .. _] => 0,
63         [1, 2, 3, .. _] => 1,
64         [1, 2, .. _] => 2,
65         _ => 3
66     };
67     assert_eq!(branch, 1);
68 }
69
70 pub fn main() {
71     a();
72     b();
73     c();
74     d();
75 }