From f4a6aa9616ee91c82068fa1b74c92364f278aac7 Mon Sep 17 00:00:00 2001 From: Serial <69764315+Serial-ATA@users.noreply.github.com> Date: Fri, 13 Jan 2023 12:21:30 -0500 Subject: [PATCH] Tests: Add TagLib ID3v1 tests --- tests/taglib/main.rs | 1 + tests/taglib/test_id3v1.rs | 51 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 tests/taglib/test_id3v1.rs diff --git a/tests/taglib/main.rs b/tests/taglib/main.rs index 4755200c1..76b9f13ee 100644 --- a/tests/taglib/main.rs +++ b/tests/taglib/main.rs @@ -6,3 +6,4 @@ mod test_apetag; mod test_fileref; mod test_flac; mod test_flacpicture; +mod test_id3v1; diff --git a/tests/taglib/test_id3v1.rs b/tests/taglib/test_id3v1.rs new file mode 100644 index 000000000..8cc6bed40 --- /dev/null +++ b/tests/taglib/test_id3v1.rs @@ -0,0 +1,51 @@ +use crate::temp_file; + +use std::io::Seek; + +use lofty::id3::v1::{ID3v1Tag, GENRES}; +use lofty::mpeg::MPEGFile; +use lofty::{Accessor, AudioFile, ParseOptions}; + +#[test] +#[ignore] // TODO: We probably should be stripping whitespace +fn test_strip_whitespace() { + let mut file = temp_file!("tests/taglib/data/xing.mp3"); + { + let mut f = MPEGFile::read_from(&mut file, ParseOptions::new()).unwrap(); + file.rewind().unwrap(); + + let mut tag = ID3v1Tag::default(); + tag.set_artist(String::from("Artist ")); + f.set_id3v1(tag); + f.save_to(&mut file).unwrap(); + } + file.rewind().unwrap(); + { + let f = MPEGFile::read_from(&mut file, ParseOptions::new()).unwrap(); + assert_eq!(f.id3v1().unwrap().artist().as_deref(), Some("Artist")); + } +} + +#[test] +fn test_genres() { + assert_eq!("Darkwave", GENRES[50]); + assert_eq!( + 100, + GENRES.iter().position(|genre| *genre == "Humour").unwrap() + ); + assert!(GENRES.contains(&"Heavy Metal")); + assert_eq!( + 79, + GENRES + .iter() + .position(|genre| *genre == "Hard Rock") + .unwrap() + ); +} + +#[test] +#[ignore] +fn test_renamed_genres() { + // Marker test, this covers a change where TagLib deviated from the list of genres available on Wikipedia. + // For now, Lofty has no reason to change. +}