@@ -6,8 +6,8 @@ use std::io::{Read, Seek};
66use lofty:: error:: ErrorKind ;
77use lofty:: resolve:: FileResolver ;
88use lofty:: {
9- Accessor , AudioFile , FileProperties , FileType , ParseOptions , Tag , TagExt , TagType , TaggedFile ,
10- TaggedFileExt ,
9+ Accessor , AudioFile , FileProperties , FileType , GlobalOptions , ParseOptions , Tag , TagExt ,
10+ TagType , TaggedFile , TaggedFileExt , WriteOptions ,
1111} ;
1212
1313fn file_ref_save ( path : & str , expected_file_type : FileType ) {
@@ -33,7 +33,7 @@ fn file_ref_save(path: &str, expected_file_type: FileType) {
3333 tag. set_comment ( String :: from ( "a comment" ) ) ;
3434 tag. set_track ( 5 ) ;
3535 tag. set_year ( 2020 ) ;
36- tag. save_to ( & mut file) . unwrap ( ) ;
36+ tag. save_to ( & mut file, WriteOptions :: default ( ) ) . unwrap ( ) ;
3737 }
3838 file. rewind ( ) . unwrap ( ) ;
3939 {
@@ -55,7 +55,7 @@ fn file_ref_save(path: &str, expected_file_type: FileType) {
5555 tag. set_comment ( String :: from ( "another comment" ) ) ;
5656 tag. set_track ( 7 ) ;
5757 tag. set_year ( 2080 ) ;
58- tag. save_to ( & mut file) . unwrap ( ) ;
58+ tag. save_to ( & mut file, WriteOptions :: default ( ) ) . unwrap ( ) ;
5959 }
6060 file. rewind ( ) . unwrap ( ) ;
6161 {
@@ -214,72 +214,76 @@ fn test_default_file_extensions() {
214214 // Marker test, Lofty does not replicate this API
215215}
216216
217- // TODO: We need to check resolvers *first* and then resort to our default implementations
218- #[ test]
219- #[ ignore]
220- fn test_file_resolver ( ) {
221- {
222- let file = lofty:: read_from_path ( "tests/taglib/data/xing.mp3" ) . unwrap ( ) ;
223- assert_eq ! ( file. file_type( ) , FileType :: Mpeg ) ;
224- }
225-
226- struct DummyResolver ;
227- impl Into < TaggedFile > for DummyResolver {
228- fn into ( self ) -> TaggedFile {
229- TaggedFile :: new ( FileType :: Vorbis , FileProperties :: default ( ) , Vec :: new ( ) )
230- }
231- }
217+ use rusty_fork:: rusty_fork_test;
232218
233- impl AudioFile for DummyResolver {
234- type Properties = ( ) ;
219+ rusty_fork_test ! {
220+ #[ test]
221+ fn test_file_resolver( ) {
222+ lofty:: apply_global_options( GlobalOptions :: new( ) . use_custom_resolvers( true ) ) ;
235223
236- fn read_from < R > ( _: & mut R , _: ParseOptions ) -> lofty:: Result < Self >
237- where
238- R : Read + Seek ,
239- Self : Sized ,
240224 {
241- Ok ( Self )
225+ let file = lofty:: read_from_path( "tests/taglib/data/xing.mp3" ) . unwrap( ) ;
226+ assert_eq!( file. file_type( ) , FileType :: Mpeg ) ;
242227 }
243228
244- fn save_to ( & self , _: & mut File ) -> lofty:: Result < ( ) > {
245- unimplemented ! ( )
229+ struct DummyResolver ;
230+ impl Into <TaggedFile > for DummyResolver {
231+ fn into( self ) -> TaggedFile {
232+ TaggedFile :: new( FileType :: Vorbis , FileProperties :: default ( ) , Vec :: new( ) )
233+ }
246234 }
247235
248- fn properties ( & self ) -> & Self :: Properties {
249- unimplemented ! ( )
250- }
236+ impl AudioFile for DummyResolver {
237+ type Properties = ( ) ;
251238
252- fn contains_tag ( & self ) -> bool {
253- unimplemented ! ( )
254- }
239+ fn read_from<R >( _: & mut R , _: ParseOptions ) -> lofty:: Result <Self >
240+ where
241+ R : Read + Seek ,
242+ Self : Sized ,
243+ {
244+ Ok ( Self )
245+ }
255246
256- fn contains_tag_type ( & self , _: TagType ) -> bool {
257- unimplemented ! ( )
258- }
259- }
247+ fn save_to( & self , _: & mut File , _: WriteOptions ) -> lofty:: Result <( ) > {
248+ unimplemented!( )
249+ }
260250
261- impl FileResolver for DummyResolver {
262- fn extension ( ) -> Option < & ' static str > {
263- Some ( "mp3" )
264- }
251+ fn properties( & self ) -> & Self :: Properties {
252+ unimplemented!( )
253+ }
265254
266- fn primary_tag_type ( ) -> TagType {
267- unimplemented ! ( )
268- }
255+ fn contains_tag ( & self ) -> bool {
256+ unimplemented!( )
257+ }
269258
270- fn supported_tag_types ( ) -> & ' static [ TagType ] {
271- unimplemented ! ( )
259+ fn contains_tag_type( & self , _: TagType ) -> bool {
260+ unimplemented!( )
261+ }
272262 }
273263
274- fn guess ( _: & [ u8 ] ) -> Option < FileType > {
275- Some ( FileType :: Vorbis )
264+ impl FileResolver for DummyResolver {
265+ fn extension( ) -> Option <& ' static str > {
266+ Some ( "mp3" )
267+ }
268+
269+ fn primary_tag_type( ) -> TagType {
270+ unimplemented!( )
271+ }
272+
273+ fn supported_tag_types( ) -> & ' static [ TagType ] {
274+ unimplemented!( )
275+ }
276+
277+ fn guess( _: & [ u8 ] ) -> Option <FileType > {
278+ Some ( FileType :: Vorbis )
279+ }
276280 }
277- }
278281
279- lofty:: resolve:: register_custom_resolver :: < DummyResolver > ( "Dummy" ) ;
282+ lofty:: resolve:: register_custom_resolver:: <DummyResolver >( "Dummy" ) ;
280283
281- {
282- let file = lofty:: read_from_path ( "tests/taglib/data/xing.mp3" ) . unwrap ( ) ;
283- assert_eq ! ( file. file_type( ) , FileType :: Vorbis ) ;
284+ {
285+ let file = lofty:: read_from_path( "tests/taglib/data/xing.mp3" ) . unwrap( ) ;
286+ assert_eq!( file. file_type( ) , FileType :: Vorbis ) ;
287+ }
284288 }
285289}
0 commit comments