]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/if-let.rs
rustdoc: Replace no-pretty-expanded with pretty-expanded
[rust.git] / src / test / run-pass / if-let.rs
1 // Copyright 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.
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 // pretty-expanded FIXME #23616
12
13 pub fn main() {
14     let x = Some(3);
15     if let Some(y) = x {
16         assert_eq!(y, 3);
17     } else {
18         panic!("if-let panicked");
19     }
20     let mut worked = false;
21     if let Some(_) = x {
22         worked = true;
23     }
24     assert!(worked);
25     let clause: uint;
26     if let None = Some("test") {
27         clause = 1;
28     } else if 4_usize > 5 {
29         clause = 2;
30     } else if let Ok(()) = Err::<(),&'static str>("test") {
31         clause = 3;
32     } else {
33         clause = 4;
34     }
35     assert_eq!(clause, 4_usize);
36
37     if 3 > 4 {
38         panic!("bad math");
39     } else if let 1 = 2 {
40         panic!("bad pattern match");
41     }
42
43     enum Foo {
44         One,
45         Two(uint),
46         Three(String, int)
47     }
48
49     let foo = Foo::Three("three".to_string(), 42);
50     if let Foo::One = foo {
51         panic!("bad pattern match");
52     } else if let Foo::Two(_x) = foo {
53         panic!("bad pattern match");
54     } else if let Foo::Three(s, _) = foo {
55         assert_eq!(s, "three");
56     } else {
57         panic!("bad else");
58     }
59
60     if false {
61         panic!("wat");
62     } else if let a@Foo::Two(_) = Foo::Two(42_usize) {
63         if let Foo::Two(b) = a {
64             assert_eq!(b, 42_usize);
65         } else {
66             panic!("panic in nested if-let");
67         }
68     }
69 }