Add tests for #97
This commit is contained in:
parent
119f654d44
commit
3535f3d088
|
@ -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<Color?>("independentColorPreservesColorSpaceKey")
|
||||||
|
Defaults[key] = fixture
|
||||||
|
XCTAssertEqual(Defaults[key]?.cgColor?.colorSpace, fixture.cgColor?.colorSpace)
|
||||||
|
XCTAssertEqual(Defaults[key]?.cgColor, fixture.cgColor)
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,3 +1,4 @@
|
||||||
|
#if canImport(AppKit)
|
||||||
import Foundation
|
import Foundation
|
||||||
import Defaults
|
import Defaults
|
||||||
import XCTest
|
import XCTest
|
||||||
|
@ -31,6 +32,16 @@ final class DefaultsNSColorTests: XCTestCase {
|
||||||
XCTAssertTrue(Defaults[key].isEqual(fixtureColor1))
|
XCTAssertTrue(Defaults[key].isEqual(fixtureColor1))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testPreservesColorSpace() {
|
||||||
|
let fixture = NSColor(displayP3Red: 1, green: 0.3, blue: 0.7, alpha: 1)
|
||||||
|
let key = Defaults.Key<NSColor?>("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() {
|
func testOptionalKey() {
|
||||||
let key = Defaults.Key<NSColor?>("independentNSColorOptionalKey")
|
let key = Defaults.Key<NSColor?>("independentNSColorOptionalKey")
|
||||||
XCTAssertNil(Defaults[key])
|
XCTAssertNil(Defaults[key])
|
||||||
|
@ -304,3 +315,4 @@ final class DefaultsNSColorTests: XCTestCase {
|
||||||
waitForExpectations(timeout: 10)
|
waitForExpectations(timeout: 10)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
|
@ -32,6 +32,15 @@ final class DefaultsNSColorTests: XCTestCase {
|
||||||
XCTAssertTrue(Defaults[key].isEqual(fixtureColor1))
|
XCTAssertTrue(Defaults[key].isEqual(fixtureColor1))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testPreservesColorSpace() {
|
||||||
|
let fixture = UIColor(displayP3Red: 1, green: 0.3, blue: 0.7, alpha: 1)
|
||||||
|
let key = Defaults.Key<UIColor?>("independentNSColorPreservesColorSpaceKey")
|
||||||
|
Defaults[key] = fixture
|
||||||
|
XCTAssertEqual(Defaults[key], fixture)
|
||||||
|
XCTAssertEqual(Defaults[key]?.cgColor.colorSpace, fixture.cgColor.colorSpace)
|
||||||
|
XCTAssertEqual(Defaults[key]?.cgColor, fixture.cgColor)
|
||||||
|
}
|
||||||
|
|
||||||
func testOptionalKey() {
|
func testOptionalKey() {
|
||||||
let key = Defaults.Key<UIColor?>("independentNSColorOptionalKey")
|
let key = Defaults.Key<UIColor?>("independentNSColorOptionalKey")
|
||||||
XCTAssertNil(Defaults[key])
|
XCTAssertNil(Defaults[key])
|
||||||
|
|
Loading…
Reference in New Issue