diff --git a/bingus/Cargo.toml b/bingus/Cargo.toml index c183587..c8e6030 100644 --- a/bingus/Cargo.toml +++ b/bingus/Cargo.toml @@ -19,3 +19,4 @@ derive-new = "0.7" strum = { version = "0.26", features = ["derive"] } derive_wrapper = "0.1" symphonia = { version = "0.5.4", features = ["all"] } +project-root = "0.2.2" diff --git a/bingus/src/snd/simphonia.rs b/bingus/src/snd/simphonia.rs index 442c727..d4b13b9 100644 --- a/bingus/src/snd/simphonia.rs +++ b/bingus/src/snd/simphonia.rs @@ -41,6 +41,15 @@ pub enum AudioOpenError { Symphonia(#[from] symphonia::core::errors::Error), } +impl PartialEq for AudioOpenError { + fn eq(&self, other: &Self) -> bool { + match self { + AudioOpenError::Io(_) => matches!(other, AudioOpenError::Io(_)), + AudioOpenError::Symphonia(_) => matches!(other, AudioOpenError::Symphonia(_)), + } + } +} + impl Audio { pub fn open>(path: P) -> Result { let registry = default::get_codecs(); @@ -159,3 +168,17 @@ where }) } } + +#[cfg(test)] +mod tests { + use project_root::get_project_root; + + use crate::IntoDataBytes; + + use super::Audio; + + #[test] + fn open_sample_file() { + assert_eq!(Ok(include_bytes!("../../../testing material/sound/1938-04-30_BBC_Winston_Churchill_To_The_Royal_Academy_Of_Arts.mp3").to_vec()), Audio::open(get_project_root().expect("can't find project root!").join("testing material").join("sound").join("1938-04-30_BBC_Winston_Churchill_To_The_Royal_Academy_Of_Arts.mp3")).map(|audio| audio.into_data_bytes())); + } +}