From a14d2dcb75d1cf951c1e349f6cd036f2e5d2cbf6 Mon Sep 17 00:00:00 2001 From: Arthur Roberts Date: Wed, 5 Feb 2025 00:12:50 +0000 Subject: [PATCH] Don't look at that awful test... I have tested it on the Oracle cards - so should like... mostly work for cards Except for, I think, mistakes? in the Scryfall database. --- scryfall_deser/src/lib.rs | 41 +++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/scryfall_deser/src/lib.rs b/scryfall_deser/src/lib.rs index 35e961f..6424230 100644 --- a/scryfall_deser/src/lib.rs +++ b/scryfall_deser/src/lib.rs @@ -61,11 +61,11 @@ struct ScryfallCard { // https://scryfall.com/docs/api/cards#print-fields pub artist: Option, pub artist_ids: Option>, - pub attraction_lights: Option>, // TODO: I'm not actually sure what these look like - I should test + pub attraction_lights: Option>, pub booster: bool, #[serde(rename = "border_color")] pub border_colour: BorderColour, - pub card_back_id: Uuid, + pub card_back_id: Option, // Scryfall docs says this should not be null, but ZHS Growing Rites of Itlimoc seems to not have one... maybe it's the back side? pub collector_number: String, pub content_warning: Option, pub digital: bool, @@ -173,6 +173,10 @@ enum Colour { Red, #[serde(rename = "G")] Green, + #[serde(rename = "C")] // I don't think it's meant to work like this... but eh + Colourless, + #[serde(rename = "T")] // See "Sole Performer" + Tap } #[derive(Deserialize, Debug)] @@ -310,7 +314,9 @@ enum FrameEffect { #[serde(rename = "upsidedowndfc")] UpsideDownDFC, #[serde(rename = "spree")] - Spree + Spree, + #[serde(rename = "fullart")] + FullArt } #[allow(dead_code)] @@ -321,7 +327,11 @@ enum Game { #[serde(rename = "mtgo")] MTGO, #[serde(rename = "arena")] - Arena + Arena, + #[serde(rename = "astral")] + Astral, + #[serde(rename = "sega")] + Sega } #[allow(dead_code)] @@ -449,17 +459,9 @@ mod tests { } #[test] - fn try_deserialise_all_cards() { - // TODO Actually write this funtion. - // The idea will be to run over one of the Scryfall dumps of all the cards so I can be - // confident I've got things working. - // I noticed that Scryfall very helpfully provides their dumps with 1 card per line. - // So using something like the link below should hopefully mean I don't have to load in the - // whole 2+GB file all at once - // https://doc.rust-lang.org/std/io/trait.BufRead.html#method.lines - // I think that's what it should do at least. I bet it'll still take a while tho. - // If that doesn't work - I should try somehow use the serde from_reader function - // I don't 100% know how I'll use that though. + #[ignore] + fn try_deserialise_all_cards_line_by_line() { + // This function is uuuuuuugly and I'm sure a terrible way to go about things let mut f = PathBuf::from(env!("CARGO_MANIFEST_DIR")); f.push("test_files/all-cards.json"); assert!(f.exists(), "You need to download the all-cards-... file from Scryfall bulk data. Can be found here: https://scryfall.com/docs/api/bulk-data and rename to all-cards.json"); @@ -467,7 +469,13 @@ mod tests { let reader = BufReader::new(ac); for line in reader.lines().skip(1) { let mut line = line.unwrap(); - line.pop(); + let c = line.pop().unwrap(); + // this is so dumb... + if c == '}' { + line.push('}'); + } + + if line.len() < 1 { continue }; let a_card: Result = serde_json::from_str(&line.as_ref()); match a_card { Err(error) => { @@ -479,6 +487,5 @@ mod tests { } } - // FIXME: Skip the last line } }