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 // ignore-lexer-test FIXME #15877
13 // Tests that match expression handles overlapped literal and range
14 // properly in the presence of guard function.
16 fn val() -> uint { 1 }
18 static CONST: uint = 1;
24 multi_pats_shadow_lit();
25 multi_pats_shadow_range();
26 lit_shadow_multi_pats();
27 range_shadow_multi_pats();
31 fn lit_shadow_range() {
32 assert_eq!(2i, match 1i {
39 assert_eq!(2i, match x+1 {
46 assert_eq!(2i, match val() {
52 assert_eq!(2i, match CONST {
59 // value is out of the range of second arm, should match wildcard pattern
60 assert_eq!(3i, match 3i {
67 fn range_shadow_lit() {
68 assert_eq!(2i, match 1i {
75 assert_eq!(2i, match x+1 {
82 assert_eq!(2i, match val() {
88 assert_eq!(2i, match CONST {
96 assert_eq!(3i, match 3i {
103 fn range_shadow_range() {
104 assert_eq!(2i, match 1i {
111 assert_eq!(2i, match x+1 {
118 assert_eq!(2i, match val() {
124 assert_eq!(2i, match CONST {
132 assert_eq!(3i, match 5i {
139 fn multi_pats_shadow_lit() {
140 assert_eq!(2i, match 1i {
142 0 | 1..10 if false => 1,
148 fn multi_pats_shadow_range() {
149 assert_eq!(2i, match 1i {
151 0 | 1..10 if false => 1,
157 fn lit_shadow_multi_pats() {
158 assert_eq!(2i, match 1i {
166 fn range_shadow_multi_pats() {
167 assert_eq!(2i, match 1i {
179 // This test basically mimics how trace_macros! macro is implemented,
180 // which is a rare combination of vector patterns, multiple wild-card
181 // patterns and guard functions.
182 let r = match [Bar(0, false)].as_slice() {
183 [Bar(_, pred)] if pred => 1i,
184 [Bar(_, pred)] if !pred => 2i,