Skip to content

Commit

Permalink
Tests: Refactor BoundTaggedFile::into_inner test
Browse files Browse the repository at this point in the history
  • Loading branch information
Serial-ATA committed Jun 6, 2024
1 parent fee3c1f commit b57992b
Showing 1 changed file with 8 additions and 23 deletions.
31 changes: 8 additions & 23 deletions lofty/tests/files/mpeg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use lofty::probe::Probe;
use lofty::tag::{Tag, TagType};

use std::borrow::Cow;
use std::fs::OpenOptions;
use std::io::{Seek, Write};

#[test]
Expand Down Expand Up @@ -213,39 +212,25 @@ fn save_number_of_track_and_disk_to_id3v2() {

#[test]
fn test_bound_tagged_into_inner() {
let file = OpenOptions::new()
.read(true)
.write(true)
.open("tests/files/assets/minimal/full_test.mp3")
.expect("Cannot open file");
let mut bounded =
BoundTaggedFile::read_from(file, Default::default()).expect("Couldn't parse file");
let file = temp_file!("tests/files/assets/minimal/full_test.mp3");

let mut bounded = BoundTaggedFile::read_from(file, ParseOptions::default()).unwrap();

let tag = bounded
.tag_mut(TagType::Id3v2)
.expect("Couldn't get ref to tag");
let original_disk = tag.disk();
tag.set_disk(123);
bounded
.save(WriteOptions::default())
.expect("Couldn't save tags");

// Reread the file
let mut original_file = bounded.into_inner();
original_file.rewind().expect("Couldn't rewind");
let mut bounded = BoundTaggedFile::read_from(original_file, Default::default())
.expect("Couldn't reparse file");
let tag = bounded
.tag_mut(TagType::Id3v2)
.expect("Cannot get ref to tag");
original_file.rewind().unwrap();
let mut bounded = BoundTaggedFile::read_from(original_file, ParseOptions::default()).unwrap();
let tag = bounded.tag_mut(TagType::Id3v2).unwrap();

assert_eq!(tag.disk(), Some(123));

// Revert the file to whatever it was after this test.
if let Some(disk) = original_disk {
tag.set_disk(disk);
}
bounded
.save(WriteOptions::default())
.expect("Couldn't save tags");
}

#[test]
Expand Down

0 comments on commit b57992b

Please sign in to comment.