@@ -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,43 @@ struct ConditionalMetadataTests {
62
63
let secondMetadata = Optional< P3> . makeConditionalMetadata( TestProtocolDescriptor . self)
63
64
#expect( firstMetadata. ids != secondMetadata. ids)
64
65
}
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
+ }
65
105
}
0 commit comments