mirror of
https://github.com/Steffo99/patched-porobot.git
synced 2024-12-23 01:54:22 +00:00
Write tests and fix things here and there
This commit is contained in:
parent
1135f5b09c
commit
83803be3e8
8 changed files with 271 additions and 13 deletions
|
@ -1,7 +1,7 @@
|
||||||
//! Module defining [CardArt].
|
//! Module defining [CardArt].
|
||||||
|
|
||||||
/// An art asset associated with a [Card].
|
/// An art asset associated with a [Card].
|
||||||
#[derive(serde::Serialize, serde::Deserialize, Clone, Debug)]
|
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct CardArt {
|
pub struct CardArt {
|
||||||
/// URL to the `.png` image of the rendered card.
|
/// URL to the `.png` image of the rendered card.
|
||||||
///
|
///
|
||||||
|
@ -51,4 +51,32 @@ impl CardArt {
|
||||||
.replace("https://dd.b.pvp.net/latest/set1", "https://poro.steffo.eu/set1-en_us")
|
.replace("https://dd.b.pvp.net/latest/set1", "https://poro.steffo.eu/set1-en_us")
|
||||||
.replace(".png", ".jpg")
|
.replace(".png", ".jpg")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::CardArt;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn deserialize() {
|
||||||
|
assert_eq!(
|
||||||
|
serde_json::de::from_str::<'static, CardArt>(r#"{"gameAbsolutePath": https://dd.b.pvp.net/latest/set1/en_us/img/cards/01DE001.png, "fullAbsolutePath": "https://dd.b.pvp.net/latest/set1/en_us/img/cards/01DE001-full.png"}"#).unwrap(),
|
||||||
|
CardArt {
|
||||||
|
card_png: "https://dd.b.pvp.net/latest/set1/en_us/img/cards/01DE001.png",
|
||||||
|
full_png: "https://dd.b.pvp.net/latest/set1/en_us/img/cards/01DE001-full.png",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn png_to_jpg() {
|
||||||
|
let art = CardArt {
|
||||||
|
card_png: "https://dd.b.pvp.net/latest/set1/en_us/img/cards/01DE001.png",
|
||||||
|
full_png: "https://dd.b.pvp.net/latest/set1/en_us/img/cards/01DE001-full.png",
|
||||||
|
};
|
||||||
|
|
||||||
|
assert_eq!(art.card_jpg(), "https://poro.steffo.eu/set1-en_us/en_us/img/cards/01DE001.jpg");
|
||||||
|
assert_eq!(art.full_jpg(), "https://poro.steffo.eu/set1-en_us/en_us/img/cards/01DE001-full.jpg");
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -10,7 +10,7 @@ use super::rarity::CardRarity;
|
||||||
use super::speed::SpellSpeed;
|
use super::speed::SpellSpeed;
|
||||||
|
|
||||||
/// A single Legends of Runeterra card as represented in the data files from [Data Dragon](https://developer.riotgames.com/docs/lor).
|
/// A single Legends of Runeterra card as represented in the data files from [Data Dragon](https://developer.riotgames.com/docs/lor).
|
||||||
#[derive(serde::Serialize, serde::Deserialize, Clone, Debug)]
|
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||||
#[serde(rename_all="camelCase")]
|
#[serde(rename_all="camelCase")]
|
||||||
pub struct Card {
|
pub struct Card {
|
||||||
/// Unique seven-character identifier of the card.
|
/// Unique seven-character identifier of the card.
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
///
|
///
|
||||||
/// Since more keywords will probably be added in the future, this enum is [non_exaustive](https://doc.rust-lang.org/reference/attributes/type_system.html#the-non_exhaustive-attribute).
|
/// Since more keywords will probably be added in the future, this enum is [non_exaustive](https://doc.rust-lang.org/reference/attributes/type_system.html#the-non_exhaustive-attribute).
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
#[derive(serde::Serialize, serde::Deserialize, Clone, Debug)]
|
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||||
pub enum CardKeyword {
|
pub enum CardKeyword {
|
||||||
/// Overwhelm on spells.
|
/// Overwhelm on spells.
|
||||||
///
|
///
|
||||||
|
@ -331,3 +331,89 @@ pub enum CardKeyword {
|
||||||
#[serde(other)]
|
#[serde(other)]
|
||||||
Unsupported,
|
Unsupported,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::CardKeyword;
|
||||||
|
|
||||||
|
macro_rules! test_deserialization {
|
||||||
|
( $id:ident, $src:literal, $res:expr ) => {
|
||||||
|
#[test]
|
||||||
|
fn $id() {
|
||||||
|
assert_eq!(serde_json::de::from_str::<'static, CardKeyword>($src).unwrap(), $res);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
test_deserialization!(deserialize_spelloverwhelm, "SpellOverwhelm", CardKeyword::SpellOverwhelm);
|
||||||
|
test_deserialization!(deserialize_burst, "Burst", CardKeyword::Burst);
|
||||||
|
test_deserialization!(deserialize_countdown, "Countdown", CardKeyword::Countdown);
|
||||||
|
test_deserialization!(deserialize_onplay, "PlaySkillMark", CardKeyword::OnPlay);
|
||||||
|
test_deserialization!(deserialize_landmark, "LandmarkVisualOnly", CardKeyword::Landmark);
|
||||||
|
test_deserialization!(deserialize_shurima, "Shurima", CardKeyword::Shurima);
|
||||||
|
test_deserialization!(deserialize_attach, "Attach", CardKeyword::Attach);
|
||||||
|
test_deserialization!(deserialize_noxus, "Noxus", CardKeyword::Noxus);
|
||||||
|
test_deserialization!(deserialize_fleeting, "Fleeting", CardKeyword::Fleeting);
|
||||||
|
test_deserialization!(deserialize_clobbernoemptyslotrequirement, "ClobberNoEmptySlotRequirement", CardKeyword::ClobberNoEmptySlotRequirement);
|
||||||
|
test_deserialization!(deserialize_nab, "Nab", CardKeyword::Nab);
|
||||||
|
test_deserialization!(deserialize_focus, "Focus", CardKeyword::Focus);
|
||||||
|
test_deserialization!(deserialize_enlightened, "Enlightened", CardKeyword::Enlightened);
|
||||||
|
test_deserialization!(deserialize_invoke, "Invoke", CardKeyword::Invoke);
|
||||||
|
test_deserialization!(deserialize_boon, "Boon", CardKeyword::Boon);
|
||||||
|
test_deserialization!(deserialize_trap, "Autoplay", CardKeyword::Trap);
|
||||||
|
test_deserialization!(deserialize_drain, "Drain", CardKeyword::Drain);
|
||||||
|
test_deserialization!(deserialize_lastbreath, "LastBreath", CardKeyword::LastBreath);
|
||||||
|
test_deserialization!(deserialize_demacia, "Demacia", CardKeyword::Demacia);
|
||||||
|
test_deserialization!(deserialize_bandlecity, "BandleCity", CardKeyword::BandleCity);
|
||||||
|
test_deserialization!(deserialize_fast, "Fast", CardKeyword::Fast);
|
||||||
|
test_deserialization!(deserialize_bilgewater, "Bilgewater", CardKeyword::Bilgewater);
|
||||||
|
test_deserialization!(deserialize_runeterra, "Runeterra", CardKeyword::Runeterra);
|
||||||
|
test_deserialization!(deserialize_recall, "Recall", CardKeyword::Recall);
|
||||||
|
test_deserialization!(deserialize_weakest, "Weakest", CardKeyword::Weakest);
|
||||||
|
test_deserialization!(deserialize_support, "Support", CardKeyword::Support);
|
||||||
|
test_deserialization!(deserialize_slow, "Slow", CardKeyword::Slow);
|
||||||
|
test_deserialization!(deserialize_obliterate, "Obliterate", CardKeyword::Obliterate);
|
||||||
|
test_deserialization!(deserialize_imbue, "Imbue", CardKeyword::Imbue);
|
||||||
|
test_deserialization!(deserialize_targon, "MtTargon", CardKeyword::Targon);
|
||||||
|
test_deserialization!(deserialize_shadowisles, "ShadowIsles", CardKeyword::ShadowIsles);
|
||||||
|
test_deserialization!(deserialize_auravisualfakekeyword, "AuraVisualFakeKeyword", CardKeyword::AuraVisualFakeKeyword);
|
||||||
|
test_deserialization!(deserialize_ionia, "Ionia", CardKeyword::Ionia);
|
||||||
|
test_deserialization!(deserialize_nightfall, "Nightfall", CardKeyword::Nightfall);
|
||||||
|
test_deserialization!(deserialize_piltoverzaun, "PiltoverZaun", CardKeyword::PiltoverZaun);
|
||||||
|
test_deserialization!(deserialize_attune, "Attune", CardKeyword::Attune);
|
||||||
|
test_deserialization!(deserialize_daybreak, "Daybreak", CardKeyword::Daybreak);
|
||||||
|
test_deserialization!(deserialize_silenceindividualkeyword, "SilenceIndividualKeyword", CardKeyword::SilenceIndividualKeyword);
|
||||||
|
test_deserialization!(deserialize_skill, "Skill", CardKeyword::Skill);
|
||||||
|
test_deserialization!(deserialize_plunder, "Plunder", CardKeyword::Plunder);
|
||||||
|
test_deserialization!(deserialize_doubleattack, "DoubleAttack", CardKeyword::DoubleAttack);
|
||||||
|
test_deserialization!(deserialize_vulnerable, "Vulnerable", CardKeyword::Vulnerable);
|
||||||
|
test_deserialization!(deserialize_elusive, "Elusive", CardKeyword::Elusive);
|
||||||
|
test_deserialization!(deserialize_stun, "Stun", CardKeyword::Stun);
|
||||||
|
test_deserialization!(deserialize_fated, "Fated", CardKeyword::Fated);
|
||||||
|
test_deserialization!(deserialize_blockelusive, "BlockElusive", CardKeyword::BlockElusive);
|
||||||
|
test_deserialization!(deserialize_fury, "Fury", CardKeyword::Fury);
|
||||||
|
test_deserialization!(deserialize_barrier, "Barrier", CardKeyword::Barrier);
|
||||||
|
test_deserialization!(deserialize_immobile, "Immobile", CardKeyword::Immobile);
|
||||||
|
test_deserialization!(deserialize_hallowed, "Hallowed", CardKeyword::Hallowed);
|
||||||
|
test_deserialization!(deserialize_evolve, "Evolve", CardKeyword::Evolve);
|
||||||
|
test_deserialization!(deserialize_frostbite, "Frostbite", CardKeyword::Frostbite);
|
||||||
|
test_deserialization!(deserialize_overwhelm, "Overwhelm", CardKeyword::Overwhelm);
|
||||||
|
test_deserialization!(deserialize_quickattack, "QuickStrike", CardKeyword::QuickAttack);
|
||||||
|
test_deserialization!(deserialize_tough, "Tough", CardKeyword::Tough);
|
||||||
|
test_deserialization!(deserialize_regeneration, "Regeneration", CardKeyword::Regeneration);
|
||||||
|
test_deserialization!(deserialize_silenced, "Silenced", CardKeyword::Silenced);
|
||||||
|
test_deserialization!(deserialize_spellshield, "SpellShield", CardKeyword::SpellShield);
|
||||||
|
test_deserialization!(deserialize_lifesteal, "Lifesteal", CardKeyword::Lifesteal);
|
||||||
|
test_deserialization!(deserialize_augment, "Augment", CardKeyword::Augment);
|
||||||
|
test_deserialization!(deserialize_impact, "Impact", CardKeyword::Impact);
|
||||||
|
test_deserialization!(deserialize_scout, "Scout", CardKeyword::Scout);
|
||||||
|
test_deserialization!(deserialize_ephemeral, Ephemeral, CardKeyword::Ephemeral);
|
||||||
|
test_deserialization!(deserialize_lurk, Lurker, CardKeyword::Lurk);
|
||||||
|
test_deserialization!(deserialize_formidable, Formidable, CardKeyword::Formidable);
|
||||||
|
test_deserialization!(deserialize_challenger, Challenger, CardKeyword::Challenger);
|
||||||
|
test_deserialization!(deserialize_fearsome, Fearsome, CardKeyword::Fearsome);
|
||||||
|
test_deserialization!(deserialize_cantblock, CantBlock, CardKeyword::CantBlock);
|
||||||
|
test_deserialization!(deserialize_deep, Deep, CardKeyword::Deep);
|
||||||
|
test_deserialization!(deserialize_unsupported, Unsupported, CardKeyword::Unsupported);
|
||||||
|
}
|
||||||
|
|
|
@ -1,21 +1,48 @@
|
||||||
//! Module defining [CardRarity].
|
//! Module defining [CardRarity].
|
||||||
|
|
||||||
/// A possible card rarity.
|
/// A possible card rarity.
|
||||||
#[derive(serde::Serialize, serde::Deserialize, Clone, Debug)]
|
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||||
pub enum CardRarity {
|
pub enum CardRarity {
|
||||||
/// The card has no rarity, as it probably is not collectible.
|
/// The card has no rarity, as it probably is not collectible.
|
||||||
|
#[serde(alias = "")]
|
||||||
#[serde(alias = "NONE")]
|
#[serde(alias = "NONE")]
|
||||||
None,
|
None,
|
||||||
/// A common card.
|
/// A common card.
|
||||||
#[serde(alias = "COMMON")]
|
#[serde(rename = "COMMON")]
|
||||||
Common,
|
Common,
|
||||||
/// A rare card.
|
/// A rare card.
|
||||||
#[serde(alias = "RARE")]
|
#[serde(rename = "RARE")]
|
||||||
Rare,
|
Rare,
|
||||||
/// An epic card.
|
/// An epic card.
|
||||||
#[serde(alias = "EPIC")]
|
#[serde(rename = "EPIC")]
|
||||||
Epic,
|
Epic,
|
||||||
/// A champion.
|
/// A champion.
|
||||||
#[serde(alias = "CHAMPION")]
|
#[serde(alias = "CHAMPION")]
|
||||||
Champion,
|
Champion,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::CardRarity;
|
||||||
|
|
||||||
|
macro_rules! test_deserialization {
|
||||||
|
( $id:ident, $src:literal, $res:expr ) => {
|
||||||
|
#[test]
|
||||||
|
fn $id() {
|
||||||
|
assert_eq!(serde_json::de::from_str::<'static, CardRarity>($src).unwrap(), $res);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
test_deserialization!(deserialize_none, "None", CardRarity::None);
|
||||||
|
test_deserialization!(deserialize_common, "COMMON", CardRarity::Common);
|
||||||
|
test_deserialization!(deserialize_rare, "RARE", CardRarity::Rare);
|
||||||
|
test_deserialization!(deserialize_epic, "EPIC", CardRarity::Epic);
|
||||||
|
test_deserialization!(deserialize_champion, "Champion", CardRarity::Champion);
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn deserialize_fallback() {
|
||||||
|
assert!(serde_json::de::from_str::<'static, CardRarity>("Xyzzy").is_err());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
///
|
///
|
||||||
/// Since more regions might be added in the future, especially Origin ones, this enum is [non_exaustive](https://doc.rust-lang.org/reference/attributes/type_system.html#the-non_exhaustive-attribute).
|
/// Since more regions might be added in the future, especially Origin ones, this enum is [non_exaustive](https://doc.rust-lang.org/reference/attributes/type_system.html#the-non_exhaustive-attribute).
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
#[derive(serde::Serialize, serde::Deserialize, Clone, Debug)]
|
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||||
pub enum CardRegion {
|
pub enum CardRegion {
|
||||||
/// Noxus.
|
/// Noxus.
|
||||||
Noxus,
|
Noxus,
|
||||||
|
@ -39,3 +39,33 @@ pub enum CardRegion {
|
||||||
#[serde(other)]
|
#[serde(other)]
|
||||||
Unsupported,
|
Unsupported,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::CardRegion;
|
||||||
|
|
||||||
|
macro_rules! test_deserialization {
|
||||||
|
( $id:ident, $src:literal, $res:expr ) => {
|
||||||
|
#[test]
|
||||||
|
fn $id() {
|
||||||
|
assert_eq!(serde_json::de::from_str::<'static, CardRegion>($src).unwrap(), $res);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
test_deserialization!(deserialize_noxus, "Noxus", CardRegion::Noxus);
|
||||||
|
test_deserialization!(deserialize_demacia, "Demacia", CardRegion::Demacia);
|
||||||
|
test_deserialization!(deserialize_freljord, "Freljord", CardRegion::Freljord);
|
||||||
|
test_deserialization!(deserialize_shadowisles, "ShadowIsles", CardRegion::ShadowIsles);
|
||||||
|
test_deserialization!(deserialize_targon, "Targon", CardRegion::Targon);
|
||||||
|
test_deserialization!(deserialize_ionia, "Ionia", CardRegion::Ionia);
|
||||||
|
test_deserialization!(deserialize_shurima, "Shurima", CardRegion::Shurima);
|
||||||
|
test_deserialization!(deserialize_piltoverzaun, "PiltoverZaun", CardRegion::PiltoverZaun);
|
||||||
|
test_deserialization!(deserialize_bandlecity, "BandleCity", CardRegion::BandleCity);
|
||||||
|
test_deserialization!(deserialize_runeterra, "Runeterra", CardRegion::Runeterra);
|
||||||
|
test_deserialization!(deserialize_jhin, "Jhin", CardRegion::Jhin);
|
||||||
|
test_deserialization!(deserialize_evelynn, "Evelynn", CardRegion::Evelynn);
|
||||||
|
test_deserialization!(deserialize_bard, "Bard", CardRegion::Bard);
|
||||||
|
test_deserialization!(deserialize_fallback, "Xyzzy", CardRegion::Unsupported);
|
||||||
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
///
|
///
|
||||||
/// Since more sets will definitely be added in the future, this enum is [non_exaustive](https://doc.rust-lang.org/reference/attributes/type_system.html#the-non_exhaustive-attribute).
|
/// Since more sets will definitely be added in the future, this enum is [non_exaustive](https://doc.rust-lang.org/reference/attributes/type_system.html#the-non_exhaustive-attribute).
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
#[derive(serde::Serialize, serde::Deserialize, Clone, Debug)]
|
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||||
pub enum CardSet {
|
pub enum CardSet {
|
||||||
/// Foundations, or "base".
|
/// Foundations, or "base".
|
||||||
#[serde(rename = "Set1")]
|
#[serde(rename = "Set1")]
|
||||||
|
@ -38,3 +38,27 @@ pub enum CardSet {
|
||||||
#[serde(other)]
|
#[serde(other)]
|
||||||
Unsupported,
|
Unsupported,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::CardSet;
|
||||||
|
|
||||||
|
macro_rules! test_deserialization {
|
||||||
|
( $id:ident, $src:literal, $res:expr ) => {
|
||||||
|
#[test]
|
||||||
|
fn $id() {
|
||||||
|
assert_eq!(serde_json::de::from_str::<'static, CardSet>($src).unwrap(), $res);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
test_deserialization!(deserialize_set1, "Set1", CardSet::Foundations);
|
||||||
|
test_deserialization!(deserialize_set2, "Set2", CardSet::RisingTides);
|
||||||
|
test_deserialization!(deserialize_set3, "Set3", CardSet::CallOfTheMountain);
|
||||||
|
test_deserialization!(deserialize_set4, "Set4", CardSet::EmpiresOfTheAscended);
|
||||||
|
test_deserialization!(deserialize_set5, "Set5", CardSet::BeyondTheBandlewood);
|
||||||
|
test_deserialization!(deserialize_set6, "Set6", CardSet::Worldwalker);
|
||||||
|
test_deserialization!(deserialize_setevent, "SetEvent", CardSet::Events);
|
||||||
|
test_deserialization!(deserialize_fallback, "Xyzzy", CardSet::Unsupported);
|
||||||
|
}
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
//! Module defining [SpellSpeed].
|
//! Module defining [SpellSpeed].
|
||||||
|
|
||||||
|
|
||||||
/// A possible spell speed.
|
/// A possible spell speed.
|
||||||
#[derive(serde::Serialize, serde::Deserialize, Clone, Debug)]
|
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||||
pub enum SpellSpeed {
|
pub enum SpellSpeed {
|
||||||
/// Non-spell cards have this speed.
|
/// Non-spell cards have this speed.
|
||||||
#[serde(alias = "")]
|
#[serde(rename = "")]
|
||||||
None,
|
None,
|
||||||
/// A Slow spell.
|
/// A Slow spell.
|
||||||
Slow,
|
Slow,
|
||||||
|
@ -12,4 +13,29 @@ pub enum SpellSpeed {
|
||||||
Fast,
|
Fast,
|
||||||
/// Either a Burst or a Focus spell; to disambiguate between the two, check for the `Focus` keyword.
|
/// Either a Burst or a Focus spell; to disambiguate between the two, check for the `Focus` keyword.
|
||||||
Burst,
|
Burst,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::SpellSpeed;
|
||||||
|
|
||||||
|
macro_rules! test_deserialization {
|
||||||
|
( $id:ident, $src:literal, $res:expr ) => {
|
||||||
|
#[test]
|
||||||
|
fn $id() {
|
||||||
|
assert_eq!(serde_json::de::from_str::<'static, SpellSpeed>($src).unwrap(), $res);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
test_deserialization!(deserialize_none, "", SpellSpeed::None);
|
||||||
|
test_deserialization!(deserialize_slow, "Slow", SpellSpeed::Slow);
|
||||||
|
test_deserialization!(deserialize_fast, "Fast", SpellSpeed::Fast);
|
||||||
|
test_deserialization!(deserialize_burst, "Burst", SpellSpeed::Burst);
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn deserialize_fallback() {
|
||||||
|
assert!(serde_json::de::from_str::<'static, SpellSpeed>("Xyzzy").is_err());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
//! Module defining [Type].
|
//! Module defining [Type].
|
||||||
|
|
||||||
|
|
||||||
/// A possible card type.
|
/// A possible card type.
|
||||||
///
|
///
|
||||||
/// Since more types might be added in the future, as it happened with landmarks, this enum is [non_exaustive](https://doc.rust-lang.org/reference/attributes/type_system.html#the-non_exhaustive-attribute).
|
/// Since more types might be added in the future, as it happened with landmarks, this enum is [non_exaustive](https://doc.rust-lang.org/reference/attributes/type_system.html#the-non_exhaustive-attribute).
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
#[derive(serde::Serialize, serde::Deserialize, Clone, Debug)]
|
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||||
pub enum CardType {
|
pub enum CardType {
|
||||||
/// A spell.
|
/// A spell.
|
||||||
Spell,
|
Spell,
|
||||||
|
@ -21,4 +22,40 @@ pub enum CardType {
|
||||||
/// Unsupported card type.
|
/// Unsupported card type.
|
||||||
#[serde(other)]
|
#[serde(other)]
|
||||||
Unsupported,
|
Unsupported,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::CardType;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn deserialize_spell() {
|
||||||
|
assert_eq!(serde_json::de::from_str::<'static, CardType>("Spell").unwrap(), CardType::Spell);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn deserialize_unit() {
|
||||||
|
assert_eq!(serde_json::de::from_str::<'static, CardType>("Unit").unwrap(), CardType::Unit);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn deserialize_ability() {
|
||||||
|
assert_eq!(serde_json::de::from_str::<'static, CardType>("Ability").unwrap(), CardType::Ability);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn deserialize_landmark() {
|
||||||
|
assert_eq!(serde_json::de::from_str::<'static, CardType>("Landmark").unwrap(), CardType::Landmark);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn deserialize_trap() {
|
||||||
|
assert_eq!(serde_json::de::from_str::<'static, CardType>("Trap").unwrap(), CardType::Trap);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn deserialize_fallback() {
|
||||||
|
assert_eq!(serde_json::de::from_str::<'static, CardType>("Xyzzy").unwrap(), CardType::Unsupported);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue