From 79f0d67d2801f17c143b38926f05a40d0c22f5c0 Mon Sep 17 00:00:00 2001 From: Jed Davis Date: Fri, 4 Jan 2013 01:22:56 -0800 Subject: [PATCH] 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. --- src/test/run-pass/const-big-enum.rs | 38 +++++++++++++++++++ src/test/run-pass/const-newtype-enum.rs | 20 ++++++++++ src/test/run-pass/const-nullary-enum.rs | 7 +++- .../run-pass/const-nullary-univariant-enum.rs | 3 ++ 4 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 src/test/run-pass/const-big-enum.rs create mode 100644 src/test/run-pass/const-newtype-enum.rs diff --git a/src/test/run-pass/const-big-enum.rs b/src/test/run-pass/const-big-enum.rs new file mode 100644 index 00000000000..aa977f17e69 --- /dev/null +++ b/src/test/run-pass/const-big-enum.rs @@ -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 or the MIT license +// , 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); diff --git a/src/test/run-pass/const-newtype-enum.rs b/src/test/run-pass/const-newtype-enum.rs new file mode 100644 index 00000000000..069565aa4f8 --- /dev/null +++ b/src/test/run-pass/const-newtype-enum.rs @@ -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 or the MIT license +// , 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); diff --git a/src/test/run-pass/const-nullary-enum.rs b/src/test/run-pass/const-nullary-enum.rs index abdddfe1c62..098305bbe35 100644 --- a/src/test/run-pass/const-nullary-enum.rs +++ b/src/test/run-pass/const-nullary-enum.rs @@ -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; diff --git a/src/test/run-pass/const-nullary-univariant-enum.rs b/src/test/run-pass/const-nullary-univariant-enum.rs index e1db50d566b..2fa5a7760f6 100644 --- a/src/test/run-pass/const-nullary-univariant-enum.rs +++ b/src/test/run-pass/const-nullary-univariant-enum.rs @@ -16,4 +16,7 @@ const X: Foo = Bar; fn main() { assert((X as uint) == 0xDEADBEE); + assert((Y as uint) == 0xDEADBEE); } + +const Y: Foo = Bar;