diff --git a/Tests/TestSWCompression/BZip2CompressionTests.swift b/Tests/TestSWCompression/BZip2CompressionTests.swift index 9dbee075..2a2c7411 100644 --- a/Tests/TestSWCompression/BZip2CompressionTests.swift +++ b/Tests/TestSWCompression/BZip2CompressionTests.swift @@ -9,7 +9,7 @@ import SWCompression struct BZip2CompressionTests { - func answerTest(_ testName: String) throws { + private func answerTest(_ testName: String) throws { let answerData = try Constants.data(forAnswer: testName) let compressedData = BZip2.compress(data: answerData) let redecompressedData = try BZip2.decompress(data: compressedData) @@ -20,7 +20,7 @@ struct BZip2CompressionTests { } } - func stringTest(_ string: String) throws { + private func stringTest(_ string: String) throws { let answerData = Data(string.utf8) let compressedData = BZip2.compress(data: answerData) diff --git a/Tests/TestSWCompression/BZip2Tests.swift b/Tests/TestSWCompression/BZip2Tests.swift index efe1bd98..0d9b0f65 100644 --- a/Tests/TestSWCompression/BZip2Tests.swift +++ b/Tests/TestSWCompression/BZip2Tests.swift @@ -9,10 +9,10 @@ import SWCompression struct BZip2Tests { - private static let testType: String = "bz2" + private let testType: String = "bz2" - func perform(test testName: String) throws { - let testData = try Constants.data(forTest: testName, withType: BZip2Tests.testType) + private func perform(test testName: String) throws { + let testData = try Constants.data(forTest: testName, withType: testType) let decompressedData = try BZip2.decompress(data: testData) let answerData = try Constants.data(forAnswer: testName) @@ -20,44 +20,44 @@ struct BZip2Tests { } @Test func test1() throws { - try self.perform(test: "test1") + try perform(test: "test1") } @Test func test2() throws { - try self.perform(test: "test2") + try perform(test: "test2") } @Test func test3() throws { - try self.perform(test: "test3") + try perform(test: "test3") } @Test func test4() throws { - try self.perform(test: "test4") + try perform(test: "test4") } @Test func test5() throws { - try self.perform(test: "test5") + try perform(test: "test5") } @Test func test6() throws { - try self.perform(test: "test6") + try perform(test: "test6") } @Test func test7() throws { - try self.perform(test: "test7") + try perform(test: "test7") } @Test func test8() throws { - try self.perform(test: "test8") + try perform(test: "test8") } @Test func test9() throws { - try self.perform(test: "test9") + try perform(test: "test9") } @Test(.bug("https://github.com/tsolomko/SWCompression/issues/21", id: 21)) func nonStandardRunLength() throws { - try self.perform(test: "test_nonstandard_runlength") + try perform(test: "test_nonstandard_runlength") } @Test func shortInput() { @@ -72,7 +72,7 @@ struct BZip2Tests { @Test func truncatedInput() throws { // This tests that encountering data truncated in the middle of a Huffman symbol correctly throws an error // (and doesn't crash). - let testData = try Constants.data(forTest: "test1", withType: BZip2Tests.testType)[0...40] + let testData = try Constants.data(forTest: "test1", withType: testType)[0...40] #expect(throws: (any Error).self) { try BZip2.decompress(data: testData) } } @@ -84,7 +84,7 @@ struct BZip2Tests { // Here we test that an error for checksum mismatch is thrown correctly and its associated value contains // expected data. We do this by programmatically adjusting the input: we change one of the bytes for the checkum, // which makes it incorrect. - var testData = try Constants.data(forTest: "test1", withType: BZip2Tests.testType) + var testData = try Constants.data(forTest: "test1", withType: testType) // The checksum is the last 4 bytes. testData[testData.endIndex - 2] &+= 1 #if compiler(>=6.1) @@ -112,7 +112,7 @@ struct BZip2Tests { // is no #expect in this test. for i in 1...9 { let testName = "test\(i)" - let testData = try Constants.data(forTest: testName, withType: BZip2Tests.testType) + let testData = try Constants.data(forTest: testName, withType: testType) // It would be better to increase amount of different truncations tested, but we hit runtime limits in CI. for _ in 0..<5 { let truncationIndex = Int.random(in: (testData.startIndex + 1)..=6.1) @@ -218,7 +218,7 @@ struct GzipTests { // Here we test that an error for checksum mismatch is thrown correctly and its associated value contains // expected data. We do this by programmatically adjusting the input: we change one of the bytes for the checkum, // which makes it incorrect. - var testData = try Constants.data(forTest: "test_multi", withType: GzipTests.testType) + var testData = try Constants.data(forTest: "test_multi", withType: testType) // Here we modify the stored value of crc32. testData[2289] &+= 1 #if compiler(>=6.1) @@ -249,7 +249,7 @@ struct GzipTests { // - that the archive consisting only of the minimal header is successfully processed, // - that the mtime field with the value 0 correctly results in a `GzipHeader.modificationTime == nil`, // - that the `GzipArchive.multiUnarchive(archive:)` works on a single member archive. - let testData = try Constants.data(forTest: "minimal", withType: GzipTests.testType) + let testData = try Constants.data(forTest: "minimal", withType: testType) let members = try GzipArchive.multiUnarchive(archive: testData) try #require(members.count == 1) if let member = members.first { @@ -267,7 +267,7 @@ struct GzipTests { // In this test we check the handling of truncation inside the optional elements (name, comment, "extra field", // crc) of a GZip header, as well as in the "checksum" information of the archive (last 8 bytes). The sample // file used is "test4_extra_field" since it contains a header which utilizes all format features. - let testData = try Constants.data(forTest: "test4_extra_field", withType: GzipTests.testType) + let testData = try Constants.data(forTest: "test4_extra_field", withType: testType) // We test all possible truncation points since there are very few of them. // The header takes first 79 bytes. @@ -288,7 +288,7 @@ struct GzipTests { @Test func randomInputTruncations() throws { for i in 1...9 { let testName = "test\(i)" - let testData = try Constants.data(forTest: testName, withType: GzipTests.testType) + let testData = try Constants.data(forTest: testName, withType: testType) // It would be better to increase amount of different truncations tested, but we hit runtime limits in CI. for _ in 0..<5 { let truncationIndex = Int.random(in: (testData.startIndex + 1)..=6.1) @@ -206,7 +206,7 @@ struct LZ4Tests { @Test func randomInputTruncations() throws { for i in 1...9 { let testName = "test\(i)" - let testData = try Constants.data(forTest: testName, withType: LZ4Tests.testType) + let testData = try Constants.data(forTest: testName, withType: testType) for _ in 0..<100 { let truncationIndex = Int.random(in: (testData.startIndex + 1)..=6.1) @@ -151,7 +151,7 @@ struct XZTests { // Here we test that an error for checksum mismatch is thrown correctly and its associated value contains // expected data. We do this by programmatically adjusting the input: we change one of the bytes for the checkum, // which makes it incorrect. - var testData = try Constants.data(forTest: "test_multi", withType: XZTests.testType) + var testData = try Constants.data(forTest: "test_multi", withType: testType) // Here we modify the stored value of crc64. testData[2346] &+= 1 #if compiler(>=6.1) diff --git a/Tests/TestSWCompression/ZipTests.swift b/Tests/TestSWCompression/ZipTests.swift index cfd09bc0..ad2b1f02 100644 --- a/Tests/TestSWCompression/ZipTests.swift +++ b/Tests/TestSWCompression/ZipTests.swift @@ -9,7 +9,7 @@ import SWCompression struct ZipTests { - private static let testType: String = "zip" + private let testType: String = "zip" @Test func shortInput() { #expect(throws: (any Error).self) { try ZipContainer.open(container: Data([0, 1, 2, 3, 4, 5, 6, 7])) } @@ -26,12 +26,12 @@ struct ZipTests { } @Test func bigContainer() throws { - let testData = try Constants.data(forTest: "SWCompressionSourceCode", withType: ZipTests.testType) + let testData = try Constants.data(forTest: "SWCompressionSourceCode", withType: testType) #expect(throws: Never.self) { try ZipContainer.open(container: testData) } } @Test func customExtraField() throws { - let testData = try Constants.data(forTest: "test_custom_extra_field", withType: ZipTests.testType) + let testData = try Constants.data(forTest: "test_custom_extra_field", withType: testType) // First, we check that without enabling support for our custom extra field, ZipContainer doesn't recognize it. var entries = try ZipContainer.open(container: testData) @@ -66,7 +66,7 @@ struct ZipTests { } @Test func zip64() throws { - let testData = try Constants.data(forTest: "test_zip64", withType: ZipTests.testType) + let testData = try Constants.data(forTest: "test_zip64", withType: testType) let entries = try ZipContainer.open(container: testData) try #require(entries.count == 6) @@ -84,7 +84,7 @@ struct ZipTests { } @Test func dataDescriptor() throws { - let testData = try Constants.data(forTest: "test_data_descriptor", withType: ZipTests.testType) + let testData = try Constants.data(forTest: "test_data_descriptor", withType: testType) let entries = try ZipContainer.open(container: testData) try #require(entries.count == 6) @@ -109,7 +109,7 @@ struct ZipTests { } @Test func unicode() throws { - let testData = try Constants.data(forTest: "test_unicode", withType: ZipTests.testType) + let testData = try Constants.data(forTest: "test_unicode", withType: testType) let entries = try ZipContainer.open(container: testData) try #require(entries.count == 1) @@ -131,7 +131,7 @@ struct ZipTests { } @Test func zipLZMA() throws { - let testData = try Constants.data(forTest: "test_zip_lzma", withType: ZipTests.testType) + let testData = try Constants.data(forTest: "test_zip_lzma", withType: testType) let entries = try ZipContainer.open(container: testData) try #require(entries.count == 1) @@ -155,7 +155,7 @@ struct ZipTests { } @Test func zipBZip2() throws { - let testData = try Constants.data(forTest: "test_zip_bzip2", withType: ZipTests.testType) + let testData = try Constants.data(forTest: "test_zip_bzip2", withType: testType) let entries = try ZipContainer.open(container: testData) try #require(entries.count == 1) @@ -179,7 +179,7 @@ struct ZipTests { } @Test func winContainer() throws { - let testData = try Constants.data(forTest: "test_win", withType: ZipTests.testType) + let testData = try Constants.data(forTest: "test_win", withType: testType) let entries = try ZipContainer.open(container: testData) try #require(entries.count == 2) @@ -222,7 +222,7 @@ struct ZipTests { } @Test func emptyFile() throws { - let testData = try Constants.data(forTest: "test_empty_file", withType: ZipTests.testType) + let testData = try Constants.data(forTest: "test_empty_file", withType: testType) let entries = try ZipContainer.open(container: testData) try #require(entries.count == 1) @@ -246,7 +246,7 @@ struct ZipTests { } @Test func emptyDirectory() throws { - let testData = try Constants.data(forTest: "test_empty_dir", withType: ZipTests.testType) + let testData = try Constants.data(forTest: "test_empty_dir", withType: testType) let entries = try ZipContainer.open(container: testData) try #require(entries.count == 1) @@ -270,7 +270,7 @@ struct ZipTests { } @Test func emptyContainer() throws { - let testData = try Constants.data(forTest: "test_empty_cont", withType: ZipTests.testType) + let testData = try Constants.data(forTest: "test_empty_cont", withType: testType) let entries = try ZipContainer.open(container: testData) #expect(entries.isEmpty) @@ -279,7 +279,7 @@ struct ZipTests { @Test func badCdExtTs() throws { // Tests ability to not crash when opening ZIP files with non well-formed Extended Timestamp extra field. // Such fields are sometimes present in Central Directory of ZIP files created by Finder in some versions of macOS. - let testData = try Constants.data(forTest: "bad_cd_ext_ts", withType: ZipTests.testType) + let testData = try Constants.data(forTest: "bad_cd_ext_ts", withType: testType) let entries = try ZipContainer.open(container: testData) try #require(entries.count == 2) let answerData = try Constants.data(forAnswer: "test4") @@ -292,7 +292,7 @@ struct ZipTests { // We introduced several CP437-specific characters from the 0x80-0xFF range into "test1.answer" to test this. // Note, that we didn't used normal characters from the 0x00-0x7F range that don't match the characters from // UTF-8 with the same codes, since they are interpreted as control characters by Foundation. - let testData = try Constants.data(forTest: "test_dos_latin_us", withType: ZipTests.testType) + let testData = try Constants.data(forTest: "test_dos_latin_us", withType: testType) let entries = try ZipContainer.open(container: testData) try #require(entries.count == 1) @@ -319,7 +319,7 @@ struct ZipTests { // Here we test that an error for checksum mismatch is thrown correctly and its associated value contains // expected data. We do this by programmatically adjusting the input: we change one of the bytes for the checkum, // which makes it incorrect. - var testData = try Constants.data(forTest: "test_unicode", withType: ZipTests.testType) + var testData = try Constants.data(forTest: "test_unicode", withType: testType) // Here we modify the stored value of crc32. testData[16] &+= 1 #if compiler(>=6.1) diff --git a/Tests/TestSWCompression/ZlibTests.swift b/Tests/TestSWCompression/ZlibTests.swift index 38ed49c1..eea46850 100644 --- a/Tests/TestSWCompression/ZlibTests.swift +++ b/Tests/TestSWCompression/ZlibTests.swift @@ -9,12 +9,12 @@ import SWCompression struct ZlibTests { - private static let testType: String = "zlib" + private let testType: String = "zlib" @Test func test() throws { let testName = "test" - let testData = try Constants.data(forTest: testName, withType: ZlibTests.testType) + let testData = try Constants.data(forTest: testName, withType: testType) let testZlibHeader = try ZlibHeader(archive: testData) #expect(testZlibHeader.compressionMethod == .deflate) @@ -23,7 +23,7 @@ struct ZlibTests { } @Test func full() throws { - let testData = try Constants.data(forTest: "random_file", withType: ZlibTests.testType) + let testData = try Constants.data(forTest: "random_file", withType: testType) let decompressedData = try ZlibArchive.unarchive(archive: testData) let answerData = try Constants.data(forAnswer: "test9") @@ -39,7 +39,7 @@ struct ZlibTests { } @Test func empty() throws { - let testData = try Constants.data(forTest: "test_empty", withType: ZlibTests.testType) + let testData = try Constants.data(forTest: "test_empty", withType: testType) #expect((try ZlibArchive.unarchive(archive: testData)) == Data()) } @@ -61,7 +61,7 @@ struct ZlibTests { // Here we test that an error for checksum mismatch is thrown correctly and its associated value contains // expected data. We do this by programmatically adjusting the input: we change one of the bytes for the checkum, // which makes it incorrect. - var testData = try Constants.data(forTest: "random_file", withType: ZlibTests.testType) + var testData = try Constants.data(forTest: "random_file", withType: testType) // Here we modify the stored value of adler32. testData[10249] &+= 1 #if compiler(>=6.1) @@ -85,7 +85,7 @@ struct ZlibTests { @Test func randomInputTruncations() throws { for testName in ["test", "random_file", "test_empty"] { - let testData = try Constants.data(forTest: testName, withType: ZlibTests.testType) + let testData = try Constants.data(forTest: testName, withType: testType) for _ in 0..<100 { let truncationIndex = Int.random(in: (testData.startIndex + 1)..