@@ -186,4 +186,36 @@ class SymbolGraphRelationshipsBuilderTests: XCTestCase {
186
186
// Test default implementation was added
187
187
XCTAssertFalse ( ( documentationCache [ " A " ] !. semantic as! Symbol ) . isRequired)
188
188
}
189
+
190
+ func testRequiredAndOptionalRequirementRelationships( ) throws {
191
+ do {
192
+ let ( bundle, _) = try testBundleAndContext ( )
193
+ var documentationCache = DocumentationContext . ContentCache < DocumentationNode > ( )
194
+ let engine = DiagnosticEngine ( )
195
+
196
+ let edge = createSymbols ( documentationCache: & documentationCache, bundle: bundle, sourceType: . init( parsedIdentifier: . method, displayName: " Method " ) , targetType: . init( parsedIdentifier: . protocol, displayName: " Protocol " ) )
197
+
198
+ // Adding the "required" relationship before the "optional" one
199
+ SymbolGraphRelationshipsBuilder . addRequirementRelationship ( edge: edge, localCache: documentationCache, engine: engine)
200
+ SymbolGraphRelationshipsBuilder . addOptionalRequirementRelationship ( edge: edge, localCache: documentationCache, engine: engine)
201
+
202
+ // Make sure that the "optional" relationship wins
203
+ XCTAssertFalse ( ( documentationCache [ " A " ] !. semantic as! Symbol ) . isRequired)
204
+ }
205
+
206
+ do {
207
+ let ( bundle, _) = try testBundleAndContext ( )
208
+ var documentationCache = DocumentationContext . ContentCache < DocumentationNode > ( )
209
+ let engine = DiagnosticEngine ( )
210
+
211
+ let edge = createSymbols ( documentationCache: & documentationCache, bundle: bundle, sourceType: . init( parsedIdentifier: . method, displayName: " Method " ) , targetType: . init( parsedIdentifier: . protocol, displayName: " Protocol " ) )
212
+
213
+ // Adding the "optional" relationship before the "required" one
214
+ SymbolGraphRelationshipsBuilder . addOptionalRequirementRelationship ( edge: edge, localCache: documentationCache, engine: engine)
215
+ SymbolGraphRelationshipsBuilder . addRequirementRelationship ( edge: edge, localCache: documentationCache, engine: engine)
216
+
217
+ // Make sure that the "optional" relationship still wins
218
+ XCTAssertFalse ( ( documentationCache [ " A " ] !. semantic as! Symbol ) . isRequired)
219
+ }
220
+ }
189
221
}
0 commit comments