From 172bc84620f07d1aaaf06bb3bfc930764dd90832 Mon Sep 17 00:00:00 2001 From: Mingwei Samuel Date: Mon, 15 Jan 2024 11:34:37 -0800 Subject: [PATCH] Add special parsing for `GameType`s missing `_GAME` suffix, add tests https://github.com/RiotGames/developer-relations/issues/878 --- riven/src/consts/game_type/test.rs | 24 ++++++++++++++++++++++++ riven/srcgen/consts/game_type.rs.dt | 6 ++++++ 2 files changed, 30 insertions(+) create mode 100644 riven/src/consts/game_type/test.rs diff --git a/riven/src/consts/game_type/test.rs b/riven/src/consts/game_type/test.rs new file mode 100644 index 0000000..05516f1 --- /dev/null +++ b/riven/src/consts/game_type/test.rs @@ -0,0 +1,24 @@ +use super::*; + +#[test] +fn check_as_ref() { + assert_eq!("MATCHED_GAME", GameType::MATCHED_GAME.as_ref()); +} + +#[test] +fn check_to_string() { + assert_eq!("MATCHED_GAME", GameType::MATCHED_GAME.to_string()); +} + +#[test] +fn check_from_string() { + assert_eq!(Ok(GameType::MATCHED_GAME), "MATCHED_GAME".parse()); + assert_eq!(Ok(GameType::MATCHED_GAME), "MATCHED".parse()); +} + +#[test] +fn check_serialize() { + assert_eq!(Some("\"MATCHED_GAME\""), + serde_json::to_string(&GameType::MATCHED_GAME) + .ok().as_deref()); +} diff --git a/riven/srcgen/consts/game_type.rs.dt b/riven/srcgen/consts/game_type.rs.dt index 4ac61e3..5cf4dde 100644 --- a/riven/srcgen/consts/game_type.rs.dt +++ b/riven/srcgen/consts/game_type.rs.dt @@ -16,12 +16,18 @@ pub enum GameType { {{ for (const e of gameTypes) { const desc = e['x-desc'] ? e['x-desc'].split('\n') : []; + const nameNoGame = e['x-name'].replace(/_GAME$/, ""); }} {{~ desc :line }} /// {{= line }} {{~}} + #[strum(to_string = "{{= e['x-name'] }}", serialize = "{{= nameNoGame }}")] + #[serde(alias = "{{= nameNoGame }}")] {{= e['x-name'] }}, {{ } }} } + +#[cfg(test)] +mod test;