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:
parent
349fa1e550
commit
79f0d67d28
38
src/test/run-pass/const-big-enum.rs
Normal file
38
src/test/run-pass/const-big-enum.rs
Normal 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);
|
20
src/test/run-pass/const-newtype-enum.rs
Normal file
20
src/test/run-pass/const-newtype-enum.rs
Normal 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);
|
@ -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;
|
||||
|
@ -16,4 +16,7 @@ const X: Foo = Bar;
|
||||
|
||||
fn main() {
|
||||
assert((X as uint) == 0xDEADBEE);
|
||||
assert((Y as uint) == 0xDEADBEE);
|
||||
}
|
||||
|
||||
const Y: Foo = Bar;
|
||||
|
Loading…
x
Reference in New Issue
Block a user