]> git.proxmox.com Git - rustc.git/blame - src/vendor/conv/tests/derive_try_from.rs
New upstream version 1.22.1+dfsg1
[rustc.git] / src / vendor / conv / tests / derive_try_from.rs
CommitLineData
ea8adc8c
XL
1#[macro_use] extern crate conv;\r
2\r
3use conv::{TryFrom, Unrepresentable};\r
4\r
5#[derive(Debug, PartialEq)]\r
6enum Get { Up, Down, AllAround }\r
7\r
8TryFrom! { (u8)\r
9 enum Get {\r
10 Up,\r
11 /// And\r
12 Down,\r
13 /** And */\r
14 AllAround\r
15 }\r
16}\r
17\r
18#[derive(Debug, PartialEq)]\r
19enum GottaGo { GetAway, Fast = 9000, Faster = 9001 }\r
20\r
21TryFrom! { (u16)\r
22 enum GottaGo {\r
23 GetAway,\r
24 Fast = 9000,\r
25 /// This show was stupid.\r
26 Faster = 9001\r
27 }\r
28}\r
29\r
30#[test]\r
31fn test_try_from() {\r
32 assert_eq!(Get::try_from(0u8), Ok(Get::Up));\r
33 assert_eq!(Get::try_from(1u8), Ok(Get::Down));\r
34 assert_eq!(Get::try_from(2u8), Ok(Get::AllAround));\r
35 assert_eq!(Get::try_from(3u8), Err(Unrepresentable(3u8)));\r
36\r
37 assert_eq!(GottaGo::try_from(0u16), Ok(GottaGo::GetAway));\r
38 assert_eq!(GottaGo::try_from(1u16), Err(Unrepresentable(1u16)));\r
39 assert_eq!(GottaGo::try_from(2u16), Err(Unrepresentable(2u16)));\r
40 assert_eq!(GottaGo::try_from(3u16), Err(Unrepresentable(3u16)));\r
41 assert_eq!(GottaGo::try_from(8999u16), Err(Unrepresentable(8999u16)));\r
42 assert_eq!(GottaGo::try_from(9000u16), Ok(GottaGo::Fast));\r
43 assert_eq!(GottaGo::try_from(9001u16), Ok(GottaGo::Faster));\r
44 assert_eq!(GottaGo::try_from(9002u16), Err(Unrepresentable(9002u16)));\r
45}\r