From 2e52b03c63d774145fef80a45117b5c76826d01f Mon Sep 17 00:00:00 2001 From: Mingwei Samuel Date: Mon, 20 Jun 2022 19:29:34 -0700 Subject: [PATCH] Add `QueueType` tests for serde & unknown variants --- riven/src/consts/queue_type.rs | 36 +++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/riven/src/consts/queue_type.rs b/riven/src/consts/queue_type.rs index be44660..65b687b 100644 --- a/riven/src/consts/queue_type.rs +++ b/riven/src/consts/queue_type.rs @@ -46,6 +46,40 @@ mod test { #[test] fn check_from_string() { - assert_eq!(Some(QueueType::RANKED_SOLO_5x5), "RANKED_SOLO_5x5".parse().ok()); + assert_eq!(QueueType::RANKED_SOLO_5x5, "RANKED_SOLO_5x5".into()); + assert_eq!(QueueType::UNKNOWN("RANKED_MYSTERY_UNKNOWN".to_owned()), "RANKED_MYSTERY_UNKNOWN".into()); + assert_eq!("RANKED_MYSTERY_UNKNOWN", QueueType::UNKNOWN("RANKED_MYSTERY_UNKNOWN".to_owned()).as_ref()); + } + + #[test] + fn check_serialize() { + assert_eq!(Some("\"RANKED_TFT_DOUBLE_UP\""), + serde_json::to_string(&QueueType::RANKED_TFT_DOUBLE_UP) + .ok().as_deref()); + assert_eq!(Some("\"RANKED_MYSTERY_UNKNOWN\""), + serde_json::to_string(&QueueType::UNKNOWN("RANKED_MYSTERY_UNKNOWN".to_owned())) + .ok().as_deref()); + } + + #[test] + fn check_deserialize() { + use std::collections::BTreeMap; + + let dict: BTreeMap = serde_json::from_str( + r#"{ + "100": "RANKED_SOLO_5x5", + "200": "RANKED_TFT_TURBO", + "210": "RANKED_TFT_DOUBLE_UP", + "211": "RANKED_TFT_PAIRS", + "900": "RANKED_MYSTERY_UNKNOWN" + }"# + ).unwrap(); + + assert_eq!(Some(&QueueType::RANKED_SOLO_5x5), dict.get(&100)); + assert_eq!(Some(&QueueType::RANKED_TFT_TURBO), dict.get(&200)); + assert_eq!(Some(&QueueType::RANKED_TFT_DOUBLE_UP), dict.get(&210)); + assert_eq!(Some(&QueueType::RANKED_TFT_PAIRS), dict.get(&211)); + assert_eq!(Some(&QueueType::UNKNOWN("RANKED_MYSTERY_UNKNOWN".to_owned())), dict.get(&900)); + } }