diff options
| author | James Miller <james@aatch.net> | 2015-01-11 13:51:58 +1300 |
|---|---|---|
| committer | Felix S. Klock II <pnkfelix@pnkfx.org> | 2015-04-10 12:23:37 +0200 |
| commit | 800c5f8038280fe8524ebd797b93c2ad4e16e1b7 (patch) | |
| tree | 7a2997f29e6d52004f67d8467b17c95740317838 /src | |
| parent | 41dd35503a358b652cfbbf7fba499cbaf1234637 (diff) | |
| download | rust-800c5f8038280fe8524ebd797b93c2ad4e16e1b7.tar.gz rust-800c5f8038280fe8524ebd797b93c2ad4e16e1b7.zip | |
Add test for discriminant_value results
Diffstat (limited to 'src')
| -rw-r--r-- | src/test/run-pass/discriminant_value.rs | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/test/run-pass/discriminant_value.rs b/src/test/run-pass/discriminant_value.rs new file mode 100644 index 00000000000..531a30d6580 --- /dev/null +++ b/src/test/run-pass/discriminant_value.rs @@ -0,0 +1,62 @@ +// Copyright 2014 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. + +extern crate core; +use core::intrinsics::discriminant_value; + +enum CLike1 { + A, + B, + C, + D +} + +enum CLike2 { + A = 5, + B = 2, + C = 19, + D +} + +enum ADT { + First(u32, u32), + Second(u64) +} + +enum NullablePointer { + Something(&'static u32), + Nothing +} + +static CONST : u32 = 0xBEEF; + +pub fn main() { + unsafe { + + assert_eq!(discriminant_value(&CLike1::A), 0); + assert_eq!(discriminant_value(&CLike1::B), 1); + assert_eq!(discriminant_value(&CLike1::C), 2); + assert_eq!(discriminant_value(&CLike1::D), 3); + + assert_eq!(discriminant_value(&CLike2::A), 5); + assert_eq!(discriminant_value(&CLike2::B), 2); + assert_eq!(discriminant_value(&CLike2::C), 19); + assert_eq!(discriminant_value(&CLike2::D), 20); + + assert_eq!(discriminant_value(&ADT::First(0,0)), 0); + assert_eq!(discriminant_value(&ADT::Second(5)), 1); + + assert_eq!(discriminant_value(&NullablePointer::Nothing), 1); + assert_eq!(discriminant_value(&NullablePointer::Something(&CONST)), 0); + + assert_eq!(discriminant_value(&10), 0); + assert_eq!(discriminant_value(&"test"), 0); + } +} |
