|
1 | 1 | use crate::{set_artist, temp_file, verify_artist};
|
2 |
| -use lofty::config::ParseOptions; |
| 2 | +use lofty::ape::ApeTag; |
| 3 | +use lofty::config::{ParseOptions, WriteOptions}; |
3 | 4 | use lofty::file::FileType;
|
4 | 5 | use lofty::prelude::*;
|
5 | 6 | use lofty::probe::Probe;
|
6 |
| -use lofty::tag::TagType; |
| 7 | +use lofty::tag::{Tag, TagType}; |
7 | 8 |
|
8 | 9 | use std::io::Seek;
|
9 | 10 |
|
@@ -77,3 +78,42 @@ fn read_no_properties() {
|
77 | 78 | fn read_no_tags() {
|
78 | 79 | crate::no_tag_test!("tests/files/assets/minimal/full_test.wv");
|
79 | 80 | }
|
| 81 | + |
| 82 | +#[test_log::test] |
| 83 | +fn write_ape_disc_key() { |
| 84 | + let mut file = crate::temp_file!("tests/files/assets/minimal/full_test.wv"); |
| 85 | + let mut tagged_file = Probe::new(&mut file) |
| 86 | + .options(ParseOptions::new()) |
| 87 | + .guess_file_type() |
| 88 | + .unwrap() |
| 89 | + .read() |
| 90 | + .unwrap(); |
| 91 | + |
| 92 | + // Create and insert a new Tag and set disk information |
| 93 | + let mut tag = Tag::new(TagType::Ape); |
| 94 | + tag.set_disk(3); |
| 95 | + tag.set_disk_total(5); |
| 96 | + tagged_file.insert_tag(tag); |
| 97 | + file.rewind().unwrap(); |
| 98 | + tagged_file |
| 99 | + .save_to(&mut file, WriteOptions::default()) |
| 100 | + .unwrap(); |
| 101 | + |
| 102 | + // Reread the file to get the actual APE tag |
| 103 | + file.rewind().unwrap(); |
| 104 | + let reread_tagged_file = Probe::new(&mut file) |
| 105 | + .options(ParseOptions::new()) |
| 106 | + .guess_file_type() |
| 107 | + .unwrap() |
| 108 | + .read() |
| 109 | + .unwrap(); |
| 110 | + let tag_ref = reread_tagged_file.tag(TagType::Ape).unwrap(); |
| 111 | + let ape_tag: ApeTag = tag_ref.clone().into(); |
| 112 | + |
| 113 | + assert!( |
| 114 | + ape_tag.get("Disc").is_some(), |
| 115 | + "APE tag should contain `Disc` key with disk information" |
| 116 | + ); |
| 117 | + assert_eq!(ape_tag.disk(), Some(3)); |
| 118 | + assert_eq!(ape_tag.disk_total(), Some(5)); |
| 119 | +} |
0 commit comments