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.
This commit is contained in:
@@ -61,11 +61,11 @@ struct ScryfallCard {
|
||||
// https://scryfall.com/docs/api/cards#print-fields
|
||||
pub artist: Option<String>,
|
||||
pub artist_ids: Option<Vec<String>>,
|
||||
pub attraction_lights: Option<Vec<String>>, // TODO: I'm not actually sure what these look like - I should test
|
||||
pub attraction_lights: Option<Vec<u8>>,
|
||||
pub booster: bool,
|
||||
#[serde(rename = "border_color")]
|
||||
pub border_colour: BorderColour,
|
||||
pub card_back_id: Uuid,
|
||||
pub card_back_id: Option<Uuid>, // 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<bool>,
|
||||
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<ScryfallCard, serde_json::Error> = serde_json::from_str(&line.as_ref());
|
||||
match a_card {
|
||||
Err(error) => {
|
||||
@@ -479,6 +487,5 @@ mod tests {
|
||||
}
|
||||
|
||||
}
|
||||
// FIXME: Skip the last line
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user