Skip to content

Commit dfae926

Browse files
committed
Update ConditionalMetadata test case
1 parent 1788b7c commit dfae926

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

Tests/OpenSwiftUICoreTests/Runtime/ConditionalMetadataTests.swift

+43-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ extension TestProtocolDescriptor: ConditionalProtocolDescriptor {
2020

2121
@Suite(.enabled(if: swiftToolchainSupported), .serialized)
2222
struct ConditionalMetadataTests {
23+
struct EmptyP: TestProtocol {}
2324
struct P1: TestProtocol {}
2425
struct P2: TestProtocol {}
2526

@@ -53,7 +54,7 @@ struct ConditionalMetadataTests {
5354
}
5455

5556
@Test
56-
func conditionalTypeDescriptorCaching() throws {
57+
func conditionalTypeDescriptorCaching() {
5758
struct P3: TestProtocol {}
5859

5960
let firstMetadata = Optional<P3>.makeConditionalMetadata(TestProtocolDescriptor.self)
@@ -62,4 +63,45 @@ struct ConditionalMetadataTests {
6263
let secondMetadata = Optional<P3>.makeConditionalMetadata(TestProtocolDescriptor.self)
6364
#expect(firstMetadata.ids != secondMetadata.ids)
6465
}
66+
67+
#if OPENSWIFTUI_SUPPORT_2024_API
68+
@Test
69+
func childInfo() throws {
70+
// optional
71+
let optionalMetadata = Optional<P1>.makeConditionalMetadata(TestProtocolDescriptor.self)
72+
let value: P1? = P1()
73+
withUnsafePointer(to: value) { ptr in
74+
let (type, id) = optionalMetadata.childInfo(ptr: ptr, emptyType: EmptyP.self)
75+
#expect(type == P1.self)
76+
#expect(id != nil)
77+
}
78+
let nilP: P1? = nil
79+
withUnsafePointer(to: nilP) { ptr in
80+
let (type, id) = optionalMetadata.childInfo(ptr: ptr, emptyType: EmptyP.self)
81+
#expect(type == EmptyP.self)
82+
#expect(id != nil)
83+
}
84+
85+
// either
86+
let eitherMetadata = ConditionalMetadata(ConditionalTypeDescriptor<TestProtocolDescriptor>(EitherType.self))
87+
let trueValue = EitherType(__storage: .trueContent(P1()))
88+
withUnsafePointer(to: trueValue) { ptr in
89+
let (type, id) = eitherMetadata.childInfo(ptr: ptr, emptyType: EmptyP.self)
90+
#expect(type == P1.self)
91+
#expect(id != nil)
92+
}
93+
let falseValue = EitherType(__storage: .falseContent(P2()))
94+
withUnsafePointer(to: falseValue) { ptr in
95+
let (type, id) = eitherMetadata.childInfo(ptr: ptr, emptyType: EmptyP.self)
96+
#expect(type == P2.self)
97+
#expect(id != nil)
98+
}
99+
let otherValue = 0
100+
withUnsafePointer(to: otherValue) { ptr in
101+
let (type, id) = eitherMetadata.childInfo(ptr: ptr, emptyType: EmptyP.self)
102+
#expect(type == P1.self)
103+
#expect(id != nil)
104+
}
105+
}
106+
#endif
65107
}

0 commit comments

Comments
 (0)