Added a very poorly written test thingy

Started fixing a couple of mistakes
This commit is contained in:
2025-02-04 23:45:53 +00:00
parent 993ac46954
commit 66b22c1c30
2 changed files with 29 additions and 11 deletions

View File

@@ -2,6 +2,7 @@
# will have compiled files and executables # will have compiled files and executables
debug/ debug/
target/ target/
test_files/all-cards.json
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html

View File

@@ -35,7 +35,7 @@ struct ScryfallCard {
// NOTE: Probably a bad idea to rename color -> colour just for the sake // 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 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")] #[serde(rename = "color_identity")]
pub colour_identity: Vec<Colour>, pub colour_identity: Option<Vec<Colour>>,
#[serde(rename = "color_indicator")] #[serde(rename = "color_indicator")]
pub colour_indicator: Option<Vec<Colour>>, pub colour_indicator: Option<Vec<Colour>>,
#[serde(rename = "colors")] #[serde(rename = "colors")]
@@ -81,7 +81,7 @@ struct ScryfallCard {
pub highres_image: bool, pub highres_image: bool,
pub illustration_id: Option<Uuid>, pub illustration_id: Option<Uuid>,
pub image_status: ImageStatus, pub image_status: ImageStatus,
pub image_uris: ImageURIs, pub image_uris: Option<ImageURIs>,
pub oversized: bool, pub oversized: bool,
pub prices: Prices, pub prices: Prices,
pub printed_name: Option<String>, pub printed_name: Option<String>,
@@ -124,7 +124,7 @@ struct ScryfallCardFaceObject {
pub artist_id: Option<Uuid>, // UUID 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 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")] #[serde(rename = "color_identity")]
pub colour_identity: Vec<Colour>, pub colour_identity: Option<Vec<Colour>>,
#[serde(rename = "color_indicator")] #[serde(rename = "color_indicator")]
pub colour_indicator: Option<Vec<Colour>>, pub colour_indicator: Option<Vec<Colour>>,
#[serde(rename = "colors")] #[serde(rename = "colors")]
@@ -132,7 +132,7 @@ struct ScryfallCardFaceObject {
pub defence: Option<String>, pub defence: Option<String>,
pub flavour_text: Option<String>, pub flavour_text: Option<String>,
pub illustration_id: Option<Uuid>, pub illustration_id: Option<Uuid>,
pub image_uris: ImageURIs, pub image_uris: Option<ImageURIs>,
pub layout: Option<String>, pub layout: Option<String>,
pub loyalty: Option<String>, pub loyalty: Option<String>,
pub mana_cost: Option<String>, pub mana_cost: Option<String>,
@@ -419,6 +419,7 @@ mod tests {
use super::*; use super::*;
use std::path::PathBuf; use std::path::PathBuf;
use std::fs; use std::fs;
use std::io::{BufRead, BufReader};
#[test] #[test]
fn deserialise_nissa() { fn deserialise_nissa() {
@@ -426,8 +427,7 @@ mod tests {
f.push("test_files/nissa.json"); f.push("test_files/nissa.json");
assert!(f.exists()); assert!(f.exists());
let fc = fs::read_to_string(f).unwrap(); let fc = fs::read_to_string(f).unwrap();
let nissa: ScryfallCard = serde_json::from_str(&fc).unwrap(); let _nissa: ScryfallCard = serde_json::from_str(&fc).unwrap();
println!("{:#?}", nissa);
} }
#[test] #[test]
@@ -436,8 +436,7 @@ mod tests {
f.push("test_files/black_lotus.json"); f.push("test_files/black_lotus.json");
assert!(f.exists()); assert!(f.exists());
let fc = fs::read_to_string(f).unwrap(); let fc = fs::read_to_string(f).unwrap();
let bl: ScryfallCard = serde_json::from_str(&fc).unwrap(); let _bl: ScryfallCard = serde_json::from_str(&fc).unwrap();
println!("{:#?}", bl);
} }
#[test] #[test]
@@ -446,12 +445,10 @@ mod tests {
f.push("test_files/little_girl.json"); f.push("test_files/little_girl.json");
assert!(f.exists()); assert!(f.exists());
let fc = fs::read_to_string(f).unwrap(); let fc = fs::read_to_string(f).unwrap();
let lg: ScryfallCard = serde_json::from_str(&fc).unwrap(); let _lg: ScryfallCard = serde_json::from_str(&fc).unwrap();
println!("{:#?}", lg);
} }
#[test] #[test]
#[ignore]
fn try_deserialise_all_cards() { fn try_deserialise_all_cards() {
// TODO Actually write this funtion. // 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 // 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. // 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 // 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. // 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
} }
} }