From 056d66f3f16d806cbb6ff85e503d9c09fc06669f Mon Sep 17 00:00:00 2001 From: kean Date: Sun, 17 Nov 2024 14:12:49 -0500 Subject: [PATCH] Update ImageEncoderTests --- Tests/NukeTests/ImageEncoderTests.swift | 84 ++++++++++++------------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/Tests/NukeTests/ImageEncoderTests.swift b/Tests/NukeTests/ImageEncoderTests.swift index 18f0516d3..549dc3043 100644 --- a/Tests/NukeTests/ImageEncoderTests.swift +++ b/Tests/NukeTests/ImageEncoderTests.swift @@ -2,95 +2,95 @@ // // Copyright (c) 2015-2024 Alexander Grebenyuk (github.com/kean). -import XCTest +import Testing @testable import Nuke -final class ImageEncoderTests: XCTestCase { - func testEncodeImage() throws { +@Suite struct ImageEncoderTests { + @Test func encodeImage() throws { // Given let image = Test.image let encoder = ImageEncoders.Default() - + // When - let data = try XCTUnwrap(encoder.encode(image)) - + let data = try #require(encoder.encode(image)) + // Then - XCTAssertEqual(AssetType(data), .jpeg) + #expect(AssetType(data) == .jpeg) } - - func testEncodeImagePNGOpaque() throws { + + @Test func encodeImagePNGOpaque() throws { // Given let image = Test.image(named: "fixture", extension: "png") let encoder = ImageEncoders.Default() - + // When - let data = try XCTUnwrap(encoder.encode(image)) - + let data = try #require(encoder.encode(image)) + // Then #if os(macOS) // It seems that on macOS, NSImage created from png has an alpha // component regardless of whether the input image has it. - XCTAssertEqual(AssetType(data), .png) + #expect(AssetType(data) == .png) #else - XCTAssertEqual(AssetType(data), .jpeg) + #expect(AssetType(data) == .jpeg) #endif } - - func testEncodeImagePNGTransparent() throws { + + @Test func encodeImagePNGTransparent() throws { // Given let image = Test.image(named: "swift", extension: "png") let encoder = ImageEncoders.Default() - + // When - let data = try XCTUnwrap(encoder.encode(image)) - + let data = try #require(encoder.encode(image)) + // Then - XCTAssertEqual(AssetType(data), .png) + #expect(AssetType(data) == .png) } - - func testPrefersHEIF() throws { + + @Test func prefersHEIF() throws { // Given let image = Test.image var encoder = ImageEncoders.Default() encoder.isHEIFPreferred = true - + // When - let data = try XCTUnwrap(encoder.encode(image)) - + let data = try #require(encoder.encode(image)) + // Then - XCTAssertNil(AssetType(data)) // TODO: update when HEIF support is added + #expect(AssetType(data) == nil) // TODO: update when HEIF support is added // TODO: update when HEIF support is added } - + #if os(iOS) || os(tvOS) || os(visionOS) - - func testEncodeCoreImageBackedImage() throws { + + @Test func encodeCoreImageBackedImage() throws { // Given let image = try ImageProcessors.GaussianBlur().processThrowing(Test.image) let encoder = ImageEncoders.Default() - + // When - let data = try XCTUnwrap(encoder.encode(image)) - + let data = try #require(encoder.encode(image)) + // Then encoded as PNG because GaussianBlur produces // images with alpha channel - XCTAssertEqual(AssetType(data), .png) + #expect(AssetType(data) == .png) } - + #endif - + // MARK: - Misc - - func testIsOpaqueWithOpaquePNG() { + + @Test func isOpaqueWithOpaquePNG() { let image = Test.image(named: "fixture", extension: "png") #if os(macOS) - XCTAssertFalse(image.cgImage!.isOpaque) + #expect(!image.cgImage!.isOpaque) #else - XCTAssertTrue(image.cgImage!.isOpaque) + #expect(image.cgImage!.isOpaque) #endif } - - func testIsOpaqueWithTransparentPNG() { + + @Test func isOpaqueWithTransparentPNG() { let image = Test.image(named: "swift", extension: "png") - XCTAssertFalse(image.cgImage!.isOpaque) + #expect(!image.cgImage!.isOpaque) } }