]>
Commit | Line | Data |
---|---|---|
9cc50fc6 SL |
1 | // Copyright 2015 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 | ||
9cc50fc6 SL |
11 | fn test1(x: i8) -> i32 { |
12 | match x { | |
13 | 1...10 => 0, | |
14 | _ => 1, | |
15 | } | |
16 | } | |
17 | ||
18 | const U: Option<i8> = Some(10); | |
19 | const S: &'static str = "hello"; | |
20 | ||
9cc50fc6 SL |
21 | fn test2(x: i8) -> i32 { |
22 | match Some(x) { | |
23 | U => 0, | |
24 | _ => 1, | |
25 | } | |
26 | } | |
27 | ||
9cc50fc6 SL |
28 | fn test3(x: &'static str) -> i32 { |
29 | match x { | |
30 | S => 0, | |
31 | _ => 1, | |
32 | } | |
33 | } | |
34 | ||
35 | enum Opt<T> { | |
36 | Some { v: T }, | |
37 | None | |
38 | } | |
39 | ||
9cc50fc6 SL |
40 | fn test4(x: u64) -> i32 { |
41 | let opt = Opt::Some{ v: x }; | |
42 | match opt { | |
43 | Opt::Some { v: 10 } => 0, | |
44 | _ => 1, | |
45 | } | |
46 | } | |
47 | ||
48 | ||
49 | fn main() { | |
50 | assert_eq!(test1(0), 1); | |
51 | assert_eq!(test1(1), 0); | |
52 | assert_eq!(test1(2), 0); | |
53 | assert_eq!(test1(5), 0); | |
54 | assert_eq!(test1(9), 0); | |
55 | assert_eq!(test1(10), 0); | |
56 | assert_eq!(test1(11), 1); | |
57 | assert_eq!(test1(20), 1); | |
58 | assert_eq!(test2(10), 0); | |
59 | assert_eq!(test2(0), 1); | |
60 | assert_eq!(test2(20), 1); | |
61 | assert_eq!(test3("hello"), 0); | |
62 | assert_eq!(test3(""), 1); | |
63 | assert_eq!(test3("world"), 1); | |
64 | assert_eq!(test4(10), 0); | |
65 | assert_eq!(test4(0), 1); | |
66 | assert_eq!(test4(20), 1); | |
67 | } |