|
11 | 11 | //===----------------------------------------------------------------------===//
|
12 | 12 |
|
13 | 13 | import Foundation
|
| 14 | +import ISDBTestSupport |
14 | 15 | import LanguageServerProtocol
|
15 | 16 | import LSPTestSupport
|
16 | 17 | import LSPLogging
|
@@ -114,25 +115,59 @@ final class SwiftInterfaceTests: XCTestCase {
|
114 | 115 | """))
|
115 | 116 | }
|
116 | 117 |
|
117 |
| - func testDefinitionInSystemModuleInterface() throws { |
118 |
| - guard let ws = try staticSourceKitSwiftPMWorkspace(name: "SwiftPMPackage") else { return } |
119 |
| - try ws.buildAndIndex(withSystemSymbols: true) |
120 |
| - let stringRef = ws.testLoc("Lib.a.string") |
121 |
| - try ws.openDocument(stringRef.url, language: .swift) |
| 118 | + /// Used by testDefinitionInSystemModuleInterface |
| 119 | + func testSystemSwiftInterface( |
| 120 | + _ testLoc: TestLocation, |
| 121 | + ws: SKSwiftPMTestWorkspace, |
| 122 | + swiftInterfaceFile: String, |
| 123 | + linePrefix: String |
| 124 | + ) throws { |
| 125 | + try ws.openDocument(testLoc.url, language: .swift) |
122 | 126 | let definition = try ws.sk.sendSync(DefinitionRequest(
|
123 |
| - textDocument: stringRef.docIdentifier, |
124 |
| - position: stringRef.position)) |
| 127 | + textDocument: testLoc.docIdentifier, |
| 128 | + position: testLoc.position)) |
125 | 129 | guard case .locations(let jump) = definition else {
|
126 | 130 | XCTFail("Response is not locations")
|
127 | 131 | return
|
128 | 132 | }
|
129 | 133 | let location = try XCTUnwrap(jump.first)
|
130 |
| - XCTAssertTrue(location.uri.pseudoPath.hasSuffix("/Swift.String.swiftinterface")) |
| 134 | + XCTAssertTrue(location.uri.pseudoPath.hasSuffix(swiftInterfaceFile)) |
131 | 135 | // load contents of swiftinterface
|
132 | 136 | let contents = try XCTUnwrap(location.uri.fileURL.flatMap({ try String(contentsOf: $0, encoding: .utf8) }))
|
133 | 137 | let lineTable = LineTable(contents)
|
134 | 138 | let line = lineTable[location.range.lowerBound.line]
|
135 |
| - XCTAssert(line.hasPrefix("@frozen public struct String")) |
| 139 | + XCTAssert(line.hasPrefix(linePrefix)) |
| 140 | + ws.closeDocument(testLoc.url) |
| 141 | + } |
| 142 | + |
| 143 | + func testDefinitionInSystemModuleInterface() throws { |
| 144 | + guard let ws = try staticSourceKitSwiftPMWorkspace(name: "SystemSwiftInterface") else { return } |
| 145 | + try ws.buildAndIndex(withSystemSymbols: true) |
| 146 | + let stringRef = ws.testLoc("lib.string") |
| 147 | + let intRef = ws.testLoc("lib.integer") |
| 148 | + let withTaskGroupRef = ws.testLoc("lib.withTaskGroup") |
| 149 | + |
| 150 | + // Test stdlib with one submodule |
| 151 | + try testSystemSwiftInterface( |
| 152 | + stringRef, |
| 153 | + ws: ws, |
| 154 | + swiftInterfaceFile: "/Swift.String.swiftinterface", |
| 155 | + linePrefix: "@frozen public struct String" |
| 156 | + ) |
| 157 | + // Test stdlib with two submodules |
| 158 | + try testSystemSwiftInterface( |
| 159 | + intRef, |
| 160 | + ws: ws, |
| 161 | + swiftInterfaceFile: "/Swift.Math.Integers.swiftinterface", |
| 162 | + linePrefix: "@frozen public struct Int" |
| 163 | + ) |
| 164 | + // Test concurrency |
| 165 | + try testSystemSwiftInterface( |
| 166 | + withTaskGroupRef, |
| 167 | + ws: ws, |
| 168 | + swiftInterfaceFile: "/_Concurrency.swiftinterface", |
| 169 | + linePrefix: "@inlinable public func withTaskGroup" |
| 170 | + ) |
136 | 171 | }
|
137 | 172 |
|
138 | 173 | func testSwiftInterfaceAcrossModules() throws {
|
|
0 commit comments