blob: 7cfcc38f8dd3104eb55806acb9e9757a19cf3971 [file] [log] [blame]
Graydon Hoared1affff2012-12-11 01:32:481// 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
Graydon Hoarece729932011-06-15 18:19:5011
12
13
Brian Anderson1326d422011-04-02 23:32:3414// -*- rust -*-
15
Tim Chevalier6d4907a2013-01-26 06:46:3216// Tests for match as expressions resulting in struct types
17struct R { i: int }
18
Brian Anderson1326d422011-04-02 23:32:3419fn test_rec() {
Nick Desaulniers4445b382013-02-12 03:26:3820 let rs = match true { true => R {i: 100}, _ => fail!() };
Corey Richardsoncc57ca02013-05-19 02:02:4521 assert_eq!(rs.i, 100);
Patrick Walton96534362012-08-27 23:26:3522}
23
24enum mood { happy, sad, }
Patrick Walton9117dcb2012-09-20 01:00:2625
Patrick Walton206ab892013-05-25 02:35:2926impl Eq for mood {
Patrick Walton3eda11a2013-03-22 18:23:2127 fn eq(&self, other: &mood) -> bool {
Patrick Walton318e5342012-11-15 02:59:3028 ((*self) as uint) == ((*other) as uint)
Patrick Walton96534362012-08-27 23:26:3529 }
Patrick Walton3eda11a2013-03-22 18:23:2130 fn ne(&self, other: &mood) -> bool { !(*self).eq(other) }
Brian Anderson1326d422011-04-02 23:32:3431}
32
33fn test_tag() {
Brian Andersonecaf9e32012-08-06 19:34:0834 let rs = match true { true => { happy } false => { sad } };
Corey Richardsoncc57ca02013-05-19 02:02:4535 assert_eq!(rs, happy);
Brian Anderson1326d422011-04-02 23:32:3436}
37
Graydon Hoare89c8ef72013-02-02 03:43:1738pub fn main() { test_rec(); test_tag(); }