forked from mirror/Riven
1
0
Fork 0

Add special parsing for `GameType`s missing `_GAME` suffix, add tests

https://github.com/RiotGames/developer-relations/issues/878
v/2.x.x
Mingwei Samuel 2024-01-15 11:34:37 -08:00
parent 2c284d860c
commit 172bc84620
2 changed files with 30 additions and 0 deletions

View File

@ -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());
}

View File

@ -16,12 +16,18 @@ pub enum GameType {
{{ {{
for (const e of gameTypes) { for (const e of gameTypes) {
const desc = e['x-desc'] ? e['x-desc'].split('\n') : []; const desc = e['x-desc'] ? e['x-desc'].split('\n') : [];
const nameNoGame = e['x-name'].replace(/_GAME$/, "");
}} }}
{{~ desc :line }} {{~ desc :line }}
/// {{= line }} /// {{= line }}
{{~}} {{~}}
#[strum(to_string = "{{= e['x-name'] }}", serialize = "{{= nameNoGame }}")]
#[serde(alias = "{{= nameNoGame }}")]
{{= e['x-name'] }}, {{= e['x-name'] }},
{{ {{
} }
}} }}
} }
#[cfg(test)]
mod test;