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.
12 #[derive(PartialEq, Eq)]
15 #[derive(PartialEq, Eq)]
23 #[derive(PartialEq, Eq)]
25 bar: Option<Direction>,
29 #[derive(PartialEq, Eq)]
30 enum EnumWithStructVariants {
37 const TRUE_TRUE: (bool, bool) = (true, true);
38 const NONE: Option<Direction> = None;
39 const EAST: Direction = Direction::East;
40 const NEW_FALSE: NewBool = NewBool(false);
41 const STATIC_FOO: Foo = Foo { bar: Some(Direction::South), baz: NEW_FALSE };
42 const VARIANT2_NORTH: EnumWithStructVariants = EnumWithStructVariants::Variant2 {
43 dir: Direction::North };
46 #[derive(Copy, Clone, PartialEq, Eq)]
47 pub struct InputState(usize);
49 pub const RELEASE : InputState = InputState(0);
50 pub const PRESS : InputState = InputState(1);
51 pub const REPEAT : InputState = InputState(2);
57 fn action_to_str(state: glfw::InputState) -> &'static str {
58 use glfw::{RELEASE, PRESS, REPEAT};
60 RELEASE => { "Released" }
61 PRESS => { "Pressed" }
62 REPEAT => { "Repeated" }
67 assert_eq!(action_to_str(glfw::RELEASE), "Released");
68 assert_eq!(action_to_str(glfw::PRESS), "Pressed");
69 assert_eq!(action_to_str(glfw::REPEAT), "Repeated");
73 const VAL: [u8; 1] = [0];
75 VAL => unreachable!(),
81 type Foo = (i32, i32);
82 const ON: Foo = (1, 1);
83 const OFF: Foo = (0, 0);
86 OFF => unreachable!(),
91 #[derive(PartialEq, Eq)]
92 enum C { D = 3, E = 4 }
95 assert_eq!(match C::D { F => 1, _ => 2, }, 1);
99 #[derive(PartialEq, Eq)]
101 const B: A = A::AA(());
110 #[derive(PartialEq, Eq)]
115 const FOO: Flags = Flags { bits: 0x01 };
116 const BAR: Flags = Flags { bits: 0x02 };
117 match (Flags { bits: 0x02 }) {
118 FOO => unreachable!(),
125 assert_eq!(match (true, false) {
132 assert_eq!(match Some(Some(Direction::North)) {
134 Some(Some(Direction::North)) => 2,
135 Some(Some(EAST)) => 3,
136 Some(Some(Direction::South)) => 4,
137 Some(Some(Direction::West)) => 5,
141 assert_eq!(match (Foo { bar: Some(Direction::West), baz: NewBool(true) }) {
142 Foo { bar: None, baz: NewBool(true) } => 1,
143 Foo { bar: NONE, baz: NEW_FALSE } => 2,
145 Foo { bar: _, baz: NEW_FALSE } => 4,
146 Foo { bar: Some(Direction::West), baz: NewBool(true) } => 5,
147 Foo { bar: Some(Direction::South), baz: NewBool(true) } => 6,
148 Foo { bar: Some(EAST), .. } => 7,
149 Foo { bar: Some(Direction::North), baz: NewBool(true) } => 8
152 assert_eq!(match (EnumWithStructVariants::Variant2 { dir: Direction::North }) {
153 EnumWithStructVariants::Variant1(true) => 1,
154 EnumWithStructVariants::Variant1(false) => 2,
155 EnumWithStructVariants::Variant2 { dir: Direction::West } => 3,
157 EnumWithStructVariants::Variant2 { dir: Direction::South } => 5,
158 EnumWithStructVariants::Variant2 { dir: Direction::East } => 6