diff --git a/Tests/DefaultsTests/DefaultsColorTests.swift b/Tests/DefaultsTests/DefaultsColorTests.swift new file mode 100644 index 0000000..6852932 --- /dev/null +++ b/Tests/DefaultsTests/DefaultsColorTests.swift @@ -0,0 +1,24 @@ +import SwiftUI +import Defaults +import XCTest + +@available(iOS 15, tvOS 15, watchOS 8, *) +final class DefaultsColorTests: XCTestCase { + override func setUp() { + super.setUp() + Defaults.removeAll() + } + + override func tearDown() { + super.tearDown() + Defaults.removeAll() + } + + func testPreservesColorSpace() { + let fixture = Color(.displayP3, red: 1, green: 0.3, blue: 0.7, opacity: 1) + let key = Defaults.Key("independentColorPreservesColorSpaceKey") + Defaults[key] = fixture + XCTAssertEqual(Defaults[key]?.cgColor?.colorSpace, fixture.cgColor?.colorSpace) + XCTAssertEqual(Defaults[key]?.cgColor, fixture.cgColor) + } +} diff --git a/Tests/DefaultsTests/DefaultsNSColorTests.swift b/Tests/DefaultsTests/DefaultsNSColorTests.swift index 051d39f..49a8c05 100644 --- a/Tests/DefaultsTests/DefaultsNSColorTests.swift +++ b/Tests/DefaultsTests/DefaultsNSColorTests.swift @@ -1,3 +1,4 @@ +#if canImport(AppKit) import Foundation import Defaults import XCTest @@ -31,6 +32,16 @@ final class DefaultsNSColorTests: XCTestCase { XCTAssertTrue(Defaults[key].isEqual(fixtureColor1)) } + func testPreservesColorSpace() { + let fixture = NSColor(displayP3Red: 1, green: 0.3, blue: 0.7, alpha: 1) + let key = Defaults.Key("independentNSColorPreservesColorSpaceKey") + Defaults[key] = fixture + XCTAssertEqual(Defaults[key]?.colorSpace, fixture.colorSpace) + XCTAssertEqual(Defaults[key]?.cgColor.colorSpace, fixture.cgColor.colorSpace) + XCTAssertEqual(Defaults[key], fixture) + XCTAssertEqual(Defaults[key]?.cgColor, fixture.cgColor) + } + func testOptionalKey() { let key = Defaults.Key("independentNSColorOptionalKey") XCTAssertNil(Defaults[key]) @@ -304,3 +315,4 @@ final class DefaultsNSColorTests: XCTestCase { waitForExpectations(timeout: 10) } } +#endif diff --git a/Tests/DefaultsTests/DefaultsUIColorTests.swift b/Tests/DefaultsTests/DefaultsUIColorTests.swift index 0e615fd..d21a1a8 100644 --- a/Tests/DefaultsTests/DefaultsUIColorTests.swift +++ b/Tests/DefaultsTests/DefaultsUIColorTests.swift @@ -32,6 +32,15 @@ final class DefaultsNSColorTests: XCTestCase { XCTAssertTrue(Defaults[key].isEqual(fixtureColor1)) } + func testPreservesColorSpace() { + let fixture = UIColor(displayP3Red: 1, green: 0.3, blue: 0.7, alpha: 1) + let key = Defaults.Key("independentNSColorPreservesColorSpaceKey") + Defaults[key] = fixture + XCTAssertEqual(Defaults[key], fixture) + XCTAssertEqual(Defaults[key]?.cgColor.colorSpace, fixture.cgColor.colorSpace) + XCTAssertEqual(Defaults[key]?.cgColor, fixture.cgColor) + } + func testOptionalKey() { let key = Defaults.Key("independentNSColorOptionalKey") XCTAssertNil(Defaults[key])