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.
21 bar: Option<Direction>,
24 enum EnumWithStructVariants {
31 const TRUE_TRUE: (bool, bool) = (true, true);
32 const NONE: Option<Direction> = None;
33 const EAST: Direction = Direction::East;
34 const NEW_FALSE: NewBool = NewBool(false);
35 const STATIC_FOO: Foo = Foo { bar: Some(Direction::South), baz: NEW_FALSE };
36 const VARIANT2_NORTH: EnumWithStructVariants = EnumWithStructVariants::Variant2 {
37 dir: Direction::North };
40 #[derive(Copy, Clone)]
41 pub struct InputState(usize);
43 pub const RELEASE : InputState = InputState(0);
44 pub const PRESS : InputState = InputState(1);
45 pub const REPEAT : InputState = InputState(2);
51 fn action_to_str(state: glfw::InputState) -> &'static str {
52 use glfw::{RELEASE, PRESS, REPEAT};
54 RELEASE => { "Released" }
55 PRESS => { "Pressed" }
56 REPEAT => { "Repeated" }
61 assert_eq!(action_to_str(glfw::RELEASE), "Released");
62 assert_eq!(action_to_str(glfw::PRESS), "Pressed");
63 assert_eq!(action_to_str(glfw::REPEAT), "Repeated");
67 const VAL: [u8; 1] = [0];
69 VAL => unreachable!(),
75 type Foo = (i32, i32);
76 const ON: Foo = (1, 1);
77 const OFF: Foo = (0, 0);
80 OFF => unreachable!(),
85 enum C { D = 3, E = 4 }
88 assert_eq!(match C::D { F => 1, _ => 2, }, 1);
93 const B: A = A::AA(());
106 const FOO: Flags = Flags { bits: 0x01 };
107 const BAR: Flags = Flags { bits: 0x02 };
108 match (Flags { bits: 0x02 }) {
109 FOO => unreachable!(),
116 assert_eq!(match (true, false) {
123 assert_eq!(match Some(Some(Direction::North)) {
125 Some(Some(Direction::North)) => 2,
126 Some(Some(EAST)) => 3,
127 Some(Some(Direction::South)) => 4,
128 Some(Some(Direction::West)) => 5,
132 assert_eq!(match (Foo { bar: Some(Direction::West), baz: NewBool(true) }) {
133 Foo { bar: None, baz: NewBool(true) } => 1,
134 Foo { bar: NONE, baz: NEW_FALSE } => 2,
136 Foo { bar: _, baz: NEW_FALSE } => 4,
137 Foo { bar: Some(Direction::West), baz: NewBool(true) } => 5,
138 Foo { bar: Some(Direction::South), baz: NewBool(true) } => 6,
139 Foo { bar: Some(EAST), .. } => 7,
140 Foo { bar: Some(Direction::North), baz: NewBool(true) } => 8
143 assert_eq!(match (EnumWithStructVariants::Variant2 { dir: Direction::North }) {
144 EnumWithStructVariants::Variant1(true) => 1,
145 EnumWithStructVariants::Variant1(false) => 2,
146 EnumWithStructVariants::Variant2 { dir: Direction::West } => 3,
148 EnumWithStructVariants::Variant2 { dir: Direction::South } => 5,
149 EnumWithStructVariants::Variant2 { dir: Direction::East } => 6