1
1
/*
2
2
This source file is part of the Swift.org open source project
3
3
4
- Copyright (c) 2021 Apple Inc. and the Swift project authors
4
+ Copyright (c) 2021-2022 Apple Inc. and the Swift project authors
5
5
Licensed under Apache License v2.0 with Runtime Library Exception
6
6
7
7
See https://swift.org/LICENSE.txt for license information
@@ -24,8 +24,8 @@ class SymbolGraphRelationshipsBuilderTests: XCTestCase {
24
24
25
25
let moduleRef = ResolvedTopicReference ( bundleIdentifier: bundle. identifier, path: " /documentation/MyKit " , sourceLanguage: . swift)
26
26
27
- let sourceSymbol = SymbolGraph . Symbol ( identifier: sourceIdentifier, names: SymbolGraph . Symbol. Names ( title: " A " , navigator: nil , subHeading: nil , prose: nil ) , pathComponents: [ " MyKit " , " A " ] , docComment: nil , accessLevel: . init( rawValue: " public " ) , kind: SymbolGraph . Symbol . Kind ( parsedIdentifier : . class , displayName : " Class " ) , mixins: [ : ] )
28
- let targetSymbol = SymbolGraph . Symbol ( identifier: targetIdentifier, names: SymbolGraph . Symbol. Names ( title: " B " , navigator: nil , subHeading: nil , prose: nil ) , pathComponents: [ " MyKit " , " B " ] , docComment: nil , accessLevel: . init( rawValue: " public " ) , kind: SymbolGraph . Symbol . Kind ( parsedIdentifier : . class , displayName : " Protocol " ) , mixins: [ : ] )
27
+ let sourceSymbol = SymbolGraph . Symbol ( identifier: sourceIdentifier, names: SymbolGraph . Symbol. Names ( title: " A " , navigator: nil , subHeading: nil , prose: nil ) , pathComponents: [ " MyKit " , " A " ] , docComment: nil , accessLevel: . init( rawValue: " public " ) , kind: sourceType , mixins: [ : ] )
28
+ let targetSymbol = SymbolGraph . Symbol ( identifier: targetIdentifier, names: SymbolGraph . Symbol. Names ( title: " B " , navigator: nil , subHeading: nil , prose: nil ) , pathComponents: [ " MyKit " , " B " ] , docComment: nil , accessLevel: . init( rawValue: " public " ) , kind: targetType , mixins: [ : ] )
29
29
30
30
let engine = DiagnosticEngine ( )
31
31
symbolIndex [ " A " ] = DocumentationNode ( reference: sourceRef, symbol: sourceSymbol, platformName: " macOS " , moduleReference: moduleRef, article: nil , engine: engine)
@@ -145,12 +145,26 @@ class SymbolGraphRelationshipsBuilderTests: XCTestCase {
145
145
var symbolIndex = [ String: DocumentationNode] ( )
146
146
let engine = DiagnosticEngine ( )
147
147
148
- let edge = createSymbols ( in: & symbolIndex, bundle: bundle, sourceType: . init( parsedIdentifier: . class , displayName: " Class " ) , targetType: . init( parsedIdentifier: . protocol, displayName: " Protocol " ) )
148
+ let edge = createSymbols ( in: & symbolIndex, bundle: bundle, sourceType: . init( parsedIdentifier: . method , displayName: " Method " ) , targetType: . init( parsedIdentifier: . protocol, displayName: " Protocol " ) )
149
149
150
150
// Adding the relationship
151
151
SymbolGraphRelationshipsBuilder . addRequirementRelationship ( edge: edge, in: bundle, symbolIndex: & symbolIndex, engine: engine)
152
152
153
153
// Test default implementation was added
154
154
XCTAssertTrue ( ( symbolIndex [ " A " ] !. semantic as! Symbol ) . isRequired)
155
155
}
156
+
157
+ func testOptionalRequirementRelationship( ) throws {
158
+ let bundle = try testBundle ( named: " TestBundle " )
159
+ var symbolIndex = [ String: DocumentationNode] ( )
160
+ let engine = DiagnosticEngine ( )
161
+
162
+ let edge = createSymbols ( in: & symbolIndex, bundle: bundle, sourceType: . init( parsedIdentifier: . method, displayName: " Method " ) , targetType: . init( parsedIdentifier: . protocol, displayName: " Protocol " ) )
163
+
164
+ // Adding the relationship
165
+ SymbolGraphRelationshipsBuilder . addOptionalRequirementRelationship ( edge: edge, in: bundle, symbolIndex: & symbolIndex, engine: engine)
166
+
167
+ // Test default implementation was added
168
+ XCTAssertFalse ( ( symbolIndex [ " A " ] !. semantic as! Symbol ) . isRequired)
169
+ }
156
170
}
0 commit comments