Defaults/Tests/DefaultsTests/DefaultsColorTests.swift

48 lines
1.2 KiB
Swift
Raw Normal View History

2022-04-20 19:16:30 +08:00
import SwiftUI
2024-09-26 05:17:26 +08:00
import Testing
2022-04-20 19:16:30 +08:00
import Defaults
2024-09-26 05:17:26 +08:00
private let suite_ = createSuite()
@Suite(.serialized)
final class DefaultsColorTests {
init() {
Defaults.removeAll(suite: suite_)
2022-04-20 19:16:30 +08:00
}
2024-09-26 05:17:26 +08:00
deinit {
Defaults.removeAll(suite: suite_)
2022-04-20 19:16:30 +08:00
}
2024-09-26 05:17:26 +08:00
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, visionOS 1.0, *)
2024-09-30 18:19:33 +08:00
@Test(.disabled()) // Fails on CI, but not locally.
2022-04-20 19:16:30 +08:00
func testPreservesColorSpace() {
let fixture = Color(.displayP3, red: 1, green: 0.3, blue: 0.7, opacity: 1)
2024-09-26 05:17:26 +08:00
let key = Defaults.Key<Color?>("independentColorPreservesColorSpaceKey", suite: suite_)
2022-04-20 19:16:30 +08:00
Defaults[key] = fixture
2024-09-26 05:17:26 +08:00
#expect(Defaults[key]?.cgColor != nil)
#expect(Defaults[key]?.cgColor?.colorSpace == fixture.cgColor?.colorSpace)
#expect(Defaults[key]?.cgColor == fixture.cgColor)
2022-04-20 19:16:30 +08:00
}
}
2024-09-26 05:17:26 +08:00
@Suite(.serialized)
final class DefaultsColorResolvedTests {
init() {
Defaults.removeAll(suite: suite_)
}
2024-09-26 05:17:26 +08:00
deinit {
Defaults.removeAll(suite: suite_)
}
2024-09-26 05:17:26 +08:00
@available(macOS 14, iOS 17, tvOS 17, watchOS 10, visionOS 1, *)
@Test
func test() {
let fixture = Color(.displayP3, red: 1, green: 0.3, blue: 0.7, opacity: 1).resolve(in: .init())
2024-09-26 05:17:26 +08:00
let key = Defaults.Key<Color.Resolved?>("independentColorResolvedKey", suite: suite_)
Defaults[key] = fixture
2024-09-26 05:17:26 +08:00
#expect(Defaults[key]?.cgColor == fixture.cgColor)
}
}