2015-04-12 18:19:48 +00:00
|
|
|
// Copyright 2013-2015 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.
|
|
|
|
|
2016-10-13 17:31:49 +00:00
|
|
|
#![feature(proc_macro)]
|
2015-04-12 18:19:48 +00:00
|
|
|
|
|
|
|
extern crate num;
|
2016-09-18 18:56:36 +00:00
|
|
|
#[macro_use]
|
2016-09-28 11:33:13 +00:00
|
|
|
extern crate num_derive;
|
2015-04-12 18:19:48 +00:00
|
|
|
|
2016-09-18 18:56:36 +00:00
|
|
|
#[derive(Debug, PartialEq, FromPrimitive)]
|
2015-04-12 18:19:48 +00:00
|
|
|
enum Color {
|
|
|
|
Red,
|
|
|
|
Blue,
|
|
|
|
Green,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2016-09-18 20:40:58 +00:00
|
|
|
fn test_from_primitive_for_trivial_case() {
|
2016-09-18 18:56:36 +00:00
|
|
|
let v: [Option<Color>; 4] = [num::FromPrimitive::from_u64(0),
|
|
|
|
num::FromPrimitive::from_u64(1),
|
|
|
|
num::FromPrimitive::from_u64(2),
|
|
|
|
num::FromPrimitive::from_u64(3)];
|
2015-04-12 18:19:48 +00:00
|
|
|
|
2016-09-18 18:56:36 +00:00
|
|
|
assert_eq!(v,
|
|
|
|
[Some(Color::Red), Some(Color::Blue), Some(Color::Green), None]);
|
2015-04-12 18:19:48 +00:00
|
|
|
}
|