@@ -18,9 +18,29 @@ import XCTest
18
18
19
19
20
20
final class ZipTests : XCTestCase {
21
+
22
+ func test_unzip( ) async throws {
23
+ // Test basic unzip behaviour we expect from the library we use
24
+ try await withTempDir { tempDir in
25
+ let tempURL = URL ( fileURLWithPath: tempDir)
26
+ let zipFile = fixtureUrl ( for: " out.zip " )
27
+ let outDir = tempURL. appendingPathComponent ( " out " )
28
+ try Zipper . unzip ( from: zipFile, to: outDir)
29
+ XCTAssert ( FileManager . default. fileExists ( atPath: outDir. path) )
30
+
31
+ // out/a.txt
32
+ // out/subdir/b.txt
33
+ let fileA = outDir. appendingPathComponent ( " a.txt " )
34
+ let fileB = outDir. appendingPathComponent ( " subdir " ) . appendingPathComponent ( " b.txt " )
35
+ XCTAssert ( FileManager . default. fileExists ( atPath: fileA. path) )
36
+ XCTAssert ( FileManager . default. fileExists ( atPath: fileB. path) )
37
+ XCTAssertEqual ( try String ( contentsOf: fileA) , " a " )
38
+ XCTAssertEqual ( try String ( contentsOf: fileB) , " b " )
39
+ }
40
+ }
21
41
22
- func test_zip ( ) async throws {
23
- // Test basic zip behaviour we expect from the library we use
42
+ func test_zip_roundtrip ( ) async throws {
43
+ // Test basic zip roundtrip
24
44
try await withTempDir { tempDir in
25
45
// temp
26
46
let tempURL = URL ( fileURLWithPath: tempDir)
@@ -40,26 +60,20 @@ final class ZipTests: XCTestCase {
40
60
let zipFile = tempURL. appendingPathComponent ( " out.zip " )
41
61
try Zipper . zip ( paths: [ fileA, subdir] , to: zipFile)
42
62
XCTAssert ( FileManager . default. fileExists ( atPath: zipFile. path) )
43
- }
44
- }
45
63
46
- func test_unzip( ) async throws {
47
- // Test basic unzip behaviour we expect from the library we use
48
- try await withTempDir { tempDir in
49
- let tempURL = URL ( fileURLWithPath: tempDir)
50
- let zipFile = fixtureUrl ( for: " out.zip " )
51
- let outDir = tempURL. appendingPathComponent ( " out " )
52
- try Zipper . unzip ( from: zipFile, to: outDir)
53
- XCTAssert ( FileManager . default. fileExists ( atPath: outDir. path) )
54
-
55
- // out/a.txt
56
- // out/subdir/b.txt
57
- let fileA = outDir. appendingPathComponent ( " a.txt " )
58
- let fileB = outDir. appendingPathComponent ( " subdir " ) . appendingPathComponent ( " b.txt " )
59
- XCTAssert ( FileManager . default. fileExists ( atPath: fileA. path) )
60
- XCTAssert ( FileManager . default. fileExists ( atPath: fileB. path) )
61
- XCTAssertEqual ( try String ( contentsOf: fileA) , " a " )
62
- XCTAssertEqual ( try String ( contentsOf: fileB) , " b " )
64
+ do { // unzip what we zipped and check results
65
+ let roundtrip = tempURL. appendingPathComponent ( " roundtrip " )
66
+ try Zipper . unzip ( from: zipFile, to: roundtrip)
67
+ XCTAssert ( FileManager . default. fileExists ( atPath: roundtrip. path) )
68
+ // roundtrip/a.txt
69
+ // roundtrip/subdir/b.txt
70
+ let fileA = roundtrip. appendingPathComponent ( " a.txt " )
71
+ let fileB = roundtrip. appendingPathComponent ( " subdir " ) . appendingPathComponent ( " b.txt " )
72
+ XCTAssert ( FileManager . default. fileExists ( atPath: fileA. path) )
73
+ XCTAssert ( FileManager . default. fileExists ( atPath: fileB. path) )
74
+ XCTAssertEqual ( try String ( contentsOf: fileA) , " a " )
75
+ XCTAssertEqual ( try String ( contentsOf: fileB) , " b " )
76
+ }
63
77
}
64
78
}
65
79
0 commit comments