mirror of
https://github.com/phranck/TUIkit.git
synced 2026-05-21 09:50:35 +00:00
82544e0e02
Add @MainActor to View, ViewModifier, Renderable, App, Scene protocols and all builders (ViewBuilder, SceneBuilder, ChildInfoProvider). Update renderToBuffer(), makeChildInfo(), resolveChildInfos() for main-actor isolation. Mark generic Equatable conformances with @preconcurrency. Update all 45 test suites with @MainActor annotation.
62 lines
1.7 KiB
Swift
62 lines
1.7 KiB
Swift
// 🖥️ TUIKit — Terminal UI Kit for Swift
|
||
// PreferenceKeyTests.swift
|
||
//
|
||
// Created by LAYERED.work
|
||
// License: MIT
|
||
|
||
import Testing
|
||
|
||
@testable import TUIkit
|
||
|
||
/// A simple string preference key for testing (default reduce = last value).
|
||
private struct TestStringKey: PreferenceKey {
|
||
static let defaultValue: String = "default"
|
||
}
|
||
|
||
/// A counter preference key with additive reduce.
|
||
private struct TestCounterKey: PreferenceKey {
|
||
static let defaultValue: Int = 0
|
||
|
||
static func reduce(value: inout Int, nextValue: () -> Int) {
|
||
value += nextValue()
|
||
}
|
||
}
|
||
|
||
/// An array preference key with append reduce.
|
||
private struct TestArrayKey: PreferenceKey {
|
||
static let defaultValue: [String] = []
|
||
|
||
static func reduce(value: inout [String], nextValue: () -> [String]) {
|
||
value.append(contentsOf: nextValue())
|
||
}
|
||
}
|
||
|
||
@MainActor
|
||
@Suite("PreferenceKey Tests")
|
||
struct PreferenceKeyTests {
|
||
|
||
@Test("Default reduce uses last value")
|
||
func defaultReduce() {
|
||
var value = TestStringKey.defaultValue
|
||
TestStringKey.reduce(value: &value) { "first" }
|
||
TestStringKey.reduce(value: &value) { "second" }
|
||
#expect(value == "second")
|
||
}
|
||
|
||
@Test("Custom additive reduce accumulates")
|
||
func customAdditiveReduce() {
|
||
var value = TestCounterKey.defaultValue
|
||
TestCounterKey.reduce(value: &value) { 5 }
|
||
TestCounterKey.reduce(value: &value) { 3 }
|
||
#expect(value == 8)
|
||
}
|
||
|
||
@Test("Custom array reduce appends")
|
||
func customArrayReduce() {
|
||
var value = TestArrayKey.defaultValue
|
||
TestArrayKey.reduce(value: &value) { ["a"] }
|
||
TestArrayKey.reduce(value: &value) { ["b", "c"] }
|
||
#expect(value == ["a", "b", "c"])
|
||
}
|
||
}
|