blob: 73b059eadf5f4537095086482c81d5796b2f75b0 [file] [log] [blame]
Graydon Hoarece729932011-06-15 18:19:501
2
3
Brian Anderson1326d422011-04-02 23:32:344// -*- rust -*-
5
Brian Andersonecaf9e32012-08-06 19:34:086// Tests for match as expressions resulting in structural types
Brian Anderson1326d422011-04-02 23:32:347fn test_rec() {
Tim Chevaliere9622f02012-08-23 21:44:588 let rs = match true { true => {i: 100}, _ => fail };
Patrick Walton96534362012-08-27 23:26:359 assert (rs.i == 100);
10}
11
12enum mood { happy, sad, }
13impl mood : cmp::Eq {
14 pure fn eq(&&other: mood) -> bool {
15 (self as uint) == (other as uint)
16 }
Brian Anderson1326d422011-04-02 23:32:3417}
18
19fn test_tag() {
Brian Andersonecaf9e32012-08-06 19:34:0820 let rs = match true { true => { happy } false => { sad } };
Marijn Haverbeke781a2652011-06-25 15:45:4921 assert (rs == happy);
Brian Anderson1326d422011-04-02 23:32:3422}
23
Brian Anderson518dc522011-08-19 22:16:4824fn main() { test_rec(); test_tag(); }