]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/expr-match-struct.rs
rollup merge of #19585: mdinger/guide_typo
[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 impl Copy for R {}
19
20 fn test_rec() {
21     let rs = match true { true => R {i: 100}, _ => panic!() };
22     assert_eq!(rs.i, 100);
23 }
24
25 #[deriving(Show)]
26 enum mood { happy, sad, }
27
28 impl Copy for mood {}
29
30 impl PartialEq for mood {
31     fn eq(&self, other: &mood) -> bool {
32         ((*self) as uint) == ((*other) as uint)
33     }
34     fn ne(&self, other: &mood) -> bool { !(*self).eq(other) }
35 }
36
37 fn test_tag() {
38     let rs = match true { true => { mood::happy } false => { mood::sad } };
39     assert_eq!(rs, mood::happy);
40 }
41
42 pub fn main() { test_rec(); test_tag(); }