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.
13 #[derive(PartialEq, Eq)]
16 #[derive(PartialEq, Eq)]
24 #[derive(PartialEq, Eq)]
26 bar
: Option
<Direction
>,
30 #[derive(PartialEq, Eq)]
31 enum EnumWithStructVariants
{
38 const TRUE_TRUE
: (bool
, bool
) = (true, true);
39 const NONE
: Option
<Direction
> = None
;
40 const EAST
: Direction
= Direction
::East
;
41 const NEW_FALSE
: NewBool
= NewBool(false);
42 const STATIC_FOO
: Foo
= Foo { bar: Some(Direction::South), baz: NEW_FALSE }
;
43 const VARIANT2_NORTH
: EnumWithStructVariants
= EnumWithStructVariants
::Variant2
{
44 dir
: Direction
::North
};
47 #[derive(Copy, Clone, PartialEq, Eq)]
48 pub struct InputState(usize);
50 pub const RELEASE
: InputState
= InputState(0);
51 pub const PRESS
: InputState
= InputState(1);
52 pub const REPEAT
: InputState
= InputState(2);
58 fn action_to_str(state
: glfw
::InputState
) -> &'
static str {
59 use glfw
::{RELEASE, PRESS, REPEAT}
;
61 RELEASE
=> { "Released" }
62 PRESS
=> { "Pressed" }
63 REPEAT
=> { "Repeated" }
68 assert_eq
!(action_to_str(glfw
::RELEASE
), "Released");
69 assert_eq
!(action_to_str(glfw
::PRESS
), "Pressed");
70 assert_eq
!(action_to_str(glfw
::REPEAT
), "Repeated");
74 const VAL
: [u8; 1] = [0];
76 VAL
=> unreachable
!(),
82 type Foo
= (i32, i32);
83 const ON
: Foo
= (1, 1);
84 const OFF
: Foo
= (0, 0);
87 OFF
=> unreachable
!(),
92 #[derive(PartialEq, Eq)]
93 enum C { D = 3, E = 4 }
96 assert_eq
!(match C
::D { F => 1, _ => 2, }
, 1);
100 #[derive(PartialEq, Eq)]
102 const B
: A
= A
::AA(());
111 #[derive(PartialEq, Eq)]
116 const FOO
: Flags
= Flags { bits: 0x01 }
;
117 const BAR
: Flags
= Flags { bits: 0x02 }
;
118 match (Flags { bits: 0x02 }
) {
119 FOO
=> unreachable
!(),
126 assert_eq
!(match (true, false) {
133 assert_eq
!(match Some(Some(Direction
::North
)) {
135 Some(Some(Direction
::North
)) => 2,
136 Some(Some(EAST
)) => 3,
137 Some(Some(Direction
::South
)) => 4,
138 Some(Some(Direction
::West
)) => 5,
142 assert_eq
!(match (Foo { bar: Some(Direction::West), baz: NewBool(true) }
) {
143 Foo { bar: None, baz: NewBool(true) }
=> 1,
144 Foo { bar: NONE, baz: NEW_FALSE }
=> 2,
146 Foo { bar: _, baz: NEW_FALSE }
=> 4,
147 Foo { bar: Some(Direction::West), baz: NewBool(true) }
=> 5,
148 Foo { bar: Some(Direction::South), baz: NewBool(true) }
=> 6,
149 Foo { bar: Some(EAST), .. }
=> 7,
150 Foo { bar: Some(Direction::North), baz: NewBool(true) }
=> 8
153 assert_eq
!(match (EnumWithStructVariants
::Variant2 { dir: Direction::North }
) {
154 EnumWithStructVariants
::Variant1(true) => 1,
155 EnumWithStructVariants
::Variant1(false) => 2,
156 EnumWithStructVariants
::Variant2 { dir: Direction::West }
=> 3,
158 EnumWithStructVariants
::Variant2 { dir: Direction::South }
=> 5,
159 EnumWithStructVariants
::Variant2 { dir: Direction::East }
=> 6