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.
11 // pretty-expanded FIXME #23616
22 bar: Option<Direction>,
25 enum EnumWithStructVariants {
32 const TRUE_TRUE: (bool, bool) = (true, true);
33 const NONE: Option<Direction> = None;
34 const EAST: Direction = Direction::East;
35 const NEW_FALSE: NewBool = NewBool(false);
36 const STATIC_FOO: Foo = Foo { bar: Some(Direction::South), baz: NEW_FALSE };
37 const VARIANT2_NORTH: EnumWithStructVariants = EnumWithStructVariants::Variant2 {
38 dir: Direction::North };
41 #[derive(Copy, Clone)]
42 pub struct InputState(usize);
44 pub const RELEASE : InputState = InputState(0);
45 pub const PRESS : InputState = InputState(1);
46 pub const REPEAT : InputState = InputState(2);
52 fn action_to_str(state: glfw::InputState) -> &'static str {
53 use glfw::{RELEASE, PRESS, REPEAT};
55 RELEASE => { "Released" }
56 PRESS => { "Pressed" }
57 REPEAT => { "Repeated" }
62 assert_eq!(action_to_str(glfw::RELEASE), "Released");
63 assert_eq!(action_to_str(glfw::PRESS), "Pressed");
64 assert_eq!(action_to_str(glfw::REPEAT), "Repeated");
68 const VAL: [u8; 1] = [0];
70 VAL => unreachable!(),
76 type Foo = (i32, i32);
77 const ON: Foo = (1, 1);
78 const OFF: Foo = (0, 0);
81 OFF => unreachable!(),
86 enum C { D = 3, E = 4 }
89 assert_eq!(match C::D { F => 1, _ => 2, }, 1);
94 const B: A = A::AA(());
107 const FOO: Flags = Flags { bits: 0x01 };
108 const BAR: Flags = Flags { bits: 0x02 };
109 match (Flags { bits: 0x02 }) {
110 FOO => unreachable!(),
117 assert_eq!(match (true, false) {
124 assert_eq!(match Some(Some(Direction::North)) {
126 Some(Some(Direction::North)) => 2,
127 Some(Some(EAST)) => 3,
128 Some(Some(Direction::South)) => 4,
129 Some(Some(Direction::West)) => 5,
133 assert_eq!(match (Foo { bar: Some(Direction::West), baz: NewBool(true) }) {
134 Foo { bar: None, baz: NewBool(true) } => 1,
135 Foo { bar: NONE, baz: NEW_FALSE } => 2,
137 Foo { bar: _, baz: NEW_FALSE } => 4,
138 Foo { bar: Some(Direction::West), baz: NewBool(true) } => 5,
139 Foo { bar: Some(Direction::South), baz: NewBool(true) } => 6,
140 Foo { bar: Some(EAST), .. } => 7,
141 Foo { bar: Some(Direction::North), baz: NewBool(true) } => 8
144 assert_eq!(match (EnumWithStructVariants::Variant2 { dir: Direction::North }) {
145 EnumWithStructVariants::Variant1(true) => 1,
146 EnumWithStructVariants::Variant1(false) => 2,
147 EnumWithStructVariants::Variant2 { dir: Direction::West } => 3,
149 EnumWithStructVariants::Variant2 { dir: Direction::South } => 5,
150 EnumWithStructVariants::Variant2 { dir: Direction::East } => 6