Added a very poorly written test thingy
Started fixing a couple of mistakes
This commit is contained in:
@@ -35,7 +35,7 @@ struct ScryfallCard {
|
||||
// NOTE: Probably a bad idea to rename color -> colour just for the sake
|
||||
pub cmc: Option<f64>, // TODO: Make this a proper Decimal - see "Little Girl" card for example of cmc of 0.5
|
||||
#[serde(rename = "color_identity")]
|
||||
pub colour_identity: Vec<Colour>,
|
||||
pub colour_identity: Option<Vec<Colour>>,
|
||||
#[serde(rename = "color_indicator")]
|
||||
pub colour_indicator: Option<Vec<Colour>>,
|
||||
#[serde(rename = "colors")]
|
||||
@@ -81,7 +81,7 @@ struct ScryfallCard {
|
||||
pub highres_image: bool,
|
||||
pub illustration_id: Option<Uuid>,
|
||||
pub image_status: ImageStatus,
|
||||
pub image_uris: ImageURIs,
|
||||
pub image_uris: Option<ImageURIs>,
|
||||
pub oversized: bool,
|
||||
pub prices: Prices,
|
||||
pub printed_name: Option<String>,
|
||||
@@ -124,7 +124,7 @@ struct ScryfallCardFaceObject {
|
||||
pub artist_id: Option<Uuid>, // UUID
|
||||
pub cmc: Option<f64>, // TODO: Make this a proper Decimal - see "Little Girl" card for example of cmc of 0.5
|
||||
#[serde(rename = "color_identity")]
|
||||
pub colour_identity: Vec<Colour>,
|
||||
pub colour_identity: Option<Vec<Colour>>,
|
||||
#[serde(rename = "color_indicator")]
|
||||
pub colour_indicator: Option<Vec<Colour>>,
|
||||
#[serde(rename = "colors")]
|
||||
@@ -132,7 +132,7 @@ struct ScryfallCardFaceObject {
|
||||
pub defence: Option<String>,
|
||||
pub flavour_text: Option<String>,
|
||||
pub illustration_id: Option<Uuid>,
|
||||
pub image_uris: ImageURIs,
|
||||
pub image_uris: Option<ImageURIs>,
|
||||
pub layout: Option<String>,
|
||||
pub loyalty: Option<String>,
|
||||
pub mana_cost: Option<String>,
|
||||
@@ -419,6 +419,7 @@ mod tests {
|
||||
use super::*;
|
||||
use std::path::PathBuf;
|
||||
use std::fs;
|
||||
use std::io::{BufRead, BufReader};
|
||||
|
||||
#[test]
|
||||
fn deserialise_nissa() {
|
||||
@@ -426,8 +427,7 @@ mod tests {
|
||||
f.push("test_files/nissa.json");
|
||||
assert!(f.exists());
|
||||
let fc = fs::read_to_string(f).unwrap();
|
||||
let nissa: ScryfallCard = serde_json::from_str(&fc).unwrap();
|
||||
println!("{:#?}", nissa);
|
||||
let _nissa: ScryfallCard = serde_json::from_str(&fc).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -436,8 +436,7 @@ mod tests {
|
||||
f.push("test_files/black_lotus.json");
|
||||
assert!(f.exists());
|
||||
let fc = fs::read_to_string(f).unwrap();
|
||||
let bl: ScryfallCard = serde_json::from_str(&fc).unwrap();
|
||||
println!("{:#?}", bl);
|
||||
let _bl: ScryfallCard = serde_json::from_str(&fc).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -446,12 +445,10 @@ mod tests {
|
||||
f.push("test_files/little_girl.json");
|
||||
assert!(f.exists());
|
||||
let fc = fs::read_to_string(f).unwrap();
|
||||
let lg: ScryfallCard = serde_json::from_str(&fc).unwrap();
|
||||
println!("{:#?}", lg);
|
||||
let _lg: ScryfallCard = serde_json::from_str(&fc).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
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
|
||||
@@ -463,5 +460,25 @@ mod tests {
|
||||
// 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.
|
||||
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");
|
||||
let ac = fs::File::open(f).unwrap();
|
||||
let reader = BufReader::new(ac);
|
||||
for line in reader.lines().skip(1) {
|
||||
let mut line = line.unwrap();
|
||||
line.pop();
|
||||
let a_card: Result<ScryfallCard, serde_json::Error> = serde_json::from_str(&line.as_ref());
|
||||
match a_card {
|
||||
Err(error) => {
|
||||
println!("{:#?}", line);
|
||||
println!("{:#?}", error);
|
||||
panic!();
|
||||
},
|
||||
Ok(_) => (),
|
||||
}
|
||||
|
||||
}
|
||||
// FIXME: Skip the last line
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user