Generate `queue_type.rs` from riotapi-schema version

pull/42/head
Mingwei Samuel 2022-06-21 00:09:08 -07:00
parent 713995491e
commit 3ae9f36888
4 changed files with 119 additions and 66 deletions

View File

@ -1,3 +1,11 @@
///////////////////////////////////////////////
// //
// ! //
// This file is automatically generated! //
// Do not directly edit! //
// //
///////////////////////////////////////////////
use strum_macros::{ EnumString, EnumVariantNames, IntoStaticStr }; use strum_macros::{ EnumString, EnumVariantNames, IntoStaticStr };
/// LoL or TFT ranked queue types. /// LoL or TFT ranked queue types.
@ -5,83 +13,33 @@ use strum_macros::{ EnumString, EnumVariantNames, IntoStaticStr };
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
#[derive(Eq, PartialEq, Hash)] #[derive(Eq, PartialEq, Hash)]
#[derive(EnumString, EnumVariantNames, IntoStaticStr)] #[derive(EnumString, EnumVariantNames, IntoStaticStr)]
#[repr(u8)]
pub enum QueueType { pub enum QueueType {
/// Catch-all variant for new, unknown queue types. /// Catch-all variant for new, unknown queue types.
#[strum(default)] #[strum(default)]
UNKNOWN(String), UNKNOWN(String),
/// League of Legends, Summoner's Rift (5v5), Ranked Solo Queue. /// 5v5 Ranked Solo games
RANKED_SOLO_5x5, RANKED_SOLO_5x5,
/// League of Legends, Summoner's Rift (5v5), Flex Queue. /// 5v5 Ranked Flex games
RANKED_FLEX_SR, RANKED_FLEX_SR,
/// League of Legends, Twisted Treeline (3v3), Flex Queue. /// 3v3 Ranked Flex games
/// Deprecated in patch 9.23
#[deprecated(note="Deprecated in patch 9.23")]
RANKED_FLEX_TT, RANKED_FLEX_TT,
/// Ranked Teamfight Tactics. /// Ranked Teamfight Tactics games
RANKED_TFT, RANKED_TFT,
/// Ranked Teamfight Tactics, Hyper Roll gamemode. /// Ranked Teamfight Tactics (Hyper Roll) games
RANKED_TFT_TURBO, RANKED_TFT_TURBO,
/// Ranked Teamfight Tactics, Double Up gamemode. /// Ranked Teamfight Tactics (Double Up Workshop) games
RANKED_TFT_DOUBLE_UP, /// Deprecated in patch 12.11 in favor of queueId 1160
#[deprecated(note="Deprecated in patch 12.11 in favor of queueId 1160")]
/// Ranked Teamfight Tactics, OLD Double Up gamemode. Changed some time before June 2022.
#[deprecated(note="Use RANKED_TFT_DOUBLE_UP instead.")]
RANKED_TFT_PAIRS, RANKED_TFT_PAIRS,
/// Ranked Teamfight Tactics (Double Up Workshop) games
RANKED_TFT_DOUBLE_UP,
} }
serde_strum_unknown!(QueueType); serde_strum_unknown!(QueueType);
#[cfg(test)] #[cfg(test)]
mod test { mod test;
use super::*;
#[test]
fn check_as_ref() {
assert_eq!("RANKED_SOLO_5x5", QueueType::RANKED_SOLO_5x5.as_ref());
}
#[test]
fn check_to_string() {
assert_eq!("RANKED_SOLO_5x5", QueueType::RANKED_SOLO_5x5.to_string());
}
#[test]
fn check_from_string() {
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]
// Note: this test is often not run due to this condition below.
#[cfg(not(feature = "deny-unknown-enum-variants-strings"))]
fn check_deserialize() {
use std::collections::BTreeMap;
let dict: BTreeMap<usize, QueueType> = 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));
}
}

View File

@ -0,0 +1,52 @@
use super::*;
#[test]
fn check_as_ref() {
assert_eq!("RANKED_SOLO_5x5", QueueType::RANKED_SOLO_5x5.as_ref());
}
#[test]
fn check_to_string() {
assert_eq!("RANKED_SOLO_5x5", QueueType::RANKED_SOLO_5x5.to_string());
}
#[test]
fn check_from_string() {
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]
// Note: this test is often not run due to this condition below.
#[cfg(not(feature = "deny-unknown-enum-variants-strings"))]
fn check_deserialize() {
use std::collections::BTreeMap;
let dict: BTreeMap<usize, QueueType> = 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));
}

View File

@ -0,0 +1,39 @@
{{
const dotUtils = require('./dotUtils.js');
const queueTypes = require('./.queueTypes.json');
}}{{= dotUtils.preamble() }}
use strum_macros::{ EnumString, EnumVariantNames, IntoStaticStr };
/// LoL or TFT ranked queue types.
#[non_exhaustive]
#[derive(Debug, Clone)]
#[derive(Eq, PartialEq, Hash)]
#[derive(EnumString, EnumVariantNames, IntoStaticStr)]
#[repr(u8)]
pub enum QueueType {
/// Catch-all variant for new, unknown queue types.
#[strum(default)]
UNKNOWN(String),
{{
for (const e of queueTypes) {
const desc = e['x-desc'] ? e['x-desc'].split('\n') : [];
}}
{{~ desc :line }}
/// {{= line }}
{{~}}
{{? e['x-deprecated'] }}
/// {{= e.notes }}
#[deprecated(note="{{= e.notes }}")]
{{?}}
{{= e['x-name'] }},
{{
}
}}
}
serde_strum_unknown!(QueueType);
#[cfg(test)]
mod test;

View File

@ -23,6 +23,10 @@ const files = [
'http://www.mingweisamuel.com/riotapi-schema/enums/queues.json', 'http://www.mingweisamuel.com/riotapi-schema/enums/queues.json',
'.queues.json' '.queues.json'
], ],
[
'http://www.mingweisamuel.com/riotapi-schema/enums/queueTypes.json',
'.queueTypes.json'
],
[ [
'http://www.mingweisamuel.com/riotapi-schema/enums/gameTypes.json', 'http://www.mingweisamuel.com/riotapi-schema/enums/gameTypes.json',
'.gameTypes.json' '.gameTypes.json'
@ -34,8 +38,8 @@ const files = [
[ [
'http://www.mingweisamuel.com/riotapi-schema/enums/maps.json', 'http://www.mingweisamuel.com/riotapi-schema/enums/maps.json',
'.maps.json' '.maps.json'
] ],
] ];
const downloadFilesPromise = Promise.all(files.map(([url, file]) => req(url) const downloadFilesPromise = Promise.all(files.map(([url, file]) => req(url)
.then(body => fs.writeFileAsync(file, body, "utf8")))); .then(body => fs.writeFileAsync(file, body, "utf8"))));