Skip to content

Commit 79f0d67

Browse files
committed
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.
1 parent 349fa1e commit 79f0d67

File tree

4 files changed

+67
-1
lines changed

4 files changed

+67
-1
lines changed

src/test/run-pass/const-big-enum.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2013 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.
4+
//
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.
10+
11+
enum Foo {
12+
Bar(u32),
13+
Baz,
14+
Quux(u64, u16)
15+
}
16+
17+
const X: Foo = Baz;
18+
19+
fn main() {
20+
match X {
21+
Baz => {}
22+
_ => fail
23+
}
24+
match Y {
25+
Bar(s) => assert(s == 2654435769),
26+
_ => fail
27+
}
28+
match Z {
29+
Quux(d,h) => {
30+
assert(d == 0x123456789abcdef0);
31+
assert(h == 0x1234);
32+
}
33+
_ => fail
34+
}
35+
}
36+
37+
const Y: Foo = Bar(2654435769);
38+
const Z: Foo = Quux(0x123456789abcdef0, 0x1234);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2013 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.
4+
//
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.
10+
11+
enum Foo = u32;
12+
13+
const X: Foo = Foo(17);
14+
15+
fn main() {
16+
assert(*X == 17);
17+
assert(*Y == 23);
18+
}
19+
20+
const Y: Foo = Foo(23);

src/test/run-pass/const-nullary-enum.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -21,5 +21,10 @@ fn main() {
2121
Bar => {}
2222
Baz | Boo => fail
2323
}
24+
match Y {
25+
Baz => {}
26+
Bar | Boo => fail
27+
}
2428
}
2529

30+
const Y: Foo = Baz;

src/test/run-pass/const-nullary-univariant-enum.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,7 @@ const X: Foo = Bar;
1616

1717
fn main() {
1818
assert((X as uint) == 0xDEADBEE);
19+
assert((Y as uint) == 0xDEADBEE);
1920
}
21+
22+
const Y: Foo = Bar;

0 commit comments

Comments
 (0)