1 // Copyright 2012-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.
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.
11 // Tests that match expression handles overlapped literal and range
12 // properly in the presence of guard function.
14 fn val() -> uint { 1 }
16 static CONST: uint = 1;
22 multi_pats_shadow_lit();
23 multi_pats_shadow_range();
24 lit_shadow_multi_pats();
25 range_shadow_multi_pats();
29 fn lit_shadow_range() {
30 assert_eq!(2, match 1 {
37 assert_eq!(2, match x+1 {
44 assert_eq!(2, match val() {
50 assert_eq!(2, match CONST {
57 // value is out of the range of second arm, should match wildcard pattern
58 assert_eq!(3, match 3 {
65 fn range_shadow_lit() {
66 assert_eq!(2, match 1 {
73 assert_eq!(2, match x+1 {
80 assert_eq!(2, match val() {
86 assert_eq!(2, match CONST {
94 assert_eq!(3, match 3 {
101 fn range_shadow_range() {
102 assert_eq!(2, match 1 {
109 assert_eq!(2, match x+1 {
116 assert_eq!(2, match val() {
122 assert_eq!(2, match CONST {
130 assert_eq!(3, match 5 {
137 fn multi_pats_shadow_lit() {
138 assert_eq!(2, match 1 {
140 0 | 1..10 if false => 1,
146 fn multi_pats_shadow_range() {
147 assert_eq!(2, match 1 {
149 0 | 1..10 if false => 1,
155 fn lit_shadow_multi_pats() {
156 assert_eq!(2, match 1 {
164 fn range_shadow_multi_pats() {
165 assert_eq!(2, match 1 {
177 // This test basically mimics how trace_macros! macro is implemented,
178 // which is a rare combination of vector patterns, multiple wild-card
179 // patterns and guard functions.
180 let r = match [Bar(0, false)].as_slice() {
181 [Bar(_, pred)] if pred => 1,
182 [Bar(_, pred)] if !pred => 2,