@@ -20,6 +20,7 @@ extension TestProtocolDescriptor: ConditionalProtocolDescriptor {
20
20
21
21
@Suite ( . enabled( if: swiftToolchainSupported) , . serialized)
22
22
struct ConditionalMetadataTests {
23
+ struct EmptyP : TestProtocol { }
23
24
struct P1 : TestProtocol { }
24
25
struct P2 : TestProtocol { }
25
26
@@ -53,7 +54,7 @@ struct ConditionalMetadataTests {
53
54
}
54
55
55
56
@Test
56
- func conditionalTypeDescriptorCaching( ) throws {
57
+ func conditionalTypeDescriptorCaching( ) {
57
58
struct P3 : TestProtocol { }
58
59
59
60
let firstMetadata = Optional< P3> . makeConditionalMetadata( TestProtocolDescriptor . self)
@@ -62,4 +63,45 @@ struct ConditionalMetadataTests {
62
63
let secondMetadata = Optional< P3> . makeConditionalMetadata( TestProtocolDescriptor . self)
63
64
#expect( firstMetadata. ids != secondMetadata. ids)
64
65
}
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
65
107
}
0 commit comments