]>
Commit | Line | Data |
---|---|---|
74b04a01 XL |
1 | // Test bindings-after-at with or-patterns and slice-patterns |
2 | ||
3 | // run-pass | |
4 | ||
74b04a01 XL |
5 | |
6 | #[derive(Debug, PartialEq)] | |
7 | enum MatchArm { | |
8 | Arm(usize), | |
9 | Wild, | |
10 | } | |
11 | ||
12 | #[derive(Debug, PartialEq)] | |
13 | enum Test { | |
14 | Foo, | |
15 | Bar, | |
16 | Baz, | |
17 | Qux, | |
18 | } | |
19 | ||
20 | fn test(foo: &[Option<Test>]) -> MatchArm { | |
21 | match foo { | |
22 | bar @ [Some(Test::Foo), .., Some(Test::Qux | Test::Foo)] => { | |
23 | assert_eq!(bar, foo); | |
24 | ||
25 | MatchArm::Arm(0) | |
26 | }, | |
27 | [.., bar @ Some(Test::Bar | Test::Qux), _] => { | |
28 | assert!(bar == &Some(Test::Bar) || bar == &Some(Test::Qux)); | |
29 | ||
30 | MatchArm::Arm(1) | |
31 | }, | |
32 | _ => MatchArm::Wild, | |
33 | } | |
34 | } | |
35 | ||
36 | fn main() { | |
37 | let foo = vec![ | |
38 | Some(Test::Foo), | |
39 | Some(Test::Bar), | |
40 | Some(Test::Baz), | |
41 | Some(Test::Qux), | |
42 | ]; | |
43 | ||
44 | // path 1a | |
45 | assert_eq!(test(&foo), MatchArm::Arm(0)); | |
46 | // path 1b | |
47 | assert_eq!(test(&[Some(Test::Foo), Some(Test::Bar), Some(Test::Foo)]), MatchArm::Arm(0)); | |
48 | // path 2a | |
49 | assert_eq!(test(&foo[..3]), MatchArm::Arm(1)); | |
50 | // path 2b | |
51 | assert_eq!(test(&[Some(Test::Bar), Some(Test::Qux), Some(Test::Baz)]), MatchArm::Arm(1)); | |
52 | // path 3 | |
53 | assert_eq!(test(&foo[1..2]), MatchArm::Wild); | |
54 | } |