]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/match-pipe-binding.rs
cleanup: s/impl Copy/#[derive(Copy)]/g
[rust.git] / src / test / run-pass / match-pipe-binding.rs
1 // Copyright 2013 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 fn test1() {
12     // from issue 6338
13     match ((1i, "a".to_string()), (2i, "b".to_string())) {
14         ((1, a), (2, b)) | ((2, b), (1, a)) => {
15                 assert_eq!(a, "a".to_string());
16                 assert_eq!(b, "b".to_string());
17             },
18             _ => panic!(),
19     }
20 }
21
22 fn test2() {
23     match (1i, 2i, 3i) {
24         (1, a, b) | (2, b, a) => {
25             assert_eq!(a, 2);
26             assert_eq!(b, 3);
27         },
28         _ => panic!(),
29     }
30 }
31
32 fn test3() {
33     match (1i, 2i, 3i) {
34         (1, ref a, ref b) | (2, ref b, ref a) => {
35             assert_eq!(*a, 2);
36             assert_eq!(*b, 3);
37         },
38         _ => panic!(),
39     }
40 }
41
42 fn test4() {
43     match (1i, 2i, 3i) {
44         (1, a, b) | (2, b, a) if a == 2 => {
45             assert_eq!(a, 2);
46             assert_eq!(b, 3);
47         },
48         _ => panic!(),
49     }
50 }
51
52 fn test5() {
53     match (1i, 2i, 3i) {
54         (1, ref a, ref b) | (2, ref b, ref a) if *a == 2 => {
55             assert_eq!(*a, 2);
56             assert_eq!(*b, 3);
57         },
58         _ => panic!(),
59     }
60 }
61
62 pub fn main() {
63     test1();
64     test2();
65     test3();
66     test4();
67     test5();
68 }