From e933030b80e723390882b79997248814046263a0 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Thu, 4 Aug 2022 21:07:27 +0200 Subject: [PATCH] Add more tests and fix things based on them --- Cargo.toml | 2 +- src/schema/corebundle/globals.rs | 94 ++++++++++++++++++++++++++++++ src/schema/corebundle/keyword.rs | 26 +++++++++ src/schema/corebundle/rarity.rs | 24 ++++++++ src/schema/corebundle/region.rs | 28 +++++++++ src/schema/corebundle/set.rs | 32 +++++++++- src/schema/corebundle/speed.rs | 24 ++++++++ src/schema/corebundle/vocabterm.rs | 26 ++++++++- src/schema/setbundle/card.rs | 2 + src/schema/setbundle/rarity.rs | 6 +- 10 files changed, 256 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6325207..c1a5882 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ log = { version = "0.4.17" } pretty_env_logger = { version = "0.4.0", optional = true } glob = { version = "0.3.0", optional = true } # schema -serde = { version = "1.0.140" } +serde = { version = "1.0.140", features = ["derive"] } serde_json = { version = "1.0.82" } # search tantivy = { version = "0.18.0", optional = true } diff --git a/src/schema/corebundle/globals.rs b/src/schema/corebundle/globals.rs index 122a524..197fca3 100644 --- a/src/schema/corebundle/globals.rs +++ b/src/schema/corebundle/globals.rs @@ -25,4 +25,98 @@ pub struct CoreGlobals { /// A [Vec] of all [CoreRarity]s in the game. pub rarities: Vec, +} + + +#[cfg(test)] +mod tests { + use crate::schema::corebundle::*; + use crate::schema::setbundle::*; + + #[test] + fn deserialize() { + assert_eq!( + serde_json::de::from_str::<'static, CoreGlobals>(r#" + { + "vocabTerms": [ + { + "description": "When you summon this, it gets its allegiance bonus if the top card of your deck matches its region.", + "name": "Allegiance", + "nameRef": "Allegiance" + } + ], + "keywords": [ + { + "description": "Inflicts damage beyond what would kill the target(s) to the enemy Nexus.", + "name": "Overwhelm", + "nameRef": "SpellOverwhelm" + } + ], + "regions": [ + { + "abbreviation": "NX", + "iconAbsolutePath": "http://dd.b.pvp.net/3_11_0/core/en_us/img/regions/icon-noxus.png", + "name": "Noxus", + "nameRef": "Noxus" + } + ], + "spellSpeeds": [ + { + "name": "Slow", + "nameRef": "Slow" + } + ], + "rarities": [ + { + "name": "COMMON", + "nameRef": "Common" + } + ], + "sets": [ + { + "iconAbsolutePath": "http://dd.b.pvp.net/3_11_0/core/en_us/img/sets/set3_crispmip.png", + "name": "Call of the Mountain", + "nameRef": "Set3" + } + ] + } + "#).unwrap(), + CoreGlobals { + vocab_terms: vec![ + CoreVocabTerm { + vocabterm: "Allegiance".to_string(), + name: "Allegiance".to_string(), + description: "When you summon this, it gets its allegiance bonus if the top card of your deck matches its region.".to_string(), + } + ], + keywords: vec![ + CoreKeyword { + keyword: CardKeyword::SpellOverwhelm, + name: "Overwhelm".to_string(), + description: "Inflicts damage beyond what would kill the target(s) to the enemy Nexus.".to_string(), + } + ], + regions: vec![ + CoreRegion { + region: CardRegion::Noxus, + name: "Noxus".to_string(), + abbreviation: "NX".to_string(), + icon_png: "http://dd.b.pvp.net/3_11_0/core/en_us/img/regions/icon-noxus.png".to_string(), + } + ], + spell_speeds: vec![ + CoreSpellSpeed { + spell_speed: SpellSpeed::Slow, + name: "Slow".to_string(), + } + ], + rarities: vec![ + CoreRarity { + rarity: CardRarity::Common, + name: "COMMON".to_string(), + } + ], + } + ) + } } \ No newline at end of file diff --git a/src/schema/corebundle/keyword.rs b/src/schema/corebundle/keyword.rs index 699574a..4a2c4e8 100644 --- a/src/schema/corebundle/keyword.rs +++ b/src/schema/corebundle/keyword.rs @@ -15,3 +15,29 @@ pub struct CoreKeyword { /// The description of the keyword, the text of the in-game tooltip. pub description: String, } + + +#[cfg(test)] +mod tests { + use crate::schema::setbundle::CardKeyword; + + use super::CoreKeyword; + + #[test] + fn deserialize() { + assert_eq!( + serde_json::de::from_str::<'static, CoreKeyword>(r#" + { + "description": "Inflicts damage beyond what would kill the target(s) to the enemy Nexus.", + "name": "Overwhelm", + "nameRef": "SpellOverwhelm" + } + "#).unwrap(), + CoreKeyword { + keyword: CardKeyword::SpellOverwhelm, + name: "Overwhelm".to_string(), + description: "Inflicts damage beyond what would kill the target(s) to the enemy Nexus.".to_string(), + } + ); + } +} diff --git a/src/schema/corebundle/rarity.rs b/src/schema/corebundle/rarity.rs index 73610e0..af0b162 100644 --- a/src/schema/corebundle/rarity.rs +++ b/src/schema/corebundle/rarity.rs @@ -12,3 +12,27 @@ pub struct CoreRarity { /// The localized name of the rarity. pub name: String, } + + +#[cfg(test)] +mod tests { + use crate::schema::setbundle::CardRarity; + + use super::CoreRarity; + + #[test] + fn deserialize() { + assert_eq!( + serde_json::de::from_str::<'static, CoreRarity>(r#" + { + "name": "COMMON", + "nameRef": "Common" + } + "#).unwrap(), + CoreRarity { + rarity: CardRarity::Common, + name: "COMMON".to_string(), + } + ); + } +} diff --git a/src/schema/corebundle/region.rs b/src/schema/corebundle/region.rs index 451698b..cda127d 100644 --- a/src/schema/corebundle/region.rs +++ b/src/schema/corebundle/region.rs @@ -21,3 +21,31 @@ pub struct CoreRegion { #[serde(rename = "iconAbsolutePath")] pub icon_png: String, } + + +#[cfg(test)] +mod tests { + use crate::schema::setbundle::CardRegion; + + use super::CoreRegion; + + #[test] + fn deserialize() { + assert_eq!( + serde_json::de::from_str::<'static, CoreRegion>(r#" + { + "abbreviation": "NX", + "iconAbsolutePath": "http://dd.b.pvp.net/3_11_0/core/en_us/img/regions/icon-noxus.png", + "name": "Noxus", + "nameRef": "Noxus" + } + "#).unwrap(), + CoreRegion { + region: CardRegion::Noxus, + name: "Noxus".to_string(), + abbreviation: "NX".to_string(), + icon_png: "http://dd.b.pvp.net/3_11_0/core/en_us/img/regions/icon-noxus.png".to_string(), + } + ); + } +} diff --git a/src/schema/corebundle/set.rs b/src/schema/corebundle/set.rs index 174dd8e..d4a7bfa 100644 --- a/src/schema/corebundle/set.rs +++ b/src/schema/corebundle/set.rs @@ -7,12 +7,38 @@ use crate::schema::setbundle::CardSet; pub struct CoreSet { /// The [CardSet] these strings refer to. #[serde(rename = "nameRef")] - set: CardSet, + pub set: CardSet, /// The localized name of the set. - name: String, + pub name: String, /// URL to the icon of the set in `.png` format. #[serde(rename = "iconAbsolutePath")] - icon_png: String, + pub icon_png: String, +} + + +#[cfg(test)] +mod tests { + use crate::schema::setbundle::CardSet; + + use super::CoreSet; + + #[test] + fn deserialize() { + assert_eq!( + serde_json::de::from_str::<'static, CoreSet>(r#" + { + "iconAbsolutePath": "http://dd.b.pvp.net/3_11_0/core/en_us/img/sets/set3_crispmip.png", + "name": "Call of the Mountain", + "nameRef": "Set3" + } + "#).unwrap(), + CoreSet { + set: CardSet::CallOfTheMountain, + name: "Call of the Mountain".to_string(), + icon_png: "http://dd.b.pvp.net/3_11_0/core/en_us/img/sets/set3_crispmip.png".to_string(), + } + ); + } } diff --git a/src/schema/corebundle/speed.rs b/src/schema/corebundle/speed.rs index bc84568..fbeca2a 100644 --- a/src/schema/corebundle/speed.rs +++ b/src/schema/corebundle/speed.rs @@ -12,3 +12,27 @@ pub struct CoreSpellSpeed { /// The localized name of the spell speed. pub name: String, } + + +#[cfg(test)] +mod tests { + use crate::schema::setbundle::SpellSpeed; + + use super::CoreSpellSpeed; + + #[test] + fn deserialize() { + assert_eq!( + serde_json::de::from_str::<'static, CoreSpellSpeed>(r#" + { + "name": "Slow", + "nameRef": "Slow" + } + "#).unwrap(), + CoreSpellSpeed { + spell_speed: SpellSpeed::Slow, + name: "Slow".to_string(), + } + ); + } +} diff --git a/src/schema/corebundle/vocabterm.rs b/src/schema/corebundle/vocabterm.rs index ddf8580..77a3a1c 100644 --- a/src/schema/corebundle/vocabterm.rs +++ b/src/schema/corebundle/vocabterm.rs @@ -19,4 +19,28 @@ pub struct CoreVocabTerm { /// The description of the vocabulary term, the text of the in-game tooltip. pub description: String, -} \ No newline at end of file +} + + +#[cfg(test)] +mod tests { + use super::CoreVocabTerm; + + #[test] + fn deserialize() { + assert_eq!( + serde_json::de::from_str::<'static, CoreVocabTerm>(r#" + { + "description": "When you summon this, it gets its allegiance bonus if the top card of your deck matches its region.", + "name": "Allegiance", + "nameRef": "Allegiance" + } + "#).unwrap(), + CoreVocabTerm { + vocabterm: "Allegiance".to_string(), + name: "Allegiance".to_string(), + description: "When you summon this, it gets its allegiance bonus if the top card of your deck matches its region.".to_string(), + } + ); + } +} diff --git a/src/schema/setbundle/card.rs b/src/schema/setbundle/card.rs index 0b5ea24..6e7b067 100644 --- a/src/schema/setbundle/card.rs +++ b/src/schema/setbundle/card.rs @@ -120,9 +120,11 @@ pub struct Card { pub(crate) associated_card_names_localized: Vec, /// Flavor text of the card, displayed when its image is inspected. + #[serde(rename = "flavorText")] pub flavor_text: String, /// Name of the artist who drew the card. + #[serde(rename = "artistName")] pub artist_name: String, /// The subtypes the card has, such as `"PORO"`. diff --git a/src/schema/setbundle/rarity.rs b/src/schema/setbundle/rarity.rs index 3b32242..4427ade 100644 --- a/src/schema/setbundle/rarity.rs +++ b/src/schema/setbundle/rarity.rs @@ -49,9 +49,9 @@ mod tests { } test_deserialization!(deserialize_none, r#""None""#, CardRarity::None); - test_deserialization!(deserialize_common, r#""COMMON""#, CardRarity::Common); - test_deserialization!(deserialize_rare, r#""RARE""#, CardRarity::Rare); - test_deserialization!(deserialize_epic, r#""EPIC""#, CardRarity::Epic); + test_deserialization!(deserialize_common, r#""Common""#, CardRarity::Common); + test_deserialization!(deserialize_rare, r#""Rare""#, CardRarity::Rare); + test_deserialization!(deserialize_epic, r#""Epic""#, CardRarity::Epic); test_deserialization!(deserialize_champion, r#""Champion""#, CardRarity::Champion); #[test]