]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/expr-match-struct.rs
rollup merge of #18413 : bkoropoff/issue-18412
[rust.git] / src / test / run-pass / expr-match-struct.rs
1 // Copyright 2012 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
12
13
14
15 // Tests for match as expressions resulting in struct types
16 struct R { i: int }
17
18 fn test_rec() {
19     let rs = match true { true => R {i: 100}, _ => panic!() };
20     assert_eq!(rs.i, 100);
21 }
22
23 #[deriving(Show)]
24 enum mood { happy, sad, }
25
26 impl PartialEq for mood {
27     fn eq(&self, other: &mood) -> bool {
28         ((*self) as uint) == ((*other) as uint)
29     }
30     fn ne(&self, other: &mood) -> bool { !(*self).eq(other) }
31 }
32
33 fn test_tag() {
34     let rs = match true { true => { happy } false => { sad } };
35     assert_eq!(rs, happy);
36 }
37
38 pub fn main() { test_rec(); test_tag(); }