Swift Testing for Compound (#5110)

This commit is contained in:
Mauro
2026-02-16 14:04:04 +01:00
committed by GitHub
parent 26bfa6ed7c
commit e8a6af1956
7 changed files with 135 additions and 122 deletions
@@ -8,36 +8,33 @@
@testable import Compound
import Foundation
import XCTest
import Testing
final class OverrideColorTests: XCTestCase {
func testSwiftUI() async {
// For some very weird reason we need this to be async, `@MainActor` is not enough
// it will compile but when running it will crash at the end of the run due to some deinit problems.
// The other solution would be to make CompoundColors nonisolated but we don't really need that.
await MainActor.run {
let colors = CompoundColors()
let tokens = CompoundColorTokens()
XCTAssertEqual(colors.textPrimary, tokens.textPrimary)
colors.override(\.textPrimary, with: .pink)
XCTAssertEqual(colors.textPrimary, .pink)
colors.override(\.textPrimary, with: nil)
XCTAssertEqual(colors.textPrimary, tokens.textPrimary)
}
}
/// UIColors are nonisolated, so this is fine.
func testUIKit() {
let colors = CompoundUIColors()
let tokens = CompoundUIColorTokens()
XCTAssertEqual(colors.textPrimary, tokens.textPrimary)
@Suite
struct OverrideColorTests {
@Test("SwiftUI color override")
func swiftUI() {
let colors = CompoundColors()
let tokens = CompoundColorTokens()
#expect(colors.textPrimary == tokens.textPrimary)
colors.override(\.textPrimary, with: .systemPink)
XCTAssertEqual(colors.textPrimary, .systemPink)
colors.override(\.textPrimary, with: .pink)
#expect(colors.textPrimary == .pink)
colors.override(\.textPrimary, with: nil)
XCTAssertEqual(colors.textPrimary, tokens.textPrimary)
#expect(colors.textPrimary == tokens.textPrimary)
}
@Test("UIKit color override")
func uiKit() {
let colors = CompoundUIColors()
let tokens = CompoundUIColorTokens()
#expect(colors.textPrimary == tokens.textPrimary)
colors.override(\.textPrimary, with: .systemPink)
#expect(colors.textPrimary == .systemPink)
colors.override(\.textPrimary, with: nil)
#expect(colors.textPrimary == tokens.textPrimary)
}
}