use behindthename::types::*; use Gender::*; #[test] fn test_serde_deserialize_gender() { match serde_json::from_str::(r#""m""#) { Ok(Male) => (), Ok(g) => panic!("{}", g), Err(e) => panic!("{}", e), } } #[test] fn test_from_str_gender() { match str::parse::("m") { Ok(Male) => (), Ok(g) => panic!("{}", g), Err(e) => panic!("{}", e), } match str::parse::("f") { Ok(Female) => (), Ok(g) => panic!("{}", g), Err(e) => panic!("{}", e), } match str::parse::("u") { Ok(Neutral) => (), Ok(g) => panic!("{}", g), Err(e) => panic!("{}", e), } match str::parse::("mf") { Ok(Ambiguous) => (), Ok(g) => panic!("{}", g), Err(e) => panic!("{}", e), } match str::parse::("fm") { Ok(Ambiguous) => (), Ok(g) => panic!("{}", g), Err(e) => panic!("{}", e), } match str::parse::("ynA") { Ok(Any) => panic!("shouldn't be able to create Any from \"ynA\""), Ok(g) => panic!("{}", g), Err(_) => (), } match str::parse::("Any") { Ok(Any) => (), Ok(g) => panic!("{}", g), Err(e) => panic!("{}", e), } } #[test] fn test_display_gender() { assert_eq!("m", format!("{}", Male)); assert_eq!("f", format!("{}", Female)); assert_eq!("u", format!("{}", Neutral)); assert_eq!("mf", format!("{}", Ambiguous)); assert_eq!("", format!("{}", Any)); }