Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 859b0fb1b3 | |||
| c04f27570e |
Generated
+1
-1
@@ -192,7 +192,7 @@ checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a"
|
||||
|
||||
[[package]]
|
||||
name = "icarus_models"
|
||||
version = "0.11.2"
|
||||
version = "0.11.3"
|
||||
dependencies = [
|
||||
"josekit",
|
||||
"rand",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "icarus_models"
|
||||
version = "0.11.2"
|
||||
version = "0.11.3"
|
||||
edition = "2024"
|
||||
rust-version = "1.95"
|
||||
description = "models used for the icarus project"
|
||||
|
||||
+36
-1
@@ -37,7 +37,42 @@ pub mod collection {
|
||||
pub artist: String,
|
||||
pub disc: i32,
|
||||
pub track: i32,
|
||||
// In seconds
|
||||
/// In seconds
|
||||
pub duration: f64,
|
||||
}
|
||||
|
||||
pub fn deserialize_json(json_data: &str, album: &mut Album) -> Result<(), serde_json::Error> {
|
||||
match serde_json::from_str::<Album>(json_data) {
|
||||
Ok(parsed_album) => {
|
||||
*album = parsed_album;
|
||||
Ok(())
|
||||
}
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn test_deserilize_album_collection_json() {
|
||||
let album_file_path = "tests/album.json";
|
||||
let album_file_content = match std::fs::read_to_string(album_file_path) {
|
||||
Ok(content) => content,
|
||||
Err(err) => {
|
||||
assert!(false, "Error: {err:?}");
|
||||
String::new()
|
||||
}
|
||||
};
|
||||
|
||||
let mut album = super::collection::Album::default();
|
||||
match super::collection::deserialize_json(&album_file_content, &mut album) {
|
||||
Ok(_) => {
|
||||
assert_eq!(3, album.tracks.len(), "Track count do not match");
|
||||
}
|
||||
Err(err) => {
|
||||
assert!(false, "Error: {err:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user