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.
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.
20 bar: Option<Direction>,
23 enum EnumWithStructVariants {
30 const TRUE_TRUE: (bool, bool) = (true, true);
31 const NONE: Option<Direction> = None;
32 const EAST: Direction = Direction::East;
33 const NEW_FALSE: NewBool = NewBool(false);
34 const STATIC_FOO: Foo = Foo { bar: Some(Direction::South), baz: NEW_FALSE };
35 const VARIANT2_NORTH: EnumWithStructVariants = EnumWithStructVariants::Variant2 {
36 dir: Direction::North };
40 pub struct InputState(uint);
42 pub const RELEASE : InputState = InputState(0);
43 pub const PRESS : InputState = InputState(1);
44 pub const REPEAT : InputState = InputState(2);
50 fn action_to_str(state: glfw::InputState) -> &'static str {
51 use glfw::{RELEASE, PRESS, REPEAT};
53 RELEASE => { "Released" }
54 PRESS => { "Pressed" }
55 REPEAT => { "Repeated" }
60 assert_eq!(action_to_str(glfw::RELEASE), "Released");
61 assert_eq!(action_to_str(glfw::PRESS), "Pressed");
62 assert_eq!(action_to_str(glfw::REPEAT), "Repeated");
66 const VAL: [u8; 1] = [0];
68 VAL => unreachable!(),
74 type Foo = (i32, i32);
75 const ON: Foo = (1, 1);
76 const OFF: Foo = (0, 0);
79 OFF => unreachable!(),
84 enum C { D = 3, E = 4 }
87 assert_eq!(match C::D { F => 1, _ => 2, }, 1);
92 const B: A = A::AA(());
105 const FOO: Flags = Flags { bits: 0x01 };
106 const BAR: Flags = Flags { bits: 0x02 };
107 match (Flags { bits: 0x02 }) {
108 FOO => unreachable!(),
115 assert_eq!(match (true, false) {
122 assert_eq!(match Some(Some(Direction::North)) {
124 Some(Some(Direction::North)) => 2,
125 Some(Some(EAST)) => 3,
126 Some(Some(Direction::South)) => 4,
127 Some(Some(Direction::West)) => 5,
131 assert_eq!(match (Foo { bar: Some(Direction::West), baz: NewBool(true) }) {
132 Foo { bar: None, baz: NewBool(true) } => 1,
133 Foo { bar: NONE, baz: NEW_FALSE } => 2,
135 Foo { bar: _, baz: NEW_FALSE } => 4,
136 Foo { bar: Some(Direction::West), baz: NewBool(true) } => 5,
137 Foo { bar: Some(Direction::South), baz: NewBool(true) } => 6,
138 Foo { bar: Some(EAST), .. } => 7,
139 Foo { bar: Some(Direction::North), baz: NewBool(true) } => 8
142 assert_eq!(match (EnumWithStructVariants::Variant2 { dir: Direction::North }) {
143 EnumWithStructVariants::Variant1(true) => 1,
144 EnumWithStructVariants::Variant1(false) => 2,
145 EnumWithStructVariants::Variant2 { dir: Direction::West } => 3,
147 EnumWithStructVariants::Variant2 { dir: Direction::South } => 5,
148 EnumWithStructVariants::Variant2 { dir: Direction::East } => 6