From 3f7a4dd8c9eb4cecf25c9f4f4d4577a04bdf5ce0 Mon Sep 17 00:00:00 2001 From: Fabrizio Duroni Date: Sat, 12 Oct 2024 15:37:45 +0200 Subject: [PATCH] Migration to swift testing + fix iso latin for linux platform --- ID3TagEditor.xcodeproj/project.pbxproj | 65 +- LinuxMain.swift | 8 - Package.swift | 5 +- Source/Frame/FrameName.swift | 1 - .../Parse/ID3FrameStringContentParser.swift | 14 +- .../ID3TagEditorAcceptanceTest.swift | 786 ++++++++++-------- .../ID3TagEditorWriteReadAcceptanceTest.swift | 536 ++++++------ .../PaddingAdderUsingNullCharTest.swift | 8 +- .../Common/PaddingRemoverUsingTrimming.swift | 10 +- ...teArrayAdapterUsingUnsafePointerTest.swift | 12 +- ...ID3AttachedPicturesFrameCreatorsTest.swift | 56 +- .../ID3DiscPositionFrameCreatorTest.swift | 12 +- .../ID3FrameContentSizeCalculatorTest.swift | 32 +- Tests/Create/ID3FrameFlagsCreatorTest.swift | 14 +- ...ID3FrameFromStringContentCreatorTest.swift | 8 +- Tests/Create/ID3FrameHeaderCreatorTest.swift | 16 +- ...D3FrameWithIntegerContentCreatorTest.swift | 12 +- ...ID3FrameWithStringContentCreatorTest.swift | 12 +- ...ramesWithLocalizedContentCreatorTest.swift | 16 +- Tests/Create/ID3GenreFrameCreatorTest.swift | 12 +- .../ID3ISO88591StringToByteAdapterTest.swift | 8 +- .../Create/ID3LocalizedFrameCreatorTest.swift | 16 +- ...ID3RecordingDateTimeFrameCreatorTest.swift | 10 +- ...ID3RecordingDayMonthFrameCreatorTest.swift | 16 +- Tests/Create/ID3TagCreatorTest.swift | 24 +- Tests/Create/ID3TimestampCreatorTest.swift | 30 +- .../ID3TrackPositionFrameCreatorTest.swift | 12 +- .../ID3UTF16StringToByteAdapterTest.swift | 8 +- Tests/Frame/ID3FrameConfigurationTest.swift | 10 +- Tests/Mock/MockStringToBytesAdapter.swift | 2 +- Tests/Mock/MockSynchsafeEncoder.swift | 2 +- Tests/Mock/MockTimestampCreator.swift | 4 +- Tests/Mp3/Mp3FileReaderTest.swift | 28 +- ...tureFrameContentParsingOperationTest.swift | 60 +- .../ID3DiscPositionStringAdapterTest.swift | 30 +- .../Parse/ID3FrameContentSizeParserTest.swift | 41 +- Tests/Parse/ID3FrameSizeParserTest.swift | 18 +- Tests/Parse/ID3GenreStringAdapterTest.swift | 40 +- ...D3LocalizedFrameParsingOperationTest.swift | 60 +- Tests/Parse/ID3PictureTypeAdapterTest.swift | 22 +- .../ID3RecordingTimestampOperationTest.swift | 61 +- ...ID3StringContentParsingOperationTest.swift | 156 ++-- Tests/Parse/ID3TagSizeParserTest.swift | 20 +- Tests/Parse/ID3TagVersionParserTest.swift | 24 +- .../ID3TrackPositionStringAdapterTest.swift | 30 +- Tests/Tag/ID3TagPresenceTest.swift | 26 +- Tests/Tag/ID3TagTest.swift | 18 +- Tests/XCTestManifests.swift | 46 - 48 files changed, 1274 insertions(+), 1183 deletions(-) delete mode 100644 LinuxMain.swift delete mode 100644 Tests/XCTestManifests.swift diff --git a/ID3TagEditor.xcodeproj/project.pbxproj b/ID3TagEditor.xcodeproj/project.pbxproj index 2e76f695..2d05061e 100644 --- a/ID3TagEditor.xcodeproj/project.pbxproj +++ b/ID3TagEditor.xcodeproj/project.pbxproj @@ -41,7 +41,6 @@ 452831CE2044C40700458375 /* ID3TagEditor macOS Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "ID3TagEditor macOS Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 452831E52044C4F500458375 /* ID3TagEditor.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ID3TagEditor.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 452831ED2044C4F500458375 /* ID3TagEditor iOS Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "ID3TagEditor iOS Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; - 4553D64521946A3000540631 /* LinuxMain.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinuxMain.swift; sourceTree = ""; }; 45541B7720598F6C0025A8BF /* ID3TagEditor.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ID3TagEditor.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 45541BE52059954C0025A8BF /* ID3TagEditor tvOS Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "ID3TagEditor tvOS Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 45541C25205999A20025A8BF /* CHANGELOG.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = CHANGELOG.md; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.markdown; }; @@ -106,7 +105,6 @@ membershipExceptions = ( Info.plist, Utils/PathLoader.swift, - XCTestManifests.swift, ); target = 452831CD2044C40700458375 /* ID3TagEditor macOS Tests */; }; @@ -115,7 +113,6 @@ membershipExceptions = ( Info.plist, Utils/PathLoader.swift, - XCTestManifests.swift, ); target = 452831EC2044C4F500458375 /* ID3TagEditor iOS Tests */; }; @@ -124,7 +121,6 @@ membershipExceptions = ( Info.plist, Utils/PathLoader.swift, - XCTestManifests.swift, ); target = 45541BE42059954C0025A8BF /* ID3TagEditor tvOS Tests */; }; @@ -232,7 +228,6 @@ 45AB7195204AD842004A2239 /* README.md */, 45AB7194204AD842004A2239 /* LICENSE.md */, 455CF9862340C14B004C880A /* ID3TagEditor.podspec */, - 4553D64521946A3000540631 /* LinuxMain.swift */, 45AB7193204AD842004A2239 /* Package.swift */, 45D4C39A25399ABD00501417 /* .codebeatignore */, 45D4C39C25399ABD00501417 /* .gitignore */, @@ -464,7 +459,6 @@ 452831CD2044C40700458375 = { CreatedOnToolsVersion = 9.2; LastSwiftMigration = 1100; - ProvisioningStyle = Automatic; }; 452831E42044C4F500458375 = { CreatedOnToolsVersion = 9.2; @@ -474,7 +468,6 @@ 452831EC2044C4F500458375 = { CreatedOnToolsVersion = 9.2; LastSwiftMigration = 1100; - ProvisioningStyle = Automatic; }; 45541B7620598F6C0025A8BF = { CreatedOnToolsVersion = 9.2; @@ -788,7 +781,7 @@ SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_STRICT_CONCURRENCY = complete; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -849,7 +842,7 @@ SWIFT_COMPILATION_MODE = wholemodule; SWIFT_OPTIMIZATION_LEVEL = "-O"; SWIFT_STRICT_CONCURRENCY = complete; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -866,6 +859,7 @@ DEAD_CODE_STRIPPING = YES; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = Y682K92RZU; + "DEVELOPMENT_TEAM[sdk=macosx*]" = 5Y4K7JX2AU; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; @@ -887,7 +881,7 @@ PROVISIONING_PROFILE_SPECIFIER = ""; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; }; name = Debug; }; @@ -902,6 +896,7 @@ DEAD_CODE_STRIPPING = YES; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = Y682K92RZU; + "DEVELOPMENT_TEAM[sdk=macosx*]" = 5Y4K7JX2AU; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; @@ -922,7 +917,7 @@ PRODUCT_NAME = ID3TagEditor; PROVISIONING_PROFILE_SPECIFIER = ""; SKIP_INSTALL = YES; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; }; name = Release; }; @@ -930,10 +925,12 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_MODULES = YES; + CODE_SIGN_IDENTITY = "Apple Development"; + "CODE_SIGN_IDENTITY[sdk=macosx*]" = "-"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; DEAD_CODE_STRIPPING = YES; - DEVELOPMENT_TEAM = Y682K92RZU; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = Tests/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", @@ -943,8 +940,9 @@ MACOSX_DEPLOYMENT_TARGET = 12.0; PRODUCT_BUNDLE_IDENTIFIER = it.chicio.ID3TagEditorTests; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; }; name = Debug; }; @@ -952,10 +950,12 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_MODULES = YES; + CODE_SIGN_IDENTITY = "Apple Development"; + "CODE_SIGN_IDENTITY[sdk=macosx*]" = "-"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; DEAD_CODE_STRIPPING = YES; - DEVELOPMENT_TEAM = Y682K92RZU; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = Tests/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", @@ -965,7 +965,8 @@ MACOSX_DEPLOYMENT_TARGET = 12.0; PRODUCT_BUNDLE_IDENTIFIER = it.chicio.ID3TagEditorTests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 5.0; + PROVISIONING_PROFILE_SPECIFIER = ""; + SWIFT_VERSION = 6.0; }; name = Release; }; @@ -1002,7 +1003,7 @@ SDKROOT = iphoneos; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -1039,7 +1040,7 @@ "PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = ""; SDKROOT = iphoneos; SKIP_INSTALL = YES; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; }; @@ -1049,10 +1050,10 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_MODULES = YES; - CODE_SIGN_IDENTITY = "iPhone Developer"; + CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMPRESS_PNG_FILES = NO; - DEVELOPMENT_TEAM = Y682K92RZU; + DEVELOPMENT_TEAM = 5Y4K7JX2AU; INFOPLIST_FILE = Tests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 15.0; LD_RUNPATH_SEARCH_PATHS = ( @@ -1063,10 +1064,11 @@ MACOSX_DEPLOYMENT_TARGET = 11.0; PRODUCT_BUNDLE_IDENTIFIER = "it.chicio.ID3TagEditor-iOSTests"; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE_SPECIFIER = ""; SDKROOT = iphoneos; STRIP_PNG_TEXT = NO; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -1075,10 +1077,10 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_MODULES = YES; - CODE_SIGN_IDENTITY = "iPhone Developer"; + CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMPRESS_PNG_FILES = NO; - DEVELOPMENT_TEAM = Y682K92RZU; + DEVELOPMENT_TEAM = 5Y4K7JX2AU; INFOPLIST_FILE = Tests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 15.0; LD_RUNPATH_SEARCH_PATHS = ( @@ -1089,9 +1091,10 @@ MACOSX_DEPLOYMENT_TARGET = 11.0; PRODUCT_BUNDLE_IDENTIFIER = "it.chicio.ID3TagEditor-iOSTests"; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE_SPECIFIER = ""; SDKROOT = iphoneos; STRIP_PNG_TEXT = NO; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; }; @@ -1125,7 +1128,7 @@ PROVISIONING_PROFILE_SPECIFIER = ""; SDKROOT = appletvos; SKIP_INSTALL = YES; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; TARGETED_DEVICE_FAMILY = 3; TVOS_DEPLOYMENT_TARGET = 12.0; }; @@ -1159,7 +1162,7 @@ PROVISIONING_PROFILE_SPECIFIER = ""; SDKROOT = appletvos; SKIP_INSTALL = YES; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; TARGETED_DEVICE_FAMILY = 3; TVOS_DEPLOYMENT_TARGET = 12.0; VALIDATE_PRODUCT = YES; @@ -1172,7 +1175,7 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COMPRESS_PNG_FILES = NO; - DEVELOPMENT_TEAM = Y682K92RZU; + DEVELOPMENT_TEAM = 5Y4K7JX2AU; INFOPLIST_FILE = Tests/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", @@ -1184,7 +1187,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = appletvos; STRIP_PNG_TEXT = NO; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; TARGETED_DEVICE_FAMILY = 3; TVOS_DEPLOYMENT_TARGET = 15.0; }; @@ -1196,7 +1199,7 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COMPRESS_PNG_FILES = NO; - DEVELOPMENT_TEAM = Y682K92RZU; + DEVELOPMENT_TEAM = 5Y4K7JX2AU; INFOPLIST_FILE = Tests/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", @@ -1208,7 +1211,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = appletvos; STRIP_PNG_TEXT = NO; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; TARGETED_DEVICE_FAMILY = 3; TVOS_DEPLOYMENT_TARGET = 15.0; VALIDATE_PRODUCT = YES; @@ -1243,7 +1246,7 @@ PROVISIONING_PROFILE_SPECIFIER = ""; SDKROOT = watchos; SKIP_INSTALL = YES; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; TARGETED_DEVICE_FAMILY = 4; TVOS_DEPLOYMENT_TARGET = 15.0; WATCHOS_DEPLOYMENT_TARGET = 8.0; @@ -1278,7 +1281,7 @@ PROVISIONING_PROFILE_SPECIFIER = ""; SDKROOT = watchos; SKIP_INSTALL = YES; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; TARGETED_DEVICE_FAMILY = 4; TVOS_DEPLOYMENT_TARGET = 15.0; VALIDATE_PRODUCT = YES; diff --git a/LinuxMain.swift b/LinuxMain.swift deleted file mode 100644 index f06f83e7..00000000 --- a/LinuxMain.swift +++ /dev/null @@ -1,8 +0,0 @@ -import XCTest - -import ID3TagEditorTests - -var tests = [XCTestCaseEntry]() -tests += ID3TagEditorTests.__allTests() - -XCTMain(tests) diff --git a/Package.swift b/Package.swift index ff6da9a3..6309224b 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.3 +// swift-tools-version: 6.0 import PackageDescription @@ -25,6 +25,5 @@ let package = Package( exclude: ["Utils/PathLoaderXcodeProj.swift", "Info.plist"], resources: [.process("Examples")] ) - ], - swiftLanguageVersions: [.v5] + ] ) diff --git a/Source/Frame/FrameName.swift b/Source/Frame/FrameName.swift index 415679fc..71f61ca4 100644 --- a/Source/Frame/FrameName.swift +++ b/Source/Frame/FrameName.swift @@ -21,7 +21,6 @@ struct FrameNamesWithLocalizedContent { } } - /// An enum used to identify the different types of frame parsed by the ID3TagEditor. /// This must be used to acces the frame data as identifier inside the dictionary /// of frame in the `ID3tag` `frames` properties. diff --git a/Source/Parse/ID3FrameStringContentParser.swift b/Source/Parse/ID3FrameStringContentParser.swift index fa8efa52..739670d2 100644 --- a/Source/Parse/ID3FrameStringContentParser.swift +++ b/Source/Parse/ID3FrameStringContentParser.swift @@ -24,13 +24,25 @@ class ID3FrameStringContentParser { let headerSize = id3FrameConfiguration.headerSizeFor(version: version) let frameContentRangeStart = headerSize + id3FrameConfiguration.encodingSize() - guard frameContentRangeStart < frame.count else { return nil } + guard frameContentRangeStart < frame.count else { + return nil + } let frameContent = frame.subdata(in: frameContentRangeStart.. ID3Tag { diff --git a/Tests/Create/ID3GenreFrameCreatorTest.swift b/Tests/Create/ID3GenreFrameCreatorTest.swift index 85ebcddf..c4186e6c 100644 --- a/Tests/Create/ID3GenreFrameCreatorTest.swift +++ b/Tests/Create/ID3GenreFrameCreatorTest.swift @@ -5,11 +5,11 @@ // 2018 Fabrizio Duroni. // -import XCTest +import Testing @testable import ID3TagEditor -class ID3GenreFrameCreatorTest: XCTestCase { - func testNoFrameCreationWhenThereIsNoGenre() { +struct ID3GenreFrameCreatorTest { + @Test func testNoFrameCreationWhenThereIsNoGenre() { let id3GenreFrameCreator = ID3GenreFrameCreator( frameCreator: MockFrameFromStringContentCreator( fakeNewFrameAsByte: [], @@ -21,10 +21,10 @@ class ID3GenreFrameCreatorTest: XCTestCase { id3Tag: ID32v3TagBuilder().build() ) - XCTAssertEqual(newTagBytes, []) + #expect(newTagBytes == []) } - func testFrameCreationWhenThereIsAGenre() { + @Test func testFrameCreationWhenThereIsAGenre() { let newFrameBytes: [UInt8] = [1, 1] let id3Tag = ID32v3TagBuilder() .genre(frame: ID3FrameGenre(genre: .metal, description: "Metalcore")) @@ -39,7 +39,7 @@ class ID3GenreFrameCreatorTest: XCTestCase { let newTagBytes = id3GenreFrameCreator.createFrames(id3Tag: id3Tag) - XCTAssertEqual(newTagBytes, newFrameBytes) + #expect(newTagBytes == newFrameBytes) } static let allTests = [ diff --git a/Tests/Create/ID3ISO88591StringToByteAdapterTest.swift b/Tests/Create/ID3ISO88591StringToByteAdapterTest.swift index 61c7aa6c..99706c4c 100644 --- a/Tests/Create/ID3ISO88591StringToByteAdapterTest.swift +++ b/Tests/Create/ID3ISO88591StringToByteAdapterTest.swift @@ -5,21 +5,21 @@ // 2018 Fabrizio Duroni. // -import XCTest +import Testing @testable import ID3TagEditor -class ID3ISO88591StringToByteAdapterTest: XCTestCase { +struct ID3ISO88591StringToByteAdapterTest { private let ENCODING: [UInt8] = [0x00] private let STRING: [UInt8] = [0x3A, 0x3A, 0x61, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x3A, 0x3A, 0x0] - func testEncodeStringToISO88591WithEncodingByte() { + @Test func testEncodeStringToISO88591WithEncodingByte() { let adapter = ID3ISO88591StringToByteAdapter(paddingAdder: MockPaddingAdder(), frameConfiguration: ID3FrameConfiguration()) let bytes = adapter.adapt(string: "::a string::", for: .version3) - XCTAssertEqual(bytes, ENCODING + STRING) + #expect(bytes == ENCODING + STRING) } static let allTests = [ diff --git a/Tests/Create/ID3LocalizedFrameCreatorTest.swift b/Tests/Create/ID3LocalizedFrameCreatorTest.swift index 9d54bae0..d9d01dc9 100644 --- a/Tests/Create/ID3LocalizedFrameCreatorTest.swift +++ b/Tests/Create/ID3LocalizedFrameCreatorTest.swift @@ -6,11 +6,11 @@ // Copyright © 2020 Fabrizio Duroni. All rights reserved. // -import XCTest +import Testing @testable import ID3TagEditor -class ID3LocalizedFrameCreatorTest: XCTestCase { - func testCreatev2() { +struct ID3LocalizedFrameCreatorTest { + @Test func testCreatev2() { let creator = ID3LocalizedFrameCreator( id3FrameConfiguration: ID3FrameConfiguration(), frameHeaderCreator: MockFrameHeaderCreator(), @@ -23,7 +23,7 @@ class ID3LocalizedFrameCreatorTest: XCTestCase { version: .version2, frameType: .unsyncronisedLyrics) - XCTAssertEqual(frame, + #expect(frame == [0x01, 0x02, 0x01, 0x69, 0x74, 0x61, 0xFF, 0xFE, 0x63, 0x00, 0x6F, 0x00, 0x6E, 0x00, 0x74, 0x00, 0x65, 0x00, 0x6E, 0x00, 0x74, 0x00, 0x20, 0x00, 0x64, 0x00, 0x65, 0x00, 0x73, 0x00, 0x63, 0x00, 0x72, 0x00, 0x69, 0x00, @@ -32,7 +32,7 @@ class ID3LocalizedFrameCreatorTest: XCTestCase { 0x00]) } - func testCreatev3() { + @Test func testCreatev3() { let creator = ID3LocalizedFrameCreator( id3FrameConfiguration: ID3FrameConfiguration(), frameHeaderCreator: MockFrameHeaderCreator(), @@ -45,7 +45,7 @@ class ID3LocalizedFrameCreatorTest: XCTestCase { version: .version3, frameType: .unsyncronisedLyrics) - XCTAssertEqual(frame, + #expect(frame == [0x01, 0x02, 0x01, 0x69, 0x74, 0x61, 0xFF, 0xFE, 0x63, 0x00, 0x6F, 0x00, 0x6E, 0x00, 0x74, 0x00, 0x65, 0x00, 0x6E, 0x00, 0x74, 0x00, 0x20, 0x00, 0x64, 0x00, 0x65, 0x00, 0x73, 0x00, 0x63, 0x00, 0x72, 0x00, 0x69, 0x00, @@ -54,7 +54,7 @@ class ID3LocalizedFrameCreatorTest: XCTestCase { 0x00]) } - func testCreatev4() { + @Test func testCreatev4() { let creator = ID3LocalizedFrameCreator( id3FrameConfiguration: ID3FrameConfiguration(), frameHeaderCreator: MockFrameHeaderCreator(), @@ -67,7 +67,7 @@ class ID3LocalizedFrameCreatorTest: XCTestCase { version: .version4, frameType: .unsyncronisedLyrics) - XCTAssertEqual(frame, + #expect(frame == [0x01, 0x02, 0x01, 0x69, 0x74, 0x61, 0xFF, 0xFE, 0x63, 0x00, 0x6F, 0x00, 0x6E, 0x00, 0x74, 0x00, 0x65, 0x00, 0x6E, 0x00, 0x74, 0x00, 0x20, 0x00, 0x64, 0x00, 0x65, 0x00, 0x73, 0x00, 0x63, 0x00, 0x72, 0x00, 0x69, 0x00, diff --git a/Tests/Create/ID3RecordingDateTimeFrameCreatorTest.swift b/Tests/Create/ID3RecordingDateTimeFrameCreatorTest.swift index eb987cbe..5c0cf246 100644 --- a/Tests/Create/ID3RecordingDateTimeFrameCreatorTest.swift +++ b/Tests/Create/ID3RecordingDateTimeFrameCreatorTest.swift @@ -5,11 +5,11 @@ // 2018 Fabrizio Duroni. // -import XCTest +import Testing @testable import ID3TagEditor -class ID3RecordingDateTimeFrameCreatorTest: XCTestCase { - func testFrameCreationWhenThereIsACompleteRecordingDateTime() { +struct ID3RecordingDateTimeFrameCreatorTest { + @Test func testFrameCreationWhenThereIsACompleteRecordingDateTime() { let newFrameBytes: [UInt8] = [1, 1] let recordingDateTime = RecordingDateTime(date: RecordingDate(day: 28, month: 7, year: 2018), time: RecordingTime(hour: 12, minute: 30)) @@ -29,8 +29,8 @@ class ID3RecordingDateTimeFrameCreatorTest: XCTestCase { let newTagBytes = id3TitleFrameCreator.createFrames(id3Tag: id3tag) - XCTAssertTrue(timestampCreator.createFromRecordingDateTimeHasBeenCalled) - XCTAssertEqual(newTagBytes, newFrameBytes) + #expect(timestampCreator.createFromRecordingDateTimeHasBeenCalled) + #expect(newTagBytes == newFrameBytes) } static let allTests = [ diff --git a/Tests/Create/ID3RecordingDayMonthFrameCreatorTest.swift b/Tests/Create/ID3RecordingDayMonthFrameCreatorTest.swift index fe62bc98..04401237 100644 --- a/Tests/Create/ID3RecordingDayMonthFrameCreatorTest.swift +++ b/Tests/Create/ID3RecordingDayMonthFrameCreatorTest.swift @@ -5,11 +5,11 @@ // 2018 Fabrizio Duroni. // -import XCTest +import Testing @testable import ID3TagEditor -class ID3RecordingDayMonthFrameCreatorTest: XCTestCase { - func testNoFrameCreationWhenThereIsNoDay() { +struct ID3RecordingDayMonthFrameCreatorTest { + @Test func testNoFrameCreationWhenThereIsNoDay() { let id3YearFrameCreator = ID3RecordingDayMonthFrameCreator( frameCreator: MockFrameFromStringContentCreator( fakeNewFrameAsByte: [], @@ -23,10 +23,10 @@ class ID3RecordingDayMonthFrameCreatorTest: XCTestCase { let newTagBytes = id3YearFrameCreator.createFrames(id3Tag: tag) - XCTAssertEqual(newTagBytes, []) + #expect(newTagBytes == []) } - func testNoFrameCreationWhenThereIsNoMonth() { + @Test func testNoFrameCreationWhenThereIsNoMonth() { let id3YearFrameCreator = ID3RecordingDayMonthFrameCreator( frameCreator: MockFrameFromStringContentCreator( fakeNewFrameAsByte: [], @@ -40,10 +40,10 @@ class ID3RecordingDayMonthFrameCreatorTest: XCTestCase { let newTagBytes = id3YearFrameCreator.createFrames(id3Tag: tag) - XCTAssertEqual(newTagBytes, []) + #expect(newTagBytes == []) } - func testFrameCreationWhenThereIsADayAndAMonth() { + @Test func testFrameCreationWhenThereIsADayAndAMonth() { let newFrameBytes: [UInt8] = [1, 1] let id3Tag = ID3Tag( version: .version3, @@ -58,7 +58,7 @@ class ID3RecordingDayMonthFrameCreatorTest: XCTestCase { let newTagBytes = id3TitleFrameCreator.createFrames(id3Tag: id3Tag) - XCTAssertEqual(newTagBytes, newFrameBytes) + #expect(newTagBytes == newFrameBytes) } static let allTests = [ diff --git a/Tests/Create/ID3TagCreatorTest.swift b/Tests/Create/ID3TagCreatorTest.swift index f2601414..4c1af673 100644 --- a/Tests/Create/ID3TagCreatorTest.swift +++ b/Tests/Create/ID3TagCreatorTest.swift @@ -5,38 +5,44 @@ // 2018 Fabrizio Duroni. // -import XCTest +import Foundation +import Testing + @testable import ID3TagEditor -class ID3TagCreatorTest: XCTestCase { - func testNoValidFrameData() { +struct ID3TagCreatorTest { + @Test func testNoValidFrameData() { let id3FramesCreator = ID3FramesCreator(id3FrameCreators: [MockID3FrameCreatorsChain()]) let id3TagHeaderCreator = ID3TagHeaderCreator(uInt32ToByteArrayAdapter: MockUInt32ToByteArrayAdapter(), id3TagConfiguration: ID3TagConfiguration()) let id3TagCreator = ID3TagCreator(id3FramesCreator: id3FramesCreator, id3TagHeaderCreator: id3TagHeaderCreator) - XCTAssertThrowsError(try id3TagCreator.create(id3Tag: ID32v3TagBuilder().build())) + #expect(throws: ID3TagEditorError.invalidTagData.self) { + try id3TagCreator.create(id3Tag: ID32v3TagBuilder().build()) + } } - func testTagTooBig() { + @Test func testTagTooBig() { let id3FrameCreators = [MockID3FrameCreatorsChain(frames: [UInt8](repeating: 0x0, count: 0xFFFFFFF))] let id3FramesCreator = ID3FramesCreator(id3FrameCreators: id3FrameCreators) let id3TagHeaderCreator = ID3TagHeaderCreator(uInt32ToByteArrayAdapter: MockUInt32ToByteArrayAdapter(), id3TagConfiguration: ID3TagConfiguration()) let id3TagCreator = ID3TagCreator(id3FramesCreator: id3FramesCreator, id3TagHeaderCreator: id3TagHeaderCreator) - XCTAssertThrowsError(try id3TagCreator.create(id3Tag: ID32v3TagBuilder().build())) + #expect(throws: ID3TagEditorError.tagTooBig.self) { + try id3TagCreator.create(id3Tag: ID32v3TagBuilder().build()) + } } - func testGenerateValidData() { + @Test func testGenerateValidData() { let id3FrameCreators = [MockID3FrameCreatorsChain(frames: [0x22, 0x33])] let id3FramesCreator = ID3FramesCreator(id3FrameCreators: id3FrameCreators) let id3TagHeaderCreator = ID3TagHeaderCreator(uInt32ToByteArrayAdapter: MockUInt32ToByteArrayAdapter(), id3TagConfiguration: ID3TagConfiguration()) let id3TagCreator = ID3TagCreator(id3FramesCreator: id3FramesCreator, id3TagHeaderCreator: id3TagHeaderCreator) - XCTAssertEqual( - try? id3TagCreator.create(id3Tag: ID32v3TagBuilder().build()), + #expect( + try! id3TagCreator.create(id3Tag: ID32v3TagBuilder().build()) == Data(ID3TagConfiguration().headerFor(version: .version3) + [0x0, 0x3, 0x2, 0x22, 0x33] + [UInt8](repeating: 0x0, count: 2048) ) diff --git a/Tests/Create/ID3TimestampCreatorTest.swift b/Tests/Create/ID3TimestampCreatorTest.swift index 17d5e98f..8ec4d529 100644 --- a/Tests/Create/ID3TimestampCreatorTest.swift +++ b/Tests/Create/ID3TimestampCreatorTest.swift @@ -5,59 +5,59 @@ // 2018 Fabrizio Duroni. // -import XCTest +import Testing @testable import ID3TagEditor -class ID3TimestampCreatorTest: XCTestCase { - func testCreateTimestampCorrectly() { +struct ID3TimestampCreatorTest { + @Test func testCreateTimestampCorrectly() { let recordingTime = RecordingDateTime(date: RecordingDate(day: 28, month: 7, year: 2018), time: RecordingTime(hour: 12, minute: 35)) let timestampCreator = ID3TimestampCreator() - XCTAssertEqual(timestampCreator.createFrom(recordingDateTime: recordingTime), "1532781300") + #expect(timestampCreator.createFrom(recordingDateTime: recordingTime) == "1532781300") } - func testNilDay() { + @Test func testNilDay() { let recordingTime = RecordingDateTime(date: RecordingDate(day: nil, month: 7, year: 2018), time: RecordingTime(hour: 12, minute: 35)) let timestampCreator = ID3TimestampCreator() - XCTAssertEqual(timestampCreator.createFrom(recordingDateTime: recordingTime), nil) + #expect(timestampCreator.createFrom(recordingDateTime: recordingTime) == nil) } - func testNilMonth() { + @Test func testNilMonth() { let recordingTime = RecordingDateTime(date: RecordingDate(day: 28, month: nil, year: 2018), time: RecordingTime(hour: 12, minute: 35)) let timestampCreator = ID3TimestampCreator() - XCTAssertEqual(timestampCreator.createFrom(recordingDateTime: recordingTime), nil) + #expect(timestampCreator.createFrom(recordingDateTime: recordingTime) == nil) } - func testNilYear() { + @Test func testNilYear() { let recordingTime = RecordingDateTime(date: RecordingDate(day: 28, month: 7, year: nil), time: RecordingTime(hour: 12, minute: 35)) let timestampCreator = ID3TimestampCreator() - XCTAssertEqual(timestampCreator.createFrom(recordingDateTime: recordingTime), nil) + #expect(timestampCreator.createFrom(recordingDateTime: recordingTime) == nil) } - func testNilHour() { + @Test func testNilHour() { let recordingTime = RecordingDateTime(date: RecordingDate(day: 28, month: 7, year: 2018), time: RecordingTime(hour: nil, minute: 35)) let timestampCreator = ID3TimestampCreator() - XCTAssertEqual(timestampCreator.createFrom(recordingDateTime: recordingTime), nil) + #expect(timestampCreator.createFrom(recordingDateTime: recordingTime) == nil) } - func testNilMinute() { + @Test func testNilMinute() { let recordingTime = RecordingDateTime(date: RecordingDate(day: 28, month: 7, year: 2018), time: RecordingTime(hour: 12, minute: nil)) let timestampCreator = ID3TimestampCreator() - XCTAssertEqual(timestampCreator.createFrom(recordingDateTime: recordingTime), nil) + #expect(timestampCreator.createFrom(recordingDateTime: recordingTime) == nil) } - static var allTests = [ + static let allTests = [ ("testCreateTimestampCorrectly", testCreateTimestampCorrectly), ("testNilDay", testNilDay), ("testNilMonth", testNilMonth), diff --git a/Tests/Create/ID3TrackPositionFrameCreatorTest.swift b/Tests/Create/ID3TrackPositionFrameCreatorTest.swift index 93a06ee6..cc9be1d6 100644 --- a/Tests/Create/ID3TrackPositionFrameCreatorTest.swift +++ b/Tests/Create/ID3TrackPositionFrameCreatorTest.swift @@ -5,11 +5,11 @@ // 2018 Fabrizio Duroni. // -import XCTest +import Testing @testable import ID3TagEditor -class ID3TrackPositionCreatorTest: XCTestCase { - func testNoFrameCreationWhenThereIsNoTrackPosition() { +struct ID3TrackPositionCreatorTest { + @Test func testNoFrameCreationWhenThereIsNoTrackPosition() { let id3TrackPositionFrameCreator = ID3TrackPositionFrameCreator( frameCreator: MockFrameFromStringContentCreator( fakeNewFrameAsByte: [], @@ -21,10 +21,10 @@ class ID3TrackPositionCreatorTest: XCTestCase { id3Tag: ID32v3TagBuilder().build() ) - XCTAssertEqual(newTagBytes, []) + #expect(newTagBytes == []) } - func testFrameCreationWhenThereIsATrackPosition() { + @Test func testFrameCreationWhenThereIsATrackPosition() { let newFrameBytes: [UInt8] = [1, 1] let id3Tag = ID32v3TagBuilder() .trackPosition(frame: ID3FramePartOfTotal(part: 1, total: 10)) @@ -39,7 +39,7 @@ class ID3TrackPositionCreatorTest: XCTestCase { let newTagBytes = id3GenreFrameCreator.createFrames(id3Tag: id3Tag) - XCTAssertEqual(newTagBytes, newFrameBytes) + #expect(newTagBytes == newFrameBytes) } static let allTests = [ diff --git a/Tests/Create/ID3UTF16StringToByteAdapterTest.swift b/Tests/Create/ID3UTF16StringToByteAdapterTest.swift index 44d16752..d55223a3 100644 --- a/Tests/Create/ID3UTF16StringToByteAdapterTest.swift +++ b/Tests/Create/ID3UTF16StringToByteAdapterTest.swift @@ -5,22 +5,22 @@ // 2018 Fabrizio Duroni. // -import XCTest +import Testing @testable import ID3TagEditor -class ID3UTF16StringToByteAdapterTest: XCTestCase { +struct ID3UTF16StringToByteAdapterTest { private let ENCODING: [UInt8] = [0x01] private let BOM: [UInt8] = [0xFF, 0xFE] private let STRING: [UInt8] = [0x3A, 0x0, 0x3A, 0x0, 0x61, 0x0, 0x20, 0x0, 0x73, 0x0, 0x74, 0x0, 0x72, 0x0, 0x69, 0x0, 0x6E, 0x0, 0x67, 0x0, 0x3A, 0x0, 0x3A, 0x0, 0x0] - func testEncodeStringToUTF16WithEncodingByte() { + @Test func testEncodeStringToUTF16WithEncodingByte() { let adapter = ID3UTF16StringToByteAdapter(paddingAdder: MockPaddingAdder(), frameConfiguration: ID3FrameConfiguration()) let bytes = adapter.adapt(string: "::a string::", for: .version3) - XCTAssertEqual(bytes, ENCODING + BOM + STRING) + #expect(bytes == ENCODING + BOM + STRING) } static let allTests = [ diff --git a/Tests/Frame/ID3FrameConfigurationTest.swift b/Tests/Frame/ID3FrameConfigurationTest.swift index 1c096af1..6f4fa005 100644 --- a/Tests/Frame/ID3FrameConfigurationTest.swift +++ b/Tests/Frame/ID3FrameConfigurationTest.swift @@ -5,15 +5,15 @@ // 2018 Fabrizio Duroni. // -import XCTest +import Testing @testable import ID3TagEditor -class ID3FrameConfigurationTest: XCTestCase { - func testInvalidIdentifierName() { - XCTAssertEqual(ID3FrameConfiguration().frameTypeFor(identifier: "::not-valid::", version: .version2), .invalid) +struct ID3FrameConfigurationTest { + @Test func invalidIdentifierName() { + #expect(ID3FrameConfiguration().frameTypeFor(identifier: "::not-valid::", version: .version2) == .invalid) } static let allTests = [ - ("testInvalidIdentifierName", testInvalidIdentifierName) + ("testInvalidIdentifierName", invalidIdentifierName) ] } diff --git a/Tests/Mock/MockStringToBytesAdapter.swift b/Tests/Mock/MockStringToBytesAdapter.swift index f92c775c..42fd6bc3 100644 --- a/Tests/Mock/MockStringToBytesAdapter.swift +++ b/Tests/Mock/MockStringToBytesAdapter.swift @@ -9,7 +9,7 @@ import Foundation @testable import ID3TagEditor -class MockStringToBytesAdapter: StringToBytesAdapter { +final class MockStringToBytesAdapter: StringToBytesAdapter { func adapt(string: String, for version: ID3Version) -> [UInt8] { return string.utf16ToBytes } diff --git a/Tests/Mock/MockSynchsafeEncoder.swift b/Tests/Mock/MockSynchsafeEncoder.swift index d98da559..823d7ae9 100644 --- a/Tests/Mock/MockSynchsafeEncoder.swift +++ b/Tests/Mock/MockSynchsafeEncoder.swift @@ -15,6 +15,6 @@ class MockSynchsafeEncoder: SynchsafeEncoder { self.encodedValue = encodedValue } func encode(integer: UInt32) -> UInt32 { - return encodedValue + return self.encodedValue } } diff --git a/Tests/Mock/MockTimestampCreator.swift b/Tests/Mock/MockTimestampCreator.swift index efc1d1cc..8392a836 100644 --- a/Tests/Mock/MockTimestampCreator.swift +++ b/Tests/Mock/MockTimestampCreator.swift @@ -17,7 +17,7 @@ class MockTimestampCreator: TimestampCreator { } func createFrom(recordingDateTime: RecordingDateTime) -> String? { - createFromRecordingDateTimeHasBeenCalled = true - return returnValue + self.createFromRecordingDateTimeHasBeenCalled = true + return self.returnValue } } diff --git a/Tests/Mp3/Mp3FileReaderTest.swift b/Tests/Mp3/Mp3FileReaderTest.swift index 90253b78..b9c96e17 100644 --- a/Tests/Mp3/Mp3FileReaderTest.swift +++ b/Tests/Mp3/Mp3FileReaderTest.swift @@ -5,51 +5,51 @@ // 2018 Fabrizio Duroni. // -import XCTest +import Testing @testable import ID3TagEditor -class Mp3FileReaderTest: XCTestCase { - func testNotAnMP3FileWhenReadingEntireFile() { +struct Mp3FileReaderTest { + @Test func testNotAnMP3FileWhenReadingEntireFile() { let path = PathLoader().pathFor(name: "example-cover", fileType: "jpg") let mp3FileReader = Mp3FileReader(tagSizeParser: ID3TagSizeParser(), id3TagConfiguration: ID3TagConfiguration()) - XCTAssertThrowsError(try mp3FileReader.readFileFrom(path: path)) + #expect(throws: ID3TagEditorError.invalidFileFormat.self) { try mp3FileReader.readFileFrom(path: path) } } - func testMP3FileWhenReadingEntireFile() { + @Test func testMP3FileWhenReadingEntireFile() { let path = PathLoader().pathFor(name: "example", fileType: "mp3") let mp3FileReader = Mp3FileReader(tagSizeParser: ID3TagSizeParser(), id3TagConfiguration: ID3TagConfiguration()) - XCTAssertNoThrow(try mp3FileReader.readFileFrom(path: path)) + #expect(throws: Never.self) { try mp3FileReader.readFileFrom(path: path) } } - func testNotAnMP3fileWhenReadingID3Tag() { + @Test func testNotAnMP3fileWhenReadingID3Tag() { let path = PathLoader().pathFor(name: "example-cover", fileType: "jpg") let mp3FileReader = Mp3FileReader(tagSizeParser: ID3TagSizeParser(), id3TagConfiguration: ID3TagConfiguration()) - XCTAssertThrowsError(try mp3FileReader.readID3TagFrom(path: path)) + #expect(throws: ID3TagEditorError.invalidFileFormat.self) { try mp3FileReader.readID3TagFrom(path: path) } } - func testMP3fileWhenReadingID3Tag() { + @Test func testMP3fileWhenReadingID3Tag() { let path = PathLoader().pathFor(name: "example", fileType: "mp3") let mp3FileReader = Mp3FileReader(tagSizeParser: ID3TagSizeParser(), id3TagConfiguration: ID3TagConfiguration()) - XCTAssertNoThrow(try mp3FileReader.readID3TagFrom(path: path)) + #expect(throws: Never.self) { try mp3FileReader.readID3TagFrom(path: path) } } - func testNonExistentMP3fileWhenReadingID3Tag() { + @Test func testNonExistentMP3fileWhenReadingID3Tag() { let path = "/non-existent.mp3" let mp3FileReader = Mp3FileReader(tagSizeParser: ID3TagSizeParser(), id3TagConfiguration: ID3TagConfiguration()) - XCTAssertThrowsError(try mp3FileReader.readID3TagFrom(path: path)) + #expect(throws: ID3TagEditorError.corruptedFile.self) { try mp3FileReader.readID3TagFrom(path: path) } } - func testOnlyReadsID3Tag() throws { + @Test func testOnlyReadsID3Tag() throws { let path = PathLoader().pathFor(name: "example", fileType: "mp3") let mp3FileReader = Mp3FileReader(tagSizeParser: ID3TagSizeParser(), id3TagConfiguration: ID3TagConfiguration()) @@ -57,7 +57,7 @@ class Mp3FileReaderTest: XCTestCase { let id3TagData = try mp3FileReader.readID3TagFrom(path: path) // 10 bytes Tag + 34213 bytes according to the Tag Size in the file's ID3 Tag - XCTAssertEqual(id3TagData.count, 10 + 34213) + #expect(id3TagData.count == 10 + 34213) } static let allTests = [ diff --git a/Tests/Parse/ID3AttachedPictureFrameContentParsingOperationTest.swift b/Tests/Parse/ID3AttachedPictureFrameContentParsingOperationTest.swift index 0356fd66..3f314318 100644 --- a/Tests/Parse/ID3AttachedPictureFrameContentParsingOperationTest.swift +++ b/Tests/Parse/ID3AttachedPictureFrameContentParsingOperationTest.swift @@ -5,52 +5,56 @@ // 2018 Fabrizio Duroni. // -import XCTest +import Foundation +import Testing + @testable import ID3TagEditor -class ID3AttachedPictureFrameContentParsingOperationTest: XCTestCase { - func testSetTagAttachedPicturePng() { - let expectation = XCTestExpectation(description: "attached picture") +struct ID3AttachedPictureFrameContentParsingOperationTest { + @Test func testSetTagAttachedPicturePng() async { let attachedPictureFrameContentParsingOperation = ID3AttachedPictureFrameContentParsingOperation( id3FrameConfiguration: ID3FrameConfiguration(), pictureTypeAdapter: MockPictureTypeAdapter() ) - - attachedPictureFrameContentParsingOperation.parse( - frame: Data([0x89, 0x50, 0x4E, 0x47, 0x11, 0x11]), - version: .version3, - completed: {(frameName, frame) in - XCTAssertEqual(frameName, .attachedPicture(.frontCover)) - XCTAssertEqual((frame as? ID3FrameAttachedPicture)?.format, .png) - XCTAssertEqual( - (frame as? ID3FrameAttachedPicture)?.picture, - Data([0x89, 0x50, 0x4E, 0x47, 0x11, 0x11]) - ) - XCTAssertEqual((frame as? ID3FrameAttachedPicture)?.type, .frontCover) - expectation.fulfill() - }) + + await confirmation("attached picture") { parsed in + attachedPictureFrameContentParsingOperation.parse( + frame: Data([0x89, 0x50, 0x4E, 0x47, 0x11, 0x11]), + version: .version3, + completed: {(frameName, frame) in + #expect(frameName == .attachedPicture(.frontCover)) + #expect((frame as? ID3FrameAttachedPicture)?.format == .png) + #expect( + (frame as? ID3FrameAttachedPicture)?.picture == + Data([0x89, 0x50, 0x4E, 0x47, 0x11, 0x11]) + ) + #expect((frame as? ID3FrameAttachedPicture)?.type == .frontCover) + parsed() + }) + } } - func testSetTagAttachedPictureJpg() { - let expectation = XCTestExpectation(description: "attached picture") + @Test func testSetTagAttachedPictureJpg() async { let attachedPictureFrameContentParsingOperation = ID3AttachedPictureFrameContentParsingOperation( id3FrameConfiguration: ID3FrameConfiguration(), pictureTypeAdapter: MockPictureTypeAdapter() ) - attachedPictureFrameContentParsingOperation.parse( + await confirmation("attached picture") { parsed in + attachedPictureFrameContentParsingOperation.parse( frame: Data([0xFF, 0xD8, 0xFF, 0xE0, 0x11, 0x11]), version: .version3, completed: {(frameName, frame) in - XCTAssertEqual(frameName, .attachedPicture(.frontCover)) - XCTAssertEqual((frame as? ID3FrameAttachedPicture)?.format, .jpeg) - XCTAssertEqual( - (frame as? ID3FrameAttachedPicture)?.picture, + #expect(frameName == .attachedPicture(.frontCover)) + #expect((frame as? ID3FrameAttachedPicture)?.format == .jpeg) + #expect( + (frame as? ID3FrameAttachedPicture)?.picture == Data([0xFF, 0xD8, 0xFF, 0xE0, 0x11, 0x11]) ) - XCTAssertEqual((frame as? ID3FrameAttachedPicture)?.type, .frontCover) - expectation.fulfill() - }) + #expect((frame as? ID3FrameAttachedPicture)?.type == .frontCover) + parsed() + }) + } } static let allTests = [ diff --git a/Tests/Parse/ID3DiscPositionStringAdapterTest.swift b/Tests/Parse/ID3DiscPositionStringAdapterTest.swift index c44fceb7..6381e79a 100644 --- a/Tests/Parse/ID3DiscPositionStringAdapterTest.swift +++ b/Tests/Parse/ID3DiscPositionStringAdapterTest.swift @@ -5,31 +5,29 @@ // 2018 Fabrizio Duroni. // -import XCTest +import Testing @testable import ID3TagEditor -class ID3DiscPositionStringAdapterTest: XCTestCase { - let discPositionStringAdapter = ID3PartOfTotalStringAdapter() +struct ID3DiscPositionStringAdapterTest { + @Test func testAdaptDiscPositionWithTotalDiscs() { + let discPosition = ID3PartOfTotalStringAdapter().adapt(partOfTotal: "1/3") - func testAdaptDiscPositionWithTotalDiscs() { - let discPosition = discPositionStringAdapter.adapt(partOfTotal: "1/3") - - XCTAssertEqual(discPosition.part, 1) - XCTAssertEqual(discPosition.total, 3) + #expect(discPosition.part == 1) + #expect(discPosition.total == 3) } - func testAdaptDiscPositionWithoutTotalDiscs() { - let discPosition = discPositionStringAdapter.adapt(partOfTotal: "1") + @Test func testAdaptDiscPositionWithoutTotalDiscs() { + let discPosition = ID3PartOfTotalStringAdapter().adapt(partOfTotal: "1") - XCTAssertEqual(discPosition.part, 1) - XCTAssertNil(discPosition.total) + #expect(discPosition.part == 1) + #expect(discPosition.total == nil) } - func testAdaptNotANumberDiscPosition() { - let discPosition = discPositionStringAdapter.adapt(partOfTotal: "::invalid::") + @Test func testAdaptNotANumberDiscPosition() { + let discPosition = ID3PartOfTotalStringAdapter().adapt(partOfTotal: "::invalid::") - XCTAssertEqual(discPosition.part, 0) - XCTAssertNil(discPosition.total) + #expect(discPosition.part == 0) + #expect(discPosition.total == nil) } static let allTests = [ diff --git a/Tests/Parse/ID3FrameContentSizeParserTest.swift b/Tests/Parse/ID3FrameContentSizeParserTest.swift index a750256b..53c4a0d8 100644 --- a/Tests/Parse/ID3FrameContentSizeParserTest.swift +++ b/Tests/Parse/ID3FrameContentSizeParserTest.swift @@ -5,47 +5,56 @@ // 2018 Fabrizio Duroni. // -import XCTest -@testable import ID3TagEditor +import Foundation +import Testing -class ID3FrameContentSizeParserTest: XCTestCase { - let id3FrameContentSizeParser = ID3FrameContentSizeParser( - id3FrameConfiguration: ID3FrameConfiguration(), - synchsafeIntegerDecoder: SynchsafeIntegerDecoder() - ) +@testable import ID3TagEditor - func testParseFrameContentSizeV2() { +@Suite struct ID3FrameContentSizeParserTest { + @Test func testParseFrameContentSizeV2() { + let id3FrameContentSizeParser = ID3FrameContentSizeParser( + id3FrameConfiguration: ID3FrameConfiguration(), + synchsafeIntegerDecoder: SynchsafeIntegerDecoder() + ) let mp3 = NSData(contentsOfFile: PathLoader().pathFor(name: "example", fileType: "mp3"))! - XCTAssertEqual( + #expect( id3FrameContentSizeParser.parse( mp3: mp3, framePosition: ID3TagConfiguration().headerSize(), version: .version2 - ), + ) == 31 ) } - func testParseFrameContentSizeV3() { + @Test func testParseFrameContentSizeV3() { + let id3FrameContentSizeParser = ID3FrameContentSizeParser( + id3FrameConfiguration: ID3FrameConfiguration(), + synchsafeIntegerDecoder: SynchsafeIntegerDecoder() + ) let mp3 = NSData(contentsOfFile: PathLoader().pathFor(name: "example-v23-png", fileType: "mp3"))! - XCTAssertEqual( + #expect( id3FrameContentSizeParser.parse( mp3: mp3, framePosition: ID3TagConfiguration().headerSize(), version: .version3 - ), + ) == 13 ) } - func testParseFrameContentSizeV4() { + @Test func testParseFrameContentSizeV4() { + let id3FrameContentSizeParser = ID3FrameContentSizeParser( + id3FrameConfiguration: ID3FrameConfiguration(), + synchsafeIntegerDecoder: SynchsafeIntegerDecoder() + ) let mp3 = NSData(contentsOfFile: PathLoader().pathFor(name: "example-v4-png", fileType: "mp3"))! - XCTAssertEqual( + #expect( id3FrameContentSizeParser.parse( mp3: mp3, framePosition: ID3TagConfiguration().headerSize(), version: .version4 - ), + ) == 14 ) } diff --git a/Tests/Parse/ID3FrameSizeParserTest.swift b/Tests/Parse/ID3FrameSizeParserTest.swift index 21d9d4f0..d48f6f1e 100644 --- a/Tests/Parse/ID3FrameSizeParserTest.swift +++ b/Tests/Parse/ID3FrameSizeParserTest.swift @@ -5,38 +5,40 @@ // 2018 Fabrizio Duroni. // -import XCTest +import Foundation +import Testing + @testable import ID3TagEditor -class ID3FrameSizeParserTest: XCTestCase { - func testParseFrameContentSizeV2() { +struct ID3FrameSizeParserTest { + @Test func testParseFrameContentSizeV2() { let mp3 = NSData(contentsOfFile: PathLoader().pathFor(name: "example", fileType: "mp3"))! let id3FrameSizeParser = ID3FrameSizeParser( frameContentSizeParser: MockFrameContentSizeParser(), id3FrameConfiguration: ID3FrameConfiguration() ) - XCTAssertEqual( + #expect( id3FrameSizeParser.parse( mp3: mp3, framePosition: ID3TagConfiguration().headerSize(), version: .version2 - ), + ) == mp3.length + ID3FrameConfiguration().headerSizeFor(version: .version2) ) } - func testParseFrameContentSizeV3() { + @Test func testParseFrameContentSizeV3() { let mp3 = NSData(contentsOfFile: PathLoader().pathFor(name: "example", fileType: "mp3"))! let id3FrameSizeParser = ID3FrameSizeParser( frameContentSizeParser: MockFrameContentSizeParser(), id3FrameConfiguration: ID3FrameConfiguration() ) - XCTAssertEqual( + #expect( id3FrameSizeParser.parse( mp3: mp3, framePosition: ID3TagConfiguration().headerSize(), version: .version3 - ), + ) == mp3.length + ID3FrameConfiguration().headerSizeFor(version: .version3) ) } diff --git a/Tests/Parse/ID3GenreStringAdapterTest.swift b/Tests/Parse/ID3GenreStringAdapterTest.swift index 102b46ca..438f8993 100644 --- a/Tests/Parse/ID3GenreStringAdapterTest.swift +++ b/Tests/Parse/ID3GenreStringAdapterTest.swift @@ -5,38 +5,36 @@ // 2018 Fabrizio Duroni. // -import XCTest +import Testing @testable import ID3TagEditor -class ID3GenreStringAdapterTest: XCTestCase { - private let id3GenreStringAdapter = ID3GenreStringAdapter() +@Suite struct ID3GenreStringAdapterTest { + @Test func testAdaptGenreWithDescription() { + let genre = ID3GenreStringAdapter().adapt(genre: "(9)Metalcore") - func testAdaptGenreWithDescription() { - let genre = id3GenreStringAdapter.adapt(genre: "(9)Metalcore") - - XCTAssert(genre.identifier == .metal) - XCTAssertEqual(genre.description, "Metalcore") + #expect(genre.identifier == .metal) + #expect(genre.description == "Metalcore") } - func testAdaptGenreWithoutDescription() { - let genre = id3GenreStringAdapter.adapt(genre: "(9)") + @Test func testAdaptGenreWithoutDescription() { + let genre = ID3GenreStringAdapter().adapt(genre: "(9)") - XCTAssert(genre.identifier == .metal) - XCTAssertNil(genre.description) + #expect(genre.identifier == .metal) + #expect(genre.description == nil) } - func testAdaptGenreWithoutGenreIdentifier() { - let genre = id3GenreStringAdapter.adapt(genre: "Rock & Roll") + @Test func testAdaptGenreWithoutGenreIdentifier() { + let genre = ID3GenreStringAdapter().adapt(genre: "Rock & Roll") - XCTAssertNil(genre.identifier) - XCTAssertEqual(genre.description, "Rock & Roll") + #expect(genre.identifier == nil) + #expect(genre.description == "Rock & Roll") } - func testAdaptID3v3NewGenresNotNumeric() { - XCTAssertEqual(id3GenreStringAdapter.adapt(genre: "(RX)").identifier, .remix) - XCTAssertEqual(id3GenreStringAdapter.adapt(genre: "(CR)").identifier, .cover) - XCTAssertNil(id3GenreStringAdapter.adapt(genre: "(XXX)").identifier) - XCTAssertEqual(id3GenreStringAdapter.adapt(genre: "(XXX)").description, "(XXX)") + @Test func testAdaptID3v3NewGenresNotNumeric() { + #expect(ID3GenreStringAdapter().adapt(genre: "(RX)").identifier == .remix) + #expect(ID3GenreStringAdapter().adapt(genre: "(CR)").identifier == .cover) + #expect(ID3GenreStringAdapter().adapt(genre: "(XXX)").identifier == nil) + #expect(ID3GenreStringAdapter().adapt(genre: "(XXX)").description == "(XXX)") } static let allTests = [ diff --git a/Tests/Parse/ID3LocalizedFrameParsingOperationTest.swift b/Tests/Parse/ID3LocalizedFrameParsingOperationTest.swift index 22ec33c9..15879b8c 100644 --- a/Tests/Parse/ID3LocalizedFrameParsingOperationTest.swift +++ b/Tests/Parse/ID3LocalizedFrameParsingOperationTest.swift @@ -1,42 +1,40 @@ -// -// ID3LocalizedFrameParsingOperationTest.swift -// ID3TagEditor -// -// Created by Fabrizio Duroni on 14/10/20. -// 2020 Fabrizio Duroni. -// +//// +//// ID3LocalizedFrameParsingOperationTest.swift +//// ID3TagEditor +//// +//// Created by Fabrizio Duroni on 14/10/20. +//// 2020 Fabrizio Duroni. +//// -import XCTest -@testable import ID3TagEditor +import Foundation +import Testing -class ID3LocalizedFrameParsingOperationTest: XCTestCase { - func testParsingValidFrame() { - let expectation = XCTestExpectation(description: "unsynchronised lyrics") +@testable import ID3TagEditor - let lyricsOperation = ID3LocalizedFrameContentParsingOperationFactory.make( - frameName: FrameName.unsynchronizedLyrics - ) +struct ID3LocalizedFrameParsingOperationTest { + @Test func testParsingValidFrame() async { + let lyricsOperation = ID3LocalizedFrameContentParsingOperationFactory.make(frameName: FrameName.unsynchronizedLyrics) - lyricsOperation.parse(frame: frameV3Valid(), version: .version3) { (_, frame) in - XCTAssertEqual((frame as? ID3FrameWithLocalizedContent)?.content, "c") - XCTAssertEqual((frame as? ID3FrameWithLocalizedContent)?.contentDescription, "cd") - XCTAssertEqual((frame as? ID3FrameWithLocalizedContent)?.language, .ita) - expectation.fulfill() + await confirmation("unsynchronised lyrics") { fulfill in + lyricsOperation.parse(frame: frameV3Valid(), version: .version3) { (_, frame) in + #expect((frame as? ID3FrameWithLocalizedContent)?.content == "c") + #expect((frame as? ID3FrameWithLocalizedContent)?.contentDescription == "cd") + #expect((frame as? ID3FrameWithLocalizedContent)?.language == .ita) + fulfill() + } } } - func testParsingInvalidLanguage() { - let expectation = XCTestExpectation(description: "unsynchronised lyrics") - - let lyricsOperation = ID3LocalizedFrameContentParsingOperationFactory.make( - frameName: FrameName.unsynchronizedLyrics - ) + @Test func testParsingInvalidLanguage() async { + let lyricsOperation = ID3LocalizedFrameContentParsingOperationFactory.make(frameName: FrameName.unsynchronizedLyrics) - lyricsOperation.parse(frame: frameV3InvalidLanguage(), version: .version3) { (_, frame) in - XCTAssertEqual((frame as? ID3FrameWithLocalizedContent)?.content, "c") - XCTAssertEqual((frame as? ID3FrameWithLocalizedContent)?.contentDescription, "cd") - XCTAssertEqual((frame as? ID3FrameWithLocalizedContent)?.language, .unknown) - expectation.fulfill() + await confirmation("unsynchronised lyrics") { fulfill in + lyricsOperation.parse(frame: frameV3InvalidLanguage(), version: .version3) { (_, frame) in + #expect((frame as? ID3FrameWithLocalizedContent)?.content == "c") + #expect((frame as? ID3FrameWithLocalizedContent)?.contentDescription == "cd") + #expect((frame as? ID3FrameWithLocalizedContent)?.language == .unknown) + fulfill() + } } } diff --git a/Tests/Parse/ID3PictureTypeAdapterTest.swift b/Tests/Parse/ID3PictureTypeAdapterTest.swift index e15443fb..7ae97145 100644 --- a/Tests/Parse/ID3PictureTypeAdapterTest.swift +++ b/Tests/Parse/ID3PictureTypeAdapterTest.swift @@ -5,31 +5,33 @@ // 2018 Fabrizio Duroni. // -import XCTest +import Foundation +import Testing + @testable import ID3TagEditor -class ID3PictureTypeAdapterTest: XCTestCase { - func testExtractTypeFromV2TagJpg() { +struct ID3PictureTypeAdapterTest { + @Test func testExtractTypeFromV2TagJpg() { let frame = Data([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00]) let id3PictureTypeAdapter = ID3PictureTypeAdapter( id3FrameConfiguration: ID3FrameConfiguration(), id3AttachedPictureFrameConfiguration: ID3AttachedPictureFrameConfiguration() ) - XCTAssertEqual(id3PictureTypeAdapter.adapt(frame: frame, format: .jpeg, version: .version2), .frontCover) + #expect(id3PictureTypeAdapter.adapt(frame: frame, format: .jpeg, version: .version2) == .frontCover) } - func testExtractTypeFromV2TagPng() { + @Test func testExtractTypeFromV2TagPng() { let frame = Data([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00]) let id3PictureTypeAdapter = ID3PictureTypeAdapter( id3FrameConfiguration: ID3FrameConfiguration(), id3AttachedPictureFrameConfiguration: ID3AttachedPictureFrameConfiguration() ) - XCTAssertEqual(id3PictureTypeAdapter.adapt(frame: frame, format: .png, version: .version2), .frontCover) + #expect(id3PictureTypeAdapter.adapt(frame: frame, format: .png, version: .version2) == .frontCover) } - func testExtractTypeFromV3TagJpg() { + @Test func testExtractTypeFromV3TagJpg() { let frame = Data([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00]) @@ -38,10 +40,10 @@ class ID3PictureTypeAdapterTest: XCTestCase { id3AttachedPictureFrameConfiguration: ID3AttachedPictureFrameConfiguration() ) - XCTAssertEqual(id3PictureTypeAdapter.adapt(frame: frame, format: .jpeg, version: .version3), .frontCover) + #expect(id3PictureTypeAdapter.adapt(frame: frame, format: .jpeg, version: .version3) == .frontCover) } - func testExtractTypeFromV3TagPng() { + @Test func testExtractTypeFromV3TagPng() { let frame = Data([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00]) @@ -50,7 +52,7 @@ class ID3PictureTypeAdapterTest: XCTestCase { id3AttachedPictureFrameConfiguration: ID3AttachedPictureFrameConfiguration() ) - XCTAssertEqual(id3PictureTypeAdapter.adapt(frame: frame, format: .png, version: .version3), .frontCover) + #expect(id3PictureTypeAdapter.adapt(frame: frame, format: .png, version: .version3) == .frontCover) } static let allTests = [ diff --git a/Tests/Parse/ID3RecordingTimestampOperationTest.swift b/Tests/Parse/ID3RecordingTimestampOperationTest.swift index 65a02c22..e45dc990 100644 --- a/Tests/Parse/ID3RecordingTimestampOperationTest.swift +++ b/Tests/Parse/ID3RecordingTimestampOperationTest.swift @@ -5,47 +5,50 @@ // 2018 Fabrizio Duroni. // -import XCTest +import Foundation +import Testing + @testable import ID3TagEditor -class ID3RecordingTimeFrameContentParsingOperationTest: XCTestCase { - func testframeContentValidTimestamp() { - let expectation = XCTestExpectation(description: "recording time") +struct ID3RecordingTimeFrameContentParsingOperationTest { + @Test func testframeContentValidTimestamp() async { let recordingTimeParsingOperation = ID3RecordingTimeFrameContentParsingOperation( stringContentParser: ID3FrameStringContentParserFactory.make() ) - recordingTimeParsingOperation.parse(frame: frameV4utf8Valid(), - version: .version4, - completed: {(frameName, frame) in - XCTAssertEqual(frameName, .recordingDateTime) - XCTAssertEqual((frame as? ID3FrameRecordingDateTime)?.recordingDateTime.date?.day, 27) - XCTAssertEqual((frame as? ID3FrameRecordingDateTime)?.recordingDateTime.date?.month, 7) - XCTAssertEqual((frame as? ID3FrameRecordingDateTime)?.recordingDateTime.date?.year, 2018) - XCTAssertEqual((frame as? ID3FrameRecordingDateTime)?.recordingDateTime.time?.hour, 11) - XCTAssertEqual((frame as? ID3FrameRecordingDateTime)?.recordingDateTime.time?.minute, 35) - expectation.fulfill() - - }) + await confirmation("recording time") { recordingTime in + recordingTimeParsingOperation.parse(frame: frameV4utf8Valid(), + version: .version4, + completed: {(frameName, frame) in + #expect(frameName == .recordingDateTime) + #expect((frame as? ID3FrameRecordingDateTime)?.recordingDateTime.date?.day == 27) + #expect((frame as? ID3FrameRecordingDateTime)?.recordingDateTime.date?.month == 7) + #expect((frame as? ID3FrameRecordingDateTime)?.recordingDateTime.date?.year == 2018) + #expect((frame as? ID3FrameRecordingDateTime)?.recordingDateTime.time?.hour == 11) + #expect((frame as? ID3FrameRecordingDateTime)?.recordingDateTime.time?.minute == 35) + recordingTime() + }) + } } - func testframeContentWithYearInsteadOfTimestamp() { - let expectation = XCTestExpectation(description: "recording time") + @Test func testframeContentWithYearInsteadOfTimestamp() async { let recordingTimeParsingOperation = ID3RecordingTimeFrameContentParsingOperation( stringContentParser: ID3FrameStringContentParserFactory.make() ) - recordingTimeParsingOperation.parse(frame: frameV4utf8Invalid(), - version: .version4, - completed: {(frameName, frame) in - XCTAssertEqual(frameName, .recordingDateTime) - XCTAssertNil((frame as? ID3FrameRecordingDateTime)?.recordingDateTime.date?.day) - XCTAssertNil((frame as? ID3FrameRecordingDateTime)?.recordingDateTime.date?.month) - XCTAssertEqual((frame as? ID3FrameRecordingDateTime)?.recordingDateTime.date?.year, 2016) - XCTAssertNil((frame as? ID3FrameRecordingDateTime)?.recordingDateTime.time?.hour) - XCTAssertNil((frame as? ID3FrameRecordingDateTime)?.recordingDateTime.time?.minute) - expectation.fulfill() - }) + await confirmation("recording time") { recordingTime in + recordingTimeParsingOperation.parse(frame: frameV4utf8Invalid(), + version: .version4, + completed: {(frameName, frame) in + #expect(frameName == .recordingDateTime) + #expect((frame as? ID3FrameRecordingDateTime)?.recordingDateTime.date?.day == nil) + #expect((frame as? ID3FrameRecordingDateTime)?.recordingDateTime.date?.month == nil) + #expect((frame as? ID3FrameRecordingDateTime)?.recordingDateTime.date?.year == 2016) + #expect((frame as? ID3FrameRecordingDateTime)?.recordingDateTime.time?.hour == nil) + #expect((frame as? ID3FrameRecordingDateTime)?.recordingDateTime.time?.minute == nil) + recordingTime() + }) + } } private func frameV4utf8Valid() -> Data { diff --git a/Tests/Parse/ID3StringContentParsingOperationTest.swift b/Tests/Parse/ID3StringContentParsingOperationTest.swift index 34eab1be..7dcd44cb 100644 --- a/Tests/Parse/ID3StringContentParsingOperationTest.swift +++ b/Tests/Parse/ID3StringContentParsingOperationTest.swift @@ -5,104 +5,150 @@ // 2018 Fabrizio Duroni. // -import XCTest +import Foundation +import Testing + @testable import ID3TagEditor -class ID3StringContentParsingOperationTest: XCTestCase { - private let stringContentParser = ID3FrameStringContentParser( - stringEncodingDetector: ID3FrameStringEncodingDetector( - id3FrameConfiguration: ID3FrameConfiguration(), - id3StringEncodingConverter: ID3StringEncodingConverter() - ), - paddingRemover: PaddingRemoverUsingTrimming(), - id3FrameConfiguration: ID3FrameConfiguration() - ) - - func testTooSmallDataValue() { +struct ID3StringContentParsingOperationTest { + @Test func testTooSmallDataValue() { + let stringContentParser = ID3FrameStringContentParser( + stringEncodingDetector: ID3FrameStringEncodingDetector( + id3FrameConfiguration: ID3FrameConfiguration(), + id3StringEncodingConverter: ID3StringEncodingConverter() + ), + paddingRemover: PaddingRemoverUsingTrimming(), + id3FrameConfiguration: ID3FrameConfiguration() + ) let value = stringContentParser.parse(frame: Data(capacity: 1), version: .version3) - XCTAssertNil(value) + #expect(value == nil) } - func testFrameContentParsedV2() { - let expectation = XCTestExpectation(description: "content without padding") + @Test func testFrameContentParsedV2() async { + let stringContentParser = ID3FrameStringContentParser( + stringEncodingDetector: ID3FrameStringEncodingDetector( + id3FrameConfiguration: ID3FrameConfiguration(), + id3StringEncodingConverter: ID3StringEncodingConverter() + ), + paddingRemover: PaddingRemoverUsingTrimming(), + id3FrameConfiguration: ID3FrameConfiguration() + ) let id3StringContentParsingOperation = ID3FrameStringContentParsingOperation( stringContentParser: stringContentParser ) { (_: String) in return (.title, ID3FrameWithStringContent(content: ":: value ::")) } - id3StringContentParsingOperation.parse(frame: frameV2(), version: .version2, completed: {(frameName, frame) in - XCTAssertEqual(frameName, .title) - XCTAssertEqual((frame as? ID3FrameWithStringContent)?.content, ":: value ::") - expectation.fulfill() - }) + await confirmation("content without padding") { fulfill in + id3StringContentParsingOperation.parse(frame: frameV2(), version: .version2, completed: {(frameName, frame) in + #expect(frameName == .title) + #expect((frame as? ID3FrameWithStringContent)?.content == ":: value ::") + fulfill() + }) + } } - func testFrameContentParsedV3() { - let expectation = XCTestExpectation(description: "content without padding") + @Test func testFrameContentParsedV3() async { + let stringContentParser = ID3FrameStringContentParser( + stringEncodingDetector: ID3FrameStringEncodingDetector( + id3FrameConfiguration: ID3FrameConfiguration(), + id3StringEncodingConverter: ID3StringEncodingConverter() + ), + paddingRemover: PaddingRemoverUsingTrimming(), + id3FrameConfiguration: ID3FrameConfiguration() + ) let id3StringContentParsingOperation = ID3FrameStringContentParsingOperation( stringContentParser: stringContentParser ) { (_: String) in return (.title, ID3FrameWithStringContent(content: ":: value ::")) } - id3StringContentParsingOperation.parse(frame: frameV3(), version: .version2, completed: {(frameName, frame) in - XCTAssertEqual(frameName, .title) - XCTAssertEqual((frame as? ID3FrameWithStringContent)?.content, ":: value ::") - expectation.fulfill() - }) + await confirmation("content without padding") { fulfill in + id3StringContentParsingOperation.parse(frame: frameV3(), version: .version2, completed: {(frameName, frame) in + #expect(frameName == .title) + #expect((frame as? ID3FrameWithStringContent)?.content == ":: value ::") + fulfill() + }) + } } - func testFrameContentParsedV2utf16() { - let expectation = XCTestExpectation(description: "content without padding") + @Test func testFrameContentParsedV2utf16() async { + let stringContentParser = ID3FrameStringContentParser( + stringEncodingDetector: ID3FrameStringEncodingDetector( + id3FrameConfiguration: ID3FrameConfiguration(), + id3StringEncodingConverter: ID3StringEncodingConverter() + ), + paddingRemover: PaddingRemoverUsingTrimming(), + id3FrameConfiguration: ID3FrameConfiguration() + ) let id3StringContentParsingOperation = ID3FrameStringContentParsingOperation( stringContentParser: stringContentParser ) { (_: String) in return (.title, ID3FrameWithStringContent(content: ":: π value ::")) } - id3StringContentParsingOperation.parse( - frame: frameV2utf16(), version: .version2, - completed: {(frameName, frame) in - XCTAssertEqual(frameName, .title) - XCTAssertEqual((frame as? ID3FrameWithStringContent)?.content, ":: π value ::") - expectation.fulfill() - }) + await confirmation("content without padding") { fulfill in + id3StringContentParsingOperation.parse( + frame: frameV2utf16(), version: .version2, + completed: {(frameName, frame) in + #expect(frameName == .title) + #expect((frame as? ID3FrameWithStringContent)?.content == ":: π value ::") + fulfill() + }) + } } - func testFrameContentParsedV3utf16() { - let expectation = XCTestExpectation(description: "content without padding") + @Test func testFrameContentParsedV3utf16() async { + let stringContentParser = ID3FrameStringContentParser( + stringEncodingDetector: ID3FrameStringEncodingDetector( + id3FrameConfiguration: ID3FrameConfiguration(), + id3StringEncodingConverter: ID3StringEncodingConverter() + ), + paddingRemover: PaddingRemoverUsingTrimming(), + id3FrameConfiguration: ID3FrameConfiguration() + ) let id3StringContentParsingOperation = ID3FrameStringContentParsingOperation( stringContentParser: stringContentParser ) { (_: String) in return (.title, ID3FrameWithStringContent(content: ":: π value ::")) } - id3StringContentParsingOperation.parse( - frame: frameV3utf16(), version: .version3, - completed: {(frameName, frame) in - XCTAssertEqual(frameName, .title) - XCTAssertEqual((frame as? ID3FrameWithStringContent)?.content, ":: π value ::") - expectation.fulfill() - }) + await confirmation("content without padding") { fulfill in + id3StringContentParsingOperation.parse( + frame: frameV3utf16(), version: .version3, + completed: {(frameName, frame) in + #expect(frameName == .title) + #expect((frame as? ID3FrameWithStringContent)?.content == ":: π value ::") + fulfill() + }) + } } - func testFrameContentParsedV4utf8() { - let expectation = XCTestExpectation(description: "content without padding") + @Test func testFrameContentParsedV4utf8() async { + let stringContentParser = ID3FrameStringContentParser( + stringEncodingDetector: ID3FrameStringEncodingDetector( + id3FrameConfiguration: ID3FrameConfiguration(), + id3StringEncodingConverter: ID3StringEncodingConverter() + ), + paddingRemover: PaddingRemoverUsingTrimming(), + id3FrameConfiguration: ID3FrameConfiguration() + ) let id3StringContentParsingOperation = ID3FrameStringContentParsingOperation( stringContentParser: stringContentParser ) { (_: String) in return (.title, ID3FrameWithStringContent(content: ":: π value ::")) } - id3StringContentParsingOperation.parse( - frame: frameV4utf8(), - version: .version4, - completed: {(frameName, frame) in - XCTAssertEqual(frameName, .title) - XCTAssertEqual((frame as? ID3FrameWithStringContent)?.content, ":: π value ::") - expectation.fulfill() - }) + await confirmation("content without padding") { fulfill in + id3StringContentParsingOperation.parse( + frame: frameV4utf8(), + version: .version4, + completed: {(frameName, frame) in + #expect(frameName == .title) + #expect((frame as? ID3FrameWithStringContent)?.content == ":: π value ::") + fulfill() + }) + } } private func frameV2() -> Data { diff --git a/Tests/Parse/ID3TagSizeParserTest.swift b/Tests/Parse/ID3TagSizeParserTest.swift index d8b773cb..b19d0b40 100644 --- a/Tests/Parse/ID3TagSizeParserTest.swift +++ b/Tests/Parse/ID3TagSizeParserTest.swift @@ -5,24 +5,24 @@ // 2018 Fabrizio Duroni. // -import XCTest -@testable import ID3TagEditor +import Foundation +import Testing -class ID3TagSizeParserTest: XCTestCase { - private let id3TagSizeParser = ID3TagSizeParser() +@testable import ID3TagEditor - func testParseTagSizeV2() { +struct ID3TagSizeParserTest { + @Test func parseTagSizeV2() { let mp3 = NSData(contentsOfFile: PathLoader().pathFor(name: "example", fileType: "mp3"))! - XCTAssertEqual(id3TagSizeParser.parse(data: mp3), 34213) + #expect(ID3TagSizeParser().parse(data: mp3) == 34213) } - func testParseTagSizeV3() { + @Test func parseTagSizeV3() { let mp3V23 = NSData(contentsOfFile: PathLoader().pathFor(name: "example-v23", fileType: "mp3"))! - XCTAssertEqual(id3TagSizeParser.parse(data: mp3V23), 245864) + #expect(ID3TagSizeParser().parse(data: mp3V23) == 245864) } static let allTests = [ - ("testParseTagSizeV2", testParseTagSizeV2), - ("testParseFrameContentSizeV3", testParseTagSizeV3) + ("parseTagSizeV2", parseTagSizeV2), + ("parseFrameContentSizeV3", parseTagSizeV3) ] } diff --git a/Tests/Parse/ID3TagVersionParserTest.swift b/Tests/Parse/ID3TagVersionParserTest.swift index d112c314..bbe216c6 100644 --- a/Tests/Parse/ID3TagVersionParserTest.swift +++ b/Tests/Parse/ID3TagVersionParserTest.swift @@ -5,36 +5,36 @@ // 2018 Fabrizio Duroni. // -import XCTest -@testable import ID3TagEditor +import Foundation +import Testing -class ID3TagVersionParserTest: XCTestCase { - private let id3VersionParser = ID3TagVersionParser() +@testable import ID3TagEditor - func testExtractVersion2() throws { +struct ID3TagVersionParserTest { + @Test func testExtractVersion2() throws { let mp3WithV2Tag = try Data( contentsOf: URL(fileURLWithPath: PathLoader().pathFor(name: "example", fileType: "mp3")) ) - XCTAssertEqual(.version2, id3VersionParser.parse(mp3: mp3WithV2Tag)) + #expect(.version2 == ID3TagVersionParser().parse(mp3: mp3WithV2Tag)) } - func testExtractVersion3() throws { + @Test func testExtractVersion3() throws { let mp3WithV2Tag = try Data( contentsOf: URL(fileURLWithPath: PathLoader().pathFor(name: "example-v23", fileType: "mp3")) ) - XCTAssertEqual(.version3, id3VersionParser.parse(mp3: mp3WithV2Tag)) + #expect(.version3 == ID3TagVersionParser().parse(mp3: mp3WithV2Tag)) } - func testShortData() throws { + @Test func testShortData() throws { let shortData = Data(capacity: 2) - XCTAssertEqual(.version3, id3VersionParser.parse(mp3: shortData)) + #expect(.version3 == ID3TagVersionParser().parse(mp3: shortData)) } - func testDefaultVersion() throws { + @Test func testDefaultVersion() throws { let mp3WithV2Tag = try Data( contentsOf: URL(fileURLWithPath: PathLoader().pathFor(name: "example-to-be-modified", fileType: "mp3")) ) - XCTAssertEqual(.version3, id3VersionParser.parse(mp3: mp3WithV2Tag)) + #expect(.version3 == ID3TagVersionParser().parse(mp3: mp3WithV2Tag)) } static let allTests = [ diff --git a/Tests/Parse/ID3TrackPositionStringAdapterTest.swift b/Tests/Parse/ID3TrackPositionStringAdapterTest.swift index 2373f7cf..878b4798 100644 --- a/Tests/Parse/ID3TrackPositionStringAdapterTest.swift +++ b/Tests/Parse/ID3TrackPositionStringAdapterTest.swift @@ -5,31 +5,29 @@ // 2018 Fabrizio Duroni. // -import XCTest +import Testing @testable import ID3TagEditor -class ID3TrackPositionStringAdapterTest: XCTestCase { - let trackPositionStringAdapter = ID3PartOfTotalStringAdapter() +struct ID3TrackPositionStringAdapterTest { + @Test func testAdaptTrackPositionWithTotalTrack() { + let trackPosition = ID3PartOfTotalStringAdapter().adapt(partOfTotal: "2/9") - func testAdaptTrackPositionWithTotalTrack() { - let trackPosition = trackPositionStringAdapter.adapt(partOfTotal: "2/9") - - XCTAssertEqual(trackPosition.part, 2) - XCTAssertEqual(trackPosition.total, 9) + #expect(trackPosition.part == 2) + #expect(trackPosition.total == 9) } - func testAdaptTrackPositionWithoutTotalTracks() { - let trackPosition = trackPositionStringAdapter.adapt(partOfTotal: "2") + @Test func testAdaptTrackPositionWithoutTotalTracks() { + let trackPosition = ID3PartOfTotalStringAdapter().adapt(partOfTotal: "2") - XCTAssertEqual(trackPosition.part, 2) - XCTAssertNil(trackPosition.total) + #expect(trackPosition.part == 2) + #expect(trackPosition.total == nil) } - func testAdaptNotANumberTrackPosition() { - let trackPosition = trackPositionStringAdapter.adapt(partOfTotal: "::invalid::") + @Test func testAdaptNotANumberTrackPosition() { + let trackPosition = ID3PartOfTotalStringAdapter().adapt(partOfTotal: "::invalid::") - XCTAssertEqual(trackPosition.part, 0) - XCTAssertNil(trackPosition.total) + #expect(trackPosition.part == 0) + #expect(trackPosition.total == nil) } static let allTests = [ diff --git a/Tests/Tag/ID3TagPresenceTest.swift b/Tests/Tag/ID3TagPresenceTest.swift index bc9694f1..2c134283 100644 --- a/Tests/Tag/ID3TagPresenceTest.swift +++ b/Tests/Tag/ID3TagPresenceTest.swift @@ -5,41 +5,43 @@ // 2018 Fabrizio Duroni. // -import XCTest +import Foundation +import Testing + @testable import ID3TagEditor -class ID3TagPresenceTest: XCTestCase { - func testHeaderVersion2IsPresent() { +struct ID3TagPresenceTest { + @Test func testHeaderVersion2IsPresent() { let id3TagConfiguration = ID3TagConfiguration() let mp3Sample = Data(id3TagConfiguration.headerFor(version: .version2) + [0x1, 0x1]) let presence = ID3TagPresence(id3TagConfiguration: id3TagConfiguration) - XCTAssertTrue(presence.isTagPresentIn(mp3: mp3Sample, version: .version2)) + #expect(presence.isTagPresentIn(mp3: mp3Sample, version: .version2)) } - func testHeaderVersion3IsPresent() { + @Test func testHeaderVersion3IsPresent() { let id3TagConfiguration = ID3TagConfiguration() let mp3Sample = Data(id3TagConfiguration.headerFor(version: .version3) + [0x1, 0x1]) let presence = ID3TagPresence(id3TagConfiguration: id3TagConfiguration) - XCTAssertTrue(presence.isTagPresentIn(mp3: mp3Sample, version: .version3)) + #expect(presence.isTagPresentIn(mp3: mp3Sample, version: .version3)) } - func testTagNotPresentSizeTooSmall() { + @Test func testTagNotPresentSizeTooSmall() { let id3TagConfiguration = ID3TagConfiguration() let mp3Sample = Data([0x1, 0x1]) let presence = ID3TagPresence(id3TagConfiguration: id3TagConfiguration) - XCTAssertFalse(presence.isTagPresentIn(mp3: mp3Sample, version: .version2)) - XCTAssertFalse(presence.isTagPresentIn(mp3: mp3Sample, version: .version3)) + #expect(!presence.isTagPresentIn(mp3: mp3Sample, version: .version2)) + #expect(!presence.isTagPresentIn(mp3: mp3Sample, version: .version3)) } - func testTagNotPresent() { + @Test func testTagNotPresent() { let id3TagConfiguration = ID3TagConfiguration() let mp3Sample = Data([0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1]) let presence = ID3TagPresence(id3TagConfiguration: id3TagConfiguration) - XCTAssertFalse(presence.isTagPresentIn(mp3: mp3Sample, version: .version2)) - XCTAssertFalse(presence.isTagPresentIn(mp3: mp3Sample, version: .version3)) + #expect(!presence.isTagPresentIn(mp3: mp3Sample, version: .version2)) + #expect(!presence.isTagPresentIn(mp3: mp3Sample, version: .version3)) } static let allTests = [ diff --git a/Tests/Tag/ID3TagTest.swift b/Tests/Tag/ID3TagTest.swift index c13ee478..352d369d 100644 --- a/Tests/Tag/ID3TagTest.swift +++ b/Tests/Tag/ID3TagTest.swift @@ -10,11 +10,13 @@ // swiftlint:disable function_body_length // swiftlint:disable type_body_length -import XCTest +import Foundation +import Testing + @testable import ID3TagEditor -class ID3TagTest: XCTestCase { - func testDebugDescriptionv3() throws { +struct ID3TagTest { + @Test func testDebugDescriptionv3() throws { let artFront = try Data( contentsOf: URL(fileURLWithPath: PathLoader().pathFor(name: "example-cover", fileType: "jpg")) ) @@ -63,8 +65,8 @@ class ID3TagTest: XCTestCase { ] ) - XCTAssertEqual( - id3Tag.debugDescription, + #expect( + id3Tag.debugDescription == """ ID3Tag: - size: 0 @@ -125,7 +127,7 @@ class ID3TagTest: XCTestCase { """) } - func testDebugDescriptionv4() throws { + @Test func testDebugDescriptionv4() throws { let artFront: Data = try Data(contentsOf: URL(fileURLWithPath: PathLoader().pathFor(name: "example-cover", fileType: "jpg"))) let artBack: Data = try Data(contentsOf: URL(fileURLWithPath: PathLoader().pathFor(name: "cover2", fileType: "jpg"))) @@ -169,8 +171,8 @@ class ID3TagTest: XCTestCase { ] ) - XCTAssertEqual( - id3Tag.debugDescription, + #expect( + id3Tag.debugDescription == """ ID3Tag: - size: 0 diff --git a/Tests/XCTestManifests.swift b/Tests/XCTestManifests.swift deleted file mode 100644 index fd2cff0c..00000000 --- a/Tests/XCTestManifests.swift +++ /dev/null @@ -1,46 +0,0 @@ -import XCTest - -#if os(Linux) -public func __allTests() -> [XCTestCaseEntry] { - return [ - testCase(ID3FrameWithStringContentCreatorTest.allTests), - testCase(ID3DiscPositionFrameCreatorTest.allTests), - testCase(ID3AttachedPictureFrameContentParsingOperationTest.allTests), - testCase(ID3AttachedPicturesFramesCreatorTest.allTests), - testCase(ID3FrameConfigurationTest.allTests), - testCase(ID3FrameContentSizeCalculatorTest.allTests), - testCase(ID3FrameFlagsCreatorTest.allTests), - testCase(ID3FrameFromStringContentCreatorTest.allTests), - testCase(ID3GenreFrameCreatorTest.allTests), - testCase(ID3GenreStringAdapterTest.allTests), - testCase(ID3ISO88591StringToByteAdapterTest.allTests), - testCase(ID3PictureTypeAdapterTest.allTests), - testCase(ID3FrameWithIntegerContentCreatorTest.allTests), - testCase(ID3RecordingDateTimeFrameCreatorTest.allTests), - testCase(ID3RecordingDayMonthFrameCreatorTest.allTests), - testCase(ID3RecordingTimeFrameContentParsingOperationTest.allTests), - testCase(ID3TagCreatorTest.allTests), - testCase(ID3TagPresenceTest.allTests), - testCase(ID3TimestampCreatorTest.allTests), - testCase(ID3TrackPositionCreatorTest.allTests), - testCase(ID3TrackPositionStringAdapterTest.allTests), - testCase(ID3DiscPositionStringAdapterTest.allTests), - testCase(ID3UTF16StringToByteAdapterTest.allTests), - testCase(PaddingAdderUsingNullCharTest.allTests), - testCase(PaddingRemoverUsingTrimmingTest.allTests), - testCase(UInt32ToByteArrayAdapterUsingUnsafePointerTest.allTests), - testCase(ID3FrameContentSizeParserTest.allTests), - testCase(ID3StringContentParsingOperationTest.allTests), - testCase(ID3FrameSizeParserTest.allTests), - testCase(ID3TagSizeParserTest.allTests), - testCase(Mp3FileReaderTest.allTests), - testCase(ID3LocalizedFrameCreatorTest.allTests), - testCase(ID3FramesWithLocalizedContentCreatorTest.allTests), - testCase(ID3FrameHeaderCreatorTest.allTests), - testCase(ID3LocalizedFrameParsingOperationTest.allTests), - testCase(ID3TagEditorAcceptanceTest.allTests), - testCase(ID3TagTest.allTests), - testCase(ID3TagVersionParserTest.allTests) - ] -} -#endif