Skip to content

Commit 7aa0406

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

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

Tests/OpenSwiftUICoreTests/Runtime/ConditionalMetadataTests.swift

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

0 commit comments

Comments
 (0)