Add more tests for enum constants.

The tests have consts defined both before and after their uses in order
to prevent bugs that depend on the order in which they are translated.
This commit is contained in:
Jed Davis 2013-01-04 01:22:56 -08:00
parent 349fa1e550
commit 79f0d67d28
4 changed files with 67 additions and 1 deletions

View File

@ -0,0 +1,38 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
enum Foo {
Bar(u32),
Baz,
Quux(u64, u16)
}
const X: Foo = Baz;
fn main() {
match X {
Baz => {}
_ => fail
}
match Y {
Bar(s) => assert(s == 2654435769),
_ => fail
}
match Z {
Quux(d,h) => {
assert(d == 0x123456789abcdef0);
assert(h == 0x1234);
}
_ => fail
}
}
const Y: Foo = Bar(2654435769);
const Z: Foo = Quux(0x123456789abcdef0, 0x1234);

View File

@ -0,0 +1,20 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
enum Foo = u32;
const X: Foo = Foo(17);
fn main() {
assert(*X == 17);
assert(*Y == 23);
}
const Y: Foo = Foo(23);

View File

@ -1,4 +1,4 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
@ -21,5 +21,10 @@ fn main() {
Bar => {}
Baz | Boo => fail
}
match Y {
Baz => {}
Bar | Boo => fail
}
}
const Y: Foo = Baz;

View File

@ -16,4 +16,7 @@ const X: Foo = Bar;
fn main() {
assert((X as uint) == 0xDEADBEE);
assert((Y as uint) == 0xDEADBEE);
}
const Y: Foo = Bar;