Skip to content

Commit 52dc129

Browse files
committed
Add StyleContextTests
1 parent ce142fc commit 52dc129

File tree

1 file changed

+253
-0
lines changed

1 file changed

+253
-0
lines changed
Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
1+
//
2+
// StyleContextTests.swift
3+
// OpenSwiftUICoreTests
4+
//
5+
// Author: Claude Code with Claude Sonnet 4.5
6+
7+
@_spi(ForOpenSwiftUIOnly)
8+
import OpenSwiftUICore
9+
import Testing
10+
11+
@MainActor
12+
struct TupleStyleContextTests {
13+
@Test("Test TupleStyleContext accepts single context at index 0")
14+
func acceptsSingleContextAtIndexZero() {
15+
typealias SingleContext = TupleStyleContext<(WindowRootContext)>
16+
#expect(SingleContext.accepts(WindowRootContext.self, at: 0))
17+
#expect(!SingleContext.accepts(MenuStyleContext.self, at: 0))
18+
#expect(!SingleContext.accepts(ToolbarStyleContext.self, at: 0))
19+
}
20+
21+
@Test("Test TupleStyleContext accepts multiple contexts at different indices")
22+
func acceptsMultipleContextsAtDifferentIndices() {
23+
typealias DoubleContext = TupleStyleContext<(WindowRootContext, MenuStyleContext)>
24+
#expect(DoubleContext.accepts(WindowRootContext.self, at: 0))
25+
#expect(DoubleContext.accepts(MenuStyleContext.self, at: 1))
26+
#expect(!DoubleContext.accepts(ToolbarStyleContext.self, at: 0))
27+
}
28+
29+
@Test("Test TupleStyleContext accepts with tuple query type")
30+
func acceptsWithTupleQueryType() {
31+
typealias TripleContext = TupleStyleContext<(WindowRootContext, MenuStyleContext, ToolbarStyleContext)>
32+
typealias DoubleQuery = TupleStyleContext<(WindowRootContext, MenuStyleContext)>
33+
#expect(!TripleContext.accepts(DoubleQuery.self, at: 0))
34+
#expect(TripleContext.accepts(DoubleQuery.self, at: 1))
35+
#expect(TripleContext.accepts(DoubleQuery.self, at: 2))
36+
}
37+
38+
@Test("Test TupleStyleContext rejects query when count exceeds context count")
39+
func rejectsQueryWhenCountExceedsContextCount() {
40+
typealias SingleContext = TupleStyleContext<(WindowRootContext)>
41+
typealias DoubleQuery = TupleStyleContext<(WindowRootContext, MenuStyleContext)>
42+
#expect(!SingleContext.accepts(DoubleQuery.self, at: 0))
43+
}
44+
45+
@Test("Test TupleStyleContext accepts at valid query index")
46+
func acceptsAtValidQueryIndex() {
47+
typealias QuadContext = TupleStyleContext<(WindowRootContext, MenuStyleContext, ToolbarStyleContext, TableStyleContext)>
48+
#expect(QuadContext.accepts(MenuStyleContext.self, at: 1))
49+
#expect(QuadContext.accepts(ToolbarStyleContext.self, at: 2))
50+
#expect(QuadContext.accepts(TableStyleContext.self, at: 3))
51+
}
52+
53+
@Test("Test TupleStyleContext with out of bounds query index")
54+
func outOfBoundsQueryIndex() {
55+
typealias DoubleContext = TupleStyleContext<(WindowRootContext, MenuStyleContext)>
56+
#expect(DoubleContext.accepts(ToolbarStyleContext.self, at: 2))
57+
#expect(DoubleContext.accepts(WindowRootContext.self, at: 5))
58+
}
59+
60+
@Test("Test TupleStyleContext with homogeneous tuple")
61+
func acceptsWithHomogeneousTuple() {
62+
typealias HomogeneousContext = TupleStyleContext<(MenuStyleContext, MenuStyleContext, MenuStyleContext)>
63+
#expect(HomogeneousContext.accepts(MenuStyleContext.self, at: 0))
64+
#expect(HomogeneousContext.accepts(MenuStyleContext.self, at: 1))
65+
#expect(HomogeneousContext.accepts(MenuStyleContext.self, at: 2))
66+
}
67+
68+
@Test("Test TupleStyleContext with different context types")
69+
func acceptsWithDifferentContextTypes() {
70+
typealias MixedContext = TupleStyleContext<(
71+
WindowRootContext,
72+
MenuStyleContext,
73+
ToolbarStyleContext,
74+
ScrollViewStyleContext,
75+
SheetStyleContext
76+
)>
77+
#expect(MixedContext.accepts(WindowRootContext.self, at: 0))
78+
#expect(MixedContext.accepts(MenuStyleContext.self, at: 1))
79+
#expect(MixedContext.accepts(ToolbarStyleContext.self, at: 2))
80+
#expect(MixedContext.accepts(ScrollViewStyleContext.self, at: 3))
81+
#expect(MixedContext.accepts(SheetStyleContext.self, at: 4))
82+
#expect(!MixedContext.accepts(TableStyleContext.self, at: 0))
83+
}
84+
85+
@Test("Test TupleStyleContext accepts nested tuple query")
86+
func acceptsNestedTupleQuery() {
87+
typealias LargeContext = TupleStyleContext<(
88+
WindowRootContext,
89+
MenuStyleContext,
90+
ToolbarStyleContext,
91+
TableStyleContext,
92+
SheetStyleContext
93+
)>
94+
typealias TripleQuery = TupleStyleContext<(MenuStyleContext, ToolbarStyleContext, TableStyleContext)>
95+
#expect(LargeContext.accepts(TripleQuery.self, at: 1))
96+
#expect(!LargeContext.accepts(TripleQuery.self, at: 0))
97+
#expect(LargeContext.accepts(TripleQuery.self, at: 3))
98+
}
99+
100+
@Test("Test TupleStyleContext accepts with accessibility contexts")
101+
func acceptsWithAccessibilityContexts() {
102+
typealias AccessibilityContext = TupleStyleContext<(
103+
AccessibilityRepresentableStyleContext,
104+
AccessibilityQuickActionStyleContext
105+
)>
106+
#expect(AccessibilityContext.accepts(AccessibilityRepresentableStyleContext.self, at: 0))
107+
#expect(AccessibilityContext.accepts(AccessibilityQuickActionStyleContext.self, at: 1))
108+
}
109+
110+
@Test("Test TupleStyleContext accepts with container and list contexts")
111+
func acceptsWithContainerAndListContexts() {
112+
typealias ContainerContext = TupleStyleContext<(
113+
ContainerStyleContext,
114+
ContentListStyleContext,
115+
MultimodalListContext
116+
)>
117+
#expect(ContainerContext.accepts(ContainerStyleContext.self, at: 0))
118+
#expect(ContainerContext.accepts(ContentListStyleContext.self, at: 1))
119+
#expect(ContainerContext.accepts(MultimodalListContext.self, at: 2))
120+
}
121+
122+
@Test("Test TupleStyleContext with sidebar and inspector contexts")
123+
func acceptsWithSidebarAndInspectorContexts() {
124+
typealias SidebarContext = TupleStyleContext<(SidebarStyleContext, InspectorStyleContext)>
125+
#expect(SidebarContext.accepts(SidebarStyleContext.self, at: 0))
126+
#expect(SidebarContext.accepts(InspectorStyleContext.self, at: 1))
127+
#expect(!SidebarContext.accepts(WindowRootContext.self, at: 0))
128+
}
129+
130+
@Test("Test TupleStyleContext with sheet and dialog contexts")
131+
func acceptsWithSheetAndDialogContexts() {
132+
typealias SheetContext = TupleStyleContext<(
133+
SheetStyleContext,
134+
SheetToolbarStyleContext,
135+
DialogActionStyleContext
136+
)>
137+
#expect(SheetContext.accepts(SheetStyleContext.self, at: 0))
138+
#expect(SheetContext.accepts(SheetToolbarStyleContext.self, at: 1))
139+
#expect(SheetContext.accepts(DialogActionStyleContext.self, at: 2))
140+
}
141+
}
142+
143+
@MainActor
144+
struct StyleContextVisitorTests {
145+
private struct CollectingVisitor: StyleContextVisitor {
146+
var visitedTypes: [String] = []
147+
148+
mutating func visit<C>(_ context: C.Type) where C: StyleContext {
149+
visitedTypes.append(String(describing: context))
150+
}
151+
}
152+
153+
@Test("Test TupleStyleContext visitStyle with single context")
154+
func visitStyleWithSingleContext() {
155+
typealias SingleContext = TupleStyleContext<(WindowRootContext)>
156+
var visitor = CollectingVisitor()
157+
SingleContext.visitStyle(&visitor)
158+
#expect(visitor.visitedTypes.contains("WindowRootContext"))
159+
}
160+
161+
@Test("Test TupleStyleContext visitStyle with multiple contexts")
162+
func visitStyleWithMultipleContexts() {
163+
typealias TripleContext = TupleStyleContext<(WindowRootContext, MenuStyleContext, ToolbarStyleContext)>
164+
var visitor = CollectingVisitor()
165+
TripleContext.visitStyle(&visitor)
166+
#expect(visitor.visitedTypes.contains("WindowRootContext"))
167+
#expect(visitor.visitedTypes.contains("MenuStyleContext"))
168+
#expect(visitor.visitedTypes.contains("ToolbarStyleContext"))
169+
}
170+
}
171+
172+
@MainActor
173+
struct ConcreteStyleContextTests {
174+
@Test("Test WindowRootContext accepts itself")
175+
func windowRootContextAcceptsItself() {
176+
#expect(WindowRootContext.accepts(WindowRootContext.self, at: 0))
177+
#expect(!WindowRootContext.accepts(MenuStyleContext.self, at: 0))
178+
}
179+
180+
@Test("Test NoStyleContext accepts itself")
181+
func noStyleContextAcceptsItself() {
182+
#expect(NoStyleContext.accepts(NoStyleContext.self, at: 0))
183+
#expect(!NoStyleContext.accepts(WindowRootContext.self, at: 0))
184+
}
185+
186+
@Test("Test acceptsTop convenience method")
187+
func acceptsTopConvenienceMethod() {
188+
#expect(WindowRootContext.acceptsTop(WindowRootContext.self))
189+
#expect(!WindowRootContext.acceptsTop(MenuStyleContext.self))
190+
191+
typealias DoubleContext = TupleStyleContext<(WindowRootContext, MenuStyleContext)>
192+
#expect(DoubleContext.acceptsTop(WindowRootContext.self))
193+
#expect(!DoubleContext.acceptsTop(MenuStyleContext.self))
194+
}
195+
196+
@Test("Test concrete context initialization")
197+
func concreteContextInitialization() {
198+
_ = WindowRootContext()
199+
_ = AccessibilityRepresentableStyleContext()
200+
_ = AccessibilityQuickActionStyleContext()
201+
_ = ContainerStyleContext()
202+
_ = ContentListStyleContext()
203+
_ = DocumentStyleContext()
204+
_ = ControlGroupStyleContext()
205+
_ = DialogActionStyleContext()
206+
_ = HostingConfigurationContext()
207+
_ = MenuStyleContext()
208+
_ = MultimodalListContext()
209+
_ = MultimodalListGridContext()
210+
_ = MultimodalListStackContext()
211+
_ = NoStyleContext()
212+
_ = ScrollViewStyleContext()
213+
_ = TextInputSuggestionsContext()
214+
_ = SectionHeaderStyleContext()
215+
_ = SheetStyleContext()
216+
_ = SheetToolbarStyleContext()
217+
_ = SidebarStyleContext()
218+
_ = SwipeActionsStyleContext()
219+
_ = TableStyleContext()
220+
_ = ToolbarStyleContext()
221+
_ = InspectorStyleContext()
222+
_ = MenuBarExtraWindowStyleContext()
223+
}
224+
225+
@Test("Test concrete context static accessors")
226+
func concreteContextStaticAccessors() {
227+
_ = WindowRootContext.windowRoot
228+
_ = AccessibilityRepresentableStyleContext.accessibilityRepresentable
229+
_ = AccessibilityQuickActionStyleContext.accessibilityQuickAction
230+
_ = ContainerStyleContext.container
231+
_ = ContentListStyleContext.contentList
232+
_ = DocumentStyleContext.document
233+
_ = ControlGroupStyleContext.controlGroup
234+
_ = DialogActionStyleContext.dialogAction
235+
_ = HostingConfigurationContext.hostingConfiguration
236+
_ = MenuStyleContext.menu
237+
_ = MultimodalListContext.multimodalList
238+
_ = MultimodalListGridContext.multimodalListGrid
239+
_ = MultimodalListStackContext.multimodalListStack
240+
_ = NoStyleContext.none
241+
_ = ScrollViewStyleContext.scrollView
242+
_ = TextInputSuggestionsContext.textInputSuggestions
243+
_ = SectionHeaderStyleContext.sectionHeader
244+
_ = SheetStyleContext.sheet
245+
_ = SheetToolbarStyleContext.sheetToolbar
246+
_ = SidebarStyleContext.sidebar
247+
_ = SwipeActionsStyleContext.swipeActions
248+
_ = TableStyleContext.table
249+
_ = ToolbarStyleContext.toolbar
250+
_ = InspectorStyleContext.inspector
251+
_ = MenuBarExtraWindowStyleContext.menuBarExtraWindow
252+
}
253+
}

0 commit comments

Comments
 (0)