Skip to content

Commit 337bb62

Browse files
authored
Merge pull request #1 from Wei18/main
Update Package.swift to support Nuke from 11.0.0
2 parents 937de78 + 22378ec commit 337bb62

9 files changed

+156
-126
lines changed

Nuke-AVIF-Plugin.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Pod::Spec.new do |s|
3838
s.module_name = 'NukeAVIFPlugin'
3939

4040
s.dependency 'libavif', '>= 0.9.1'
41-
s.dependency 'Nuke', '~> 9.0'
41+
s.dependency 'Nuke', '~> 11.0'
4242
s.libraries = 'c++'
4343

4444
end

Nuke_AVIF_PluginTests/AVIFDecodeTests.swift

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,21 @@
77
//
88

99
import XCTest
10-
import Nuke
1110
@testable import NukeAVIFPlugin
11+
#if SWIFT_PACKAGE
12+
import NukeAVIFPluginC
13+
#endif
1214

15+
#if os(iOS)
1316
class AVIFDecodeTests: XCTestCase {
1417

1518
private lazy var avifImagePath: URL = {
16-
let avifImagePath = Bundle(for: type(of: self)).url(forResource: "sample", withExtension: "avif")!
19+
let avifImagePath = BundleToken.bundle.url(forResource: "sample", withExtension: "avif")!
1720
return avifImagePath
1821
}()
1922

2023
private lazy var gifImagePath: URL = {
21-
let gifImagePath = Bundle(for: type(of: self)).url(forResource: "sample", withExtension: "gif")!
24+
let gifImagePath = BundleToken.bundle.url(forResource: "sample", withExtension: "gif")!
2225
return gifImagePath
2326
}()
2427

@@ -32,56 +35,53 @@ class AVIFDecodeTests: XCTestCase {
3235
super.tearDown()
3336
}
3437

35-
func testsDecodeAVIFImage() {
36-
let avifData = try! Data(contentsOf: self.avifImagePath)
37-
let image: UIImage? = UIImage(data: avifData)
38-
XCTAssertNil(image)
38+
func testsDecodeAVIFImage() throws {
39+
let avifData = try Data(contentsOf: self.avifImagePath)
40+
if #unavailable(iOS 16.0) {
41+
let image: UIImage? = UIImage(data: avifData)
42+
XCTAssertNil(image)
43+
}
3944

40-
let decoder = NukeAVIFPlugin.AVIFDataDecoder();
45+
let decoder = NukeAVIFPluginC.AVIFDataDecoder();
4146
let avifImage: UIImage? = decoder.decode(avifData)
4247
XCTAssertNotNil(avifImage)
4348
}
4449

45-
func testsDecodeNotAVIFImage() {
46-
let gifData = try! Data(contentsOf: self.gifImagePath)
50+
func testsDecodeNotAVIFImage() throws {
51+
let gifData = try Data(contentsOf: self.gifImagePath)
4752
let image: UIImage? = UIImage(data: gifData)
4853
XCTAssertNotNil(image)
4954

50-
let decoder = NukeAVIFPlugin.AVIFDataDecoder();
55+
let decoder = NukeAVIFPluginC.AVIFDataDecoder();
5156
let avifImage: UIImage? = decoder.decode(gifData)
5257
XCTAssertNil(avifImage)
5358
}
5459

55-
func testsProgressiveDecodeAVIFImage() {
56-
let avifData = try! Data(contentsOf: self.avifImagePath)
57-
let decoder = NukeAVIFPlugin.AVIFDataDecoder();
60+
func testsProgressiveDecodeAVIFImage() throws {
61+
let avifData = try Data(contentsOf: self.avifImagePath)
62+
let decoder = NukeAVIFPluginC.AVIFDataDecoder();
5863
// no image
5964
XCTAssertNil(decoder.incrementallyDecode(avifData[0...200]))
6065

6166
// created image
6267
let scan1 = decoder.incrementallyDecode(avifData[0...8000])
6368
XCTAssertNotNil(scan1)
64-
XCTAssertEqual(scan1!.size.width, 200)
65-
XCTAssertEqual(scan1!.size.height, 180)
69+
XCTAssertEqual(scan1?.size.width, 200)
70+
XCTAssertEqual(scan1?.size.height, 180)
6671

6772
let scan2 = decoder.incrementallyDecode(avifData)
6873
XCTAssertNotNil(scan2)
69-
XCTAssertEqual(scan2!.size.width, 200)
70-
XCTAssertEqual(scan2!.size.height, 180)
74+
XCTAssertEqual(scan2?.size.width, 200)
75+
XCTAssertEqual(scan2?.size.height, 180)
7176
}
7277

73-
func testPerformanceDecodeAVIF() {
78+
func testPerformanceDecodeAVIF() throws {
7479
// This is an example of a performance test case.
7580
self.measure {
7681
// Put the code you want to measure the time of here.
77-
let avifData = try! Data(contentsOf: self.avifImagePath)
78-
let image: UIImage? = UIImage(data: avifData)
79-
XCTAssertNil(image)
80-
81-
let decoder = NukeAVIFPlugin.AVIFDataDecoder();
82-
let avifImage: UIImage? = decoder.decode(avifData)
83-
XCTAssertNotNil(avifImage)
82+
try? testsDecodeAVIFImage()
8483
}
8584
}
8685

8786
}
87+
#endif

Nuke_AVIF_PluginTests/AVIFDecodeTests_MacOS.swift

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,21 @@
77
//
88

99
import XCTest
10-
import Nuke
1110
@testable import NukeAVIFPlugin
11+
#if SWIFT_PACKAGE
12+
import NukeAVIFPluginC
13+
#endif
1214

15+
#if os(macOS)
1316
class AVIFDecodeTests: XCTestCase {
1417

1518
private lazy var avifImagePath: URL = {
16-
let avifImagePath = Bundle(for: type(of: self)).url(forResource: "sample", withExtension: "avif")!
19+
let avifImagePath = BundleToken.bundle.url(forResource: "sample", withExtension: "avif")!
1720
return avifImagePath
1821
}()
1922

2023
private lazy var gifImagePath: URL = {
21-
let gifImagePath = Bundle(for: type(of: self)).url(forResource: "sample", withExtension: "gif")!
24+
let gifImagePath = BundleToken.bundle.url(forResource: "sample", withExtension: "gif")!
2225
return gifImagePath
2326
}()
2427

@@ -32,56 +35,53 @@ class AVIFDecodeTests: XCTestCase {
3235
super.tearDown()
3336
}
3437

35-
func testsDecodeAVIFImage() {
36-
let avifData = try! Data(contentsOf: self.avifImagePath)
37-
let image: NSImage? = NSImage(data: avifData)
38-
XCTAssertNil(image)
38+
func testsDecodeAVIFImage() throws {
39+
let avifData = try Data(contentsOf: self.avifImagePath)
40+
if #unavailable(macOS 13.0) {
41+
let image: NSImage? = NSImage(data: avifData)
42+
XCTAssertNil(image)
43+
}
3944

40-
let decoder = NukeAVIFPlugin.AVIFDataDecoder();
45+
let decoder = NukeAVIFPluginC.AVIFDataDecoder();
4146
let avifImage: NSImage? = decoder.decode(avifData)
4247
XCTAssertNotNil(avifImage)
4348
}
4449

45-
func testsDecodeNotAVIFImage() {
46-
let gifData = try! Data(contentsOf: self.gifImagePath)
50+
func testsDecodeNotAVIFImage() throws {
51+
let gifData = try Data(contentsOf: self.gifImagePath)
4752
let image: NSImage? = NSImage(data: gifData)
4853
XCTAssertNotNil(image)
4954

50-
let decoder = NukeAVIFPlugin.AVIFDataDecoder();
55+
let decoder = NukeAVIFPluginC.AVIFDataDecoder();
5156
let avifImage: NSImage? = decoder.decode(gifData)
5257
XCTAssertNil(avifImage)
5358
}
5459

55-
func testsProgressiveDecodeAVIFImage() {
56-
let avifData = try! Data(contentsOf: self.avifImagePath)
57-
let decoder = NukeAVIFPlugin.AVIFDataDecoder();
60+
func testsProgressiveDecodeAVIFImage() throws {
61+
let avifData = try Data(contentsOf: self.avifImagePath)
62+
let decoder = NukeAVIFPluginC.AVIFDataDecoder();
5863
// no image
59-
XCTAssertNil(decoder.incrementallyDecode(avifData[0...500]))
64+
XCTAssertNil(decoder.incrementallyDecode(avifData[0...200]))
6065

6166
// created image
62-
let scan1 = decoder.incrementallyDecode(avifData[0...3702])
67+
let scan1 = decoder.incrementallyDecode(avifData[0...8000])
6368
XCTAssertNotNil(scan1)
64-
XCTAssertEqual(scan1!.size.width, 320)
65-
XCTAssertEqual(scan1!.size.height, 235)
69+
XCTAssertEqual(scan1?.size.width, 200)
70+
XCTAssertEqual(scan1?.size.height, 180)
6671

6772
let scan2 = decoder.incrementallyDecode(avifData)
6873
XCTAssertNotNil(scan2)
69-
XCTAssertEqual(scan2!.size.width, 320)
70-
XCTAssertEqual(scan2!.size.height, 235)
74+
XCTAssertEqual(scan2?.size.width, 200)
75+
XCTAssertEqual(scan2?.size.height, 180)
7176
}
7277

7378
func testPerformanceDecodeAVIF() {
7479
// This is an example of a performance test case.
7580
self.measure {
7681
// Put the code you want to measure the time of here.
77-
let avifData = try! Data(contentsOf: self.avifImagePath)
78-
let image: NSImage? = NSImage(data: avifData)
79-
XCTAssertNil(image)
80-
81-
let decoder = NukeAVIFPlugin.AVIFDataDecoder();
82-
let avifImage: NSImage? = decoder.decode(avifData)
83-
XCTAssertNotNil(avifImage)
82+
try? testsDecodeAVIFImage()
8483
}
8584
}
8685

8786
}
87+
#endif

Nuke_AVIF_PluginTests/AVIFImageDecoderTests.swift

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import Nuke
1111
@testable import NukeAVIFPlugin
1212

1313
class AVIFImageDecoderTests: XCTestCase {
14-
14+
1515
private lazy var avifImagePath: URL = {
16-
let avifImagePath = Bundle(for: type(of: self)).url(forResource: "sample", withExtension: "avif")!
16+
let avifImagePath = BundleToken.bundle.url(forResource: "sample", withExtension: "avif")!
1717
return avifImagePath
1818
}()
1919

@@ -29,21 +29,20 @@ class AVIFImageDecoderTests: XCTestCase {
2929
super.tearDown()
3030
}
3131

32-
func testsProgressiveDecodeAVIFImageDecoder() {
33-
let avifData = try! Data(contentsOf: self.avifImagePath)
32+
func testsProgressiveDecodeAVIFImageDecoder() throws {
33+
let avifData = try Data(contentsOf: self.avifImagePath)
3434
let decoder = NukeAVIFPlugin.AVIFImageDecoder()
3535

3636
// no image
37-
XCTAssertNil(decoder.decode(avifData[0...500]))
37+
XCTAssertThrowsError(try decoder.decode(avifData[0...500]))
3838

3939
// created image
40-
let scan1 = decoder.decode(avifData[0...3702])
41-
XCTAssertNil(scan1)
40+
XCTAssertThrowsError(try decoder.decode(avifData[0...3702]))
4241

43-
let scan2 = decoder.decode(avifData)
42+
let scan2 = try decoder.decode(avifData)
4443
XCTAssertNotNil(scan2)
45-
XCTAssertEqual(scan2!.image.size.width, 320)
46-
XCTAssertEqual(scan2!.image.size.height, 235)
44+
XCTAssertEqual(scan2.image.size.width, 200)
45+
XCTAssertEqual(scan2.image.size.height, 180)
4746
}
4847

4948
func testsImageDecoderRegistryRegistered() {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// BundleToken.swift
3+
//
4+
//
5+
// Created by zwc on 2023/2/2.
6+
//
7+
8+
import Foundation
9+
10+
final class BundleToken {
11+
static let bundle: Bundle = {
12+
#if SWIFT_PACKAGE
13+
return Bundle.module
14+
#else
15+
return Bundle(for: BundleToken.self)
16+
#endif
17+
}()
18+
}

Nuke_AVIF_PluginTests/DataExtensionsTests.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ import XCTest
1212
class DataExtensionsTests: XCTestCase {
1313

1414
private lazy var avifImagePath: URL = {
15-
let avifImagePath = Bundle(for: type(of: self)).url(forResource: "sample", withExtension: "avif")!
15+
let avifImagePath = BundleToken.bundle.url(forResource: "sample", withExtension: "avif")!
1616
return avifImagePath
1717
}()
1818

1919
private lazy var gifImagePath: URL = {
20-
let gifImagePath = Bundle(for: type(of: self)).url(forResource: "sample", withExtension: "gif")!
20+
let gifImagePath = BundleToken.bundle.url(forResource: "sample", withExtension: "gif")!
2121
return gifImagePath
2222
}()
2323

2424
private lazy var webpImagePath: URL = {
25-
let webpImagePath = Bundle(for: type(of: self)).url(forResource: "sample", withExtension: "webp")!
25+
let webpImagePath = BundleToken.bundle.url(forResource: "sample", withExtension: "webp")!
2626
return webpImagePath
2727
}()
2828

@@ -36,14 +36,14 @@ class DataExtensionsTests: XCTestCase {
3636
super.tearDown()
3737
}
3838

39-
func testsDataIsAVIFFormat() {
40-
let avifData = try! Data(contentsOf: self.avifImagePath)
39+
func testsDataIsAVIFFormat() throws {
40+
let avifData = try Data(contentsOf: self.avifImagePath)
4141
XCTAssertTrue(avifData.isAVIFFormat)
4242

43-
let gifData = try! Data(contentsOf: self.gifImagePath)
43+
let gifData = try Data(contentsOf: self.gifImagePath)
4444
XCTAssertFalse(gifData.isAVIFFormat)
4545

46-
let webpData = try! Data(contentsOf: self.webpImagePath)
46+
let webpData = try Data(contentsOf: self.webpImagePath)
4747
XCTAssertFalse(webpData.isAVIFFormat)
4848
}
4949

Package.resolved

Lines changed: 38 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)