]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass/vec-matching.rs
Imported Upstream version 1.0.0~beta.3
[rustc.git] / src / test / run-pass / vec-matching.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11
12 #![feature(advanced_slice_patterns)]
13 #![feature(slice_patterns)]
14
15 fn a() {
16 let x = [1];
17 match x {
18 [a] => {
19 assert_eq!(a, 1);
20 }
21 }
22 }
23
24 fn b() {
25 let x = [1, 2, 3];
26 match x {
27 [a, b, c..] => {
28 assert_eq!(a, 1);
29 assert_eq!(b, 2);
30 let expected: &[_] = &[3];
31 assert_eq!(c, expected);
32 }
33 }
34 match x {
35 [a.., b, c] => {
36 let expected: &[_] = &[1];
37 assert_eq!(a, expected);
38 assert_eq!(b, 2);
39 assert_eq!(c, 3);
40 }
41 }
42 match x {
43 [a, b.., c] => {
44 assert_eq!(a, 1);
45 let expected: &[_] = &[2];
46 assert_eq!(b, expected);
47 assert_eq!(c, 3);
48 }
49 }
50 match x {
51 [a, b, c] => {
52 assert_eq!(a, 1);
53 assert_eq!(b, 2);
54 assert_eq!(c, 3);
55 }
56 }
57 }
58
59 fn c() {
60 let x = [1];
61 match x {
62 [2, ..] => panic!(),
63 [..] => ()
64 }
65 }
66
67 fn d() {
68 let x = [1, 2, 3];
69 let branch = match x {
70 [1, 1, ..] => 0,
71 [1, 2, 3, ..] => 1,
72 [1, 2, ..] => 2,
73 _ => 3
74 };
75 assert_eq!(branch, 1);
76 }
77
78 fn e() {
79 let x: &[isize] = &[1, 2, 3];
80 match x {
81 [1, 2] => (),
82 [..] => ()
83 }
84 }
85
86 pub fn main() {
87 a();
88 b();
89 c();
90 d();
91 e();
92 }