Skip to content

Commit b6fdafd

Browse files
committed
More test coverage
1 parent 9f353cc commit b6fdafd

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

Sources/Overlays/_Testing_CoreGraphics/Attachments/AttachableImageFormat+UTType.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ extension AttachableImageFormat {
9494
public init?(pathExtension: String, encodingQuality: Float = 1.0) {
9595
let pathExtension = pathExtension.drop { $0 == "." }
9696

97-
guard let contentType = UTType(filenameExtension: String(pathExtension), conformingTo: .image) else {
97+
guard let contentType = UTType(filenameExtension: String(pathExtension), conformingTo: .image),
98+
contentType.isDeclared else {
9899
return nil
99100
}
100101

Sources/Testing/Attachments/Images/AttachableImageFormat.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,7 @@ extension AttachableImageFormat.Kind: Equatable, Hashable {
9898
return true
9999
case let (.systemValue(lhs), .systemValue(rhs)):
100100
func open<T>(_ lhs: T) -> Bool where T: Equatable {
101-
guard let rhs = rhs as? T else {
102-
return false
103-
}
104-
return lhs == rhs
101+
lhs == (rhs as? T)
105102
}
106103
return open(lhs)
107104
default:

Tests/TestingTests/AttachmentTests.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,34 @@ extension AttachmentTests {
840840
@Test func imageFormatFromPathExtension() {
841841
let format = AttachableImageFormat(pathExtension: "png")
842842
#expect(format != nil)
843+
#expect(format == .png)
844+
845+
let badFormat = AttachableImageFormat(pathExtension: "no-such-image-format")
846+
#expect(badFormat == nil)
847+
}
848+
849+
@available(_uttypesAPI, *)
850+
@Test func imageFormatEquatableConformance() {
851+
let format1 = AttachableImageFormat.png
852+
let format2 = AttachableImageFormat.jpeg
853+
#if canImport(CoreGraphics) && canImport(_Testing_CoreGraphics)
854+
let format3 = AttachableImageFormat(contentType: .tiff)
855+
#elseif canImport(WinSDK) && canImport(_Testing_WinSDK)
856+
let format3 = AttachableImageFormat(encoderCLSID: .CLSID_WICTiffEncoder)
857+
#endif
858+
#expect(format1 == format1)
859+
#expect(format2 == format2)
860+
#expect(format3 == format3)
861+
#expect(format1 != format2)
862+
#expect(format2 != format3)
863+
#expect(format1 != format3)
864+
865+
#expect(format1.hashValue == format1.hashValue)
866+
#expect(format2.hashValue == format2.hashValue)
867+
#expect(format3.hashValue == format3.hashValue)
868+
#expect(format1.hashValue != format2.hashValue)
869+
#expect(format2.hashValue != format3.hashValue)
870+
#expect(format1.hashValue != format3.hashValue)
843871
}
844872
#endif
845873
}

0 commit comments

Comments
 (0)