test_macro.rs 999 B

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright 2013-2015 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. #![feature(custom_derive, plugin)]
  11. #![plugin(num_macros)]
  12. extern crate num;
  13. #[derive(Debug, PartialEq, NumFromPrimitive)]
  14. enum Color {
  15. Red,
  16. Blue,
  17. Green,
  18. }
  19. #[test]
  20. fn test_from_primitive() {
  21. let v: Vec<Option<Color>> = vec![
  22. num::FromPrimitive::from_u64(0),
  23. num::FromPrimitive::from_u64(1),
  24. num::FromPrimitive::from_u64(2),
  25. num::FromPrimitive::from_u64(3),
  26. ];
  27. assert_eq!(
  28. v,
  29. vec![Some(Color::Red), Some(Color::Blue), Some(Color::Green), None]
  30. );
  31. }