Skip to content

Commit b4ba5f5

Browse files
use dictionary in tests rather than array
1 parent 4b9288a commit b4ba5f5

File tree

1 file changed

+92
-95
lines changed

1 file changed

+92
-95
lines changed

Tests/SourceKitLSPTests/DoccDocumentationTests.swift

Lines changed: 92 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ final class DoccDocumentationTests: XCTestCase {
2424
try await renderDocumentation(
2525
swiftFile: "0️⃣",
2626
expectedResponses: [
27-
.error(.noDocumentation)
27+
"0️⃣": .error(.noDocumentation)
2828
]
2929
)
3030
}
@@ -38,10 +38,10 @@ final class DoccDocumentationTests: XCTestCase {
3838
}3️⃣
3939
""",
4040
expectedResponses: [
41-
.renderNode(kind: .symbol, path: "test/function()"),
42-
.renderNode(kind: .symbol, path: "test/function()"),
43-
.renderNode(kind: .symbol, path: "test/function()"),
44-
.error(.noDocumentation),
41+
"0️⃣": .renderNode(kind: .symbol, path: "test/function()"),
42+
"1️⃣": .renderNode(kind: .symbol, path: "test/function()"),
43+
"2️⃣": .renderNode(kind: .symbol, path: "test/function()"),
44+
"3️⃣": .error(.noDocumentation),
4545
]
4646
)
4747
}
@@ -65,15 +65,15 @@ final class DoccDocumentationTests: XCTestCase {
6565
}8️⃣
6666
""",
6767
expectedResponses: [
68-
.renderNode(kind: .symbol, path: "test/Structure"),
69-
.renderNode(kind: .symbol, path: "test/Structure"),
70-
.renderNode(kind: .symbol, path: "test/Structure/foo"),
71-
.renderNode(kind: .symbol, path: "test/Structure/foo"),
72-
.renderNode(kind: .symbol, path: "test/Structure/bar"),
73-
.renderNode(kind: .symbol, path: "test/Structure/bar"),
74-
.renderNode(kind: .symbol, path: "test/Structure/init(_:bar:)"),
75-
.renderNode(kind: .symbol, path: "test/Structure/init(_:bar:)"),
76-
.error(.noDocumentation),
68+
"0️⃣": .renderNode(kind: .symbol, path: "test/Structure"),
69+
"1️⃣": .renderNode(kind: .symbol, path: "test/Structure"),
70+
"2️⃣": .renderNode(kind: .symbol, path: "test/Structure/foo"),
71+
"3️⃣": .renderNode(kind: .symbol, path: "test/Structure/foo"),
72+
"4️⃣": .renderNode(kind: .symbol, path: "test/Structure/bar"),
73+
"5️⃣": .renderNode(kind: .symbol, path: "test/Structure/bar"),
74+
"6️⃣": .renderNode(kind: .symbol, path: "test/Structure/init(_:bar:)"),
75+
"7️⃣": .renderNode(kind: .symbol, path: "test/Structure/init(_:bar:)"),
76+
"8️⃣": .error(.noDocumentation),
7777
]
7878
)
7979
}
@@ -86,10 +86,10 @@ final class DoccDocumentationTests: XCTestCase {
8686
}3️⃣
8787
""",
8888
expectedResponses: [
89-
.renderNode(kind: .symbol, path: "test/Structure"),
90-
.renderNode(kind: .symbol, path: "test/Structure"),
91-
.renderNode(kind: .symbol, path: "test/Structure"),
92-
.error(.noDocumentation),
89+
"0️⃣": .renderNode(kind: .symbol, path: "test/Structure"),
90+
"1️⃣": .renderNode(kind: .symbol, path: "test/Structure"),
91+
"2️⃣": .renderNode(kind: .symbol, path: "test/Structure"),
92+
"3️⃣": .error(.noDocumentation),
9393
]
9494
)
9595
}
@@ -113,16 +113,16 @@ final class DoccDocumentationTests: XCTestCase {
113113
}9️⃣
114114
""",
115115
expectedResponses: [
116-
.renderNode(kind: .symbol, path: "test/Class"),
117-
.renderNode(kind: .symbol, path: "test/Class"),
118-
.renderNode(kind: .symbol, path: "test/Class/foo"),
119-
.renderNode(kind: .symbol, path: "test/Class/foo"),
120-
.renderNode(kind: .symbol, path: "test/Class/bar"),
121-
.renderNode(kind: .symbol, path: "test/Class/bar"),
122-
.renderNode(kind: .symbol, path: "test/Class/init(_:bar:)"),
123-
.renderNode(kind: .symbol, path: "test/Class/init(_:bar:)"),
124-
.renderNode(kind: .symbol, path: "test/Class"),
125-
.error(.noDocumentation),
116+
"0️⃣": .renderNode(kind: .symbol, path: "test/Class"),
117+
"1️⃣": .renderNode(kind: .symbol, path: "test/Class"),
118+
"2️⃣": .renderNode(kind: .symbol, path: "test/Class/foo"),
119+
"3️⃣": .renderNode(kind: .symbol, path: "test/Class/foo"),
120+
"4️⃣": .renderNode(kind: .symbol, path: "test/Class/bar"),
121+
"5️⃣": .renderNode(kind: .symbol, path: "test/Class/bar"),
122+
"6️⃣": .renderNode(kind: .symbol, path: "test/Class/init(_:bar:)"),
123+
"7️⃣": .renderNode(kind: .symbol, path: "test/Class/init(_:bar:)"),
124+
"8️⃣": .renderNode(kind: .symbol, path: "test/Class"),
125+
"9️⃣": .error(.noDocumentation),
126126
]
127127
)
128128
}
@@ -135,10 +135,10 @@ final class DoccDocumentationTests: XCTestCase {
135135
}3️⃣
136136
""",
137137
expectedResponses: [
138-
.renderNode(kind: .symbol, path: "test/Class"),
139-
.renderNode(kind: .symbol, path: "test/Class"),
140-
.renderNode(kind: .symbol, path: "test/Class"),
141-
.error(.noDocumentation),
138+
"0️⃣": .renderNode(kind: .symbol, path: "test/Class"),
139+
"1️⃣": .renderNode(kind: .symbol, path: "test/Class"),
140+
"2️⃣": .renderNode(kind: .symbol, path: "test/Class"),
141+
"3️⃣": .error(.noDocumentation),
142142
]
143143
)
144144
}
@@ -162,15 +162,15 @@ final class DoccDocumentationTests: XCTestCase {
162162
}8️⃣
163163
""",
164164
expectedResponses: [
165-
.renderNode(kind: .symbol, path: "test/Actor"),
166-
.renderNode(kind: .symbol, path: "test/Actor"),
167-
.renderNode(kind: .symbol, path: "test/Actor/foo"),
168-
.renderNode(kind: .symbol, path: "test/Actor/foo"),
169-
.renderNode(kind: .symbol, path: "test/Actor/bar"),
170-
.renderNode(kind: .symbol, path: "test/Actor/bar"),
171-
.renderNode(kind: .symbol, path: "test/Actor/init(_:bar:)"),
172-
.renderNode(kind: .symbol, path: "test/Actor/init(_:bar:)"),
173-
.error(.noDocumentation),
165+
"0️⃣": .renderNode(kind: .symbol, path: "test/Actor"),
166+
"1️⃣": .renderNode(kind: .symbol, path: "test/Actor"),
167+
"2️⃣": .renderNode(kind: .symbol, path: "test/Actor/foo"),
168+
"3️⃣": .renderNode(kind: .symbol, path: "test/Actor/foo"),
169+
"4️⃣": .renderNode(kind: .symbol, path: "test/Actor/bar"),
170+
"5️⃣": .renderNode(kind: .symbol, path: "test/Actor/bar"),
171+
"6️⃣": .renderNode(kind: .symbol, path: "test/Actor/init(_:bar:)"),
172+
"7️⃣": .renderNode(kind: .symbol, path: "test/Actor/init(_:bar:)"),
173+
"8️⃣": .error(.noDocumentation),
174174
]
175175
)
176176
}
@@ -183,10 +183,10 @@ final class DoccDocumentationTests: XCTestCase {
183183
}3️⃣
184184
""",
185185
expectedResponses: [
186-
.renderNode(kind: .symbol, path: "test/Actor"),
187-
.renderNode(kind: .symbol, path: "test/Actor"),
188-
.renderNode(kind: .symbol, path: "test/Actor"),
189-
.error(.noDocumentation),
186+
"0️⃣": .renderNode(kind: .symbol, path: "test/Actor"),
187+
"1️⃣": .renderNode(kind: .symbol, path: "test/Actor"),
188+
"2️⃣": .renderNode(kind: .symbol, path: "test/Actor"),
189+
"3️⃣": .error(.noDocumentation),
190190
]
191191
)
192192
}
@@ -207,15 +207,15 @@ final class DoccDocumentationTests: XCTestCase {
207207
}8️⃣
208208
""",
209209
expectedResponses: [
210-
.renderNode(kind: .symbol, path: "test/Enum"),
211-
.renderNode(kind: .symbol, path: "test/Enum"),
212-
.renderNode(kind: .symbol, path: "test/Enum/first"),
213-
.renderNode(kind: .symbol, path: "test/Enum/first"),
214-
.renderNode(kind: .symbol, path: "test/Enum/second"),
215-
.renderNode(kind: .symbol, path: "test/Enum/second"),
216-
.renderNode(kind: .symbol, path: "test/Enum/third(_:)"),
217-
.renderNode(kind: .symbol, path: "test/Enum/third(_:)"),
218-
.error(.noDocumentation),
210+
"0️⃣": .renderNode(kind: .symbol, path: "test/Enum"),
211+
"1️⃣": .renderNode(kind: .symbol, path: "test/Enum"),
212+
"2️⃣": .renderNode(kind: .symbol, path: "test/Enum/first"),
213+
"3️⃣": .renderNode(kind: .symbol, path: "test/Enum/first"),
214+
"4️⃣": .renderNode(kind: .symbol, path: "test/Enum/second"),
215+
"5️⃣": .renderNode(kind: .symbol, path: "test/Enum/second"),
216+
"6️⃣": .renderNode(kind: .symbol, path: "test/Enum/third(_:)"),
217+
"7️⃣": .renderNode(kind: .symbol, path: "test/Enum/third(_:)"),
218+
"8️⃣": .error(.noDocumentation),
219219
]
220220
)
221221
}
@@ -245,7 +245,7 @@ final class DoccDocumentationTests: XCTestCase {
245245
testClient: testClient,
246246
uri: uri,
247247
positions: positions,
248-
expectedResponses: [.renderNode(kind: .symbol, containing: "The second case")]
248+
expectedResponses: ["0️⃣": .renderNode(kind: .symbol, containing: "The second case")]
249249
)
250250

251251
// Change the content of the documentation comment
@@ -263,7 +263,7 @@ final class DoccDocumentationTests: XCTestCase {
263263
testClient: testClient,
264264
uri: uri,
265265
positions: positions,
266-
expectedResponses: [.renderNode(kind: .symbol, containing: "The very second case")]
266+
expectedResponses: ["0️⃣": .renderNode(kind: .symbol, containing: "The very second case")]
267267
)
268268
}
269269

@@ -280,13 +280,13 @@ final class DoccDocumentationTests: XCTestCase {
280280
}6️⃣
281281
""",
282282
expectedResponses: [
283-
.renderNode(kind: .symbol, path: "test/Protocol"),
284-
.renderNode(kind: .symbol, path: "test/Protocol"),
285-
.renderNode(kind: .symbol, path: "test/Protocol/foo"),
286-
.renderNode(kind: .symbol, path: "test/Protocol/foo"),
287-
.renderNode(kind: .symbol, path: "test/Protocol/bar"),
288-
.renderNode(kind: .symbol, path: "test/Protocol/bar"),
289-
.error(.noDocumentation),
283+
"0️⃣": .renderNode(kind: .symbol, path: "test/Protocol"),
284+
"1️⃣": .renderNode(kind: .symbol, path: "test/Protocol"),
285+
"2️⃣": .renderNode(kind: .symbol, path: "test/Protocol/foo"),
286+
"3️⃣": .renderNode(kind: .symbol, path: "test/Protocol/foo"),
287+
"4️⃣": .renderNode(kind: .symbol, path: "test/Protocol/bar"),
288+
"5️⃣": .renderNode(kind: .symbol, path: "test/Protocol/bar"),
289+
"6️⃣": .error(.noDocumentation),
290290
]
291291
)
292292
}
@@ -300,10 +300,10 @@ final class DoccDocumentationTests: XCTestCase {
300300
}3️⃣
301301
""",
302302
expectedResponses: [
303-
.renderNode(kind: .symbol, path: "test/Protocol"),
304-
.renderNode(kind: .symbol, path: "test/Protocol"),
305-
.renderNode(kind: .symbol, path: "test/Protocol"),
306-
.error(.noDocumentation),
303+
"0️⃣": .renderNode(kind: .symbol, path: "test/Protocol"),
304+
"1️⃣": .renderNode(kind: .symbol, path: "test/Protocol"),
305+
"2️⃣": .renderNode(kind: .symbol, path: "test/Protocol"),
306+
"3️⃣": .error(.noDocumentation),
307307
]
308308
)
309309
}
@@ -330,12 +330,12 @@ final class DoccDocumentationTests: XCTestCase {
330330
}5️⃣
331331
""",
332332
expectedResponses: [
333-
.error(.noDocumentation),
334-
.renderNode(kind: .symbol, path: "test/Structure/numberPlusOne"),
335-
.renderNode(kind: .symbol, path: "test/Structure/Kind"),
336-
.renderNode(kind: .symbol, path: "test/Structure/Kind/first"),
337-
.renderNode(kind: .symbol, path: "test/Structure/Kind/second"),
338-
.error(.noDocumentation),
333+
"0️⃣": .error(.noDocumentation),
334+
"1️⃣": .renderNode(kind: .symbol, path: "test/Structure/numberPlusOne"),
335+
"2️⃣": .renderNode(kind: .symbol, path: "test/Structure/Kind"),
336+
"3️⃣": .renderNode(kind: .symbol, path: "test/Structure/Kind/first"),
337+
"4️⃣": .renderNode(kind: .symbol, path: "test/Structure/Kind/second"),
338+
"5️⃣": .error(.noDocumentation),
339339
]
340340
)
341341
}
@@ -358,7 +358,7 @@ final class DoccDocumentationTests: XCTestCase {
358358
testClient: testClient,
359359
uri: uri,
360360
positions: positions,
361-
expectedResponses: [.renderNode(kind: .symbol, containing: "A structure containing important information")]
361+
expectedResponses: ["0️⃣": .renderNode(kind: .symbol, containing: "A structure containing important information")]
362362
)
363363

364364
// Change the content of the documentation comment
@@ -376,7 +376,9 @@ final class DoccDocumentationTests: XCTestCase {
376376
testClient: testClient,
377377
uri: uri,
378378
positions: positions,
379-
expectedResponses: [.renderNode(kind: .symbol, containing: "A structure containing very important information")]
379+
expectedResponses: [
380+
"0️⃣": .renderNode(kind: .symbol, containing: "A structure containing very important information")
381+
]
380382
)
381383
}
382384

@@ -400,7 +402,7 @@ final class DoccDocumentationTests: XCTestCase {
400402
testClient: testClient,
401403
uri: uri,
402404
positions: positions,
403-
expectedResponses: [.renderNode(kind: .symbol, containing: "This is a description")]
405+
expectedResponses: ["0️⃣": .renderNode(kind: .symbol, containing: "This is a description")]
404406
)
405407

406408
// Change the content of the documentation comment
@@ -418,7 +420,7 @@ final class DoccDocumentationTests: XCTestCase {
418420
testClient: testClient,
419421
uri: uri,
420422
positions: positions,
421-
expectedResponses: [.renderNode(kind: .symbol, containing: "This is an amazing description")]
423+
expectedResponses: ["0️⃣": .renderNode(kind: .symbol, containing: "This is an amazing description")]
422424
)
423425
}
424426

@@ -444,7 +446,7 @@ final class DoccDocumentationTests: XCTestCase {
444446
testClient: testClient,
445447
uri: uri,
446448
positions: positions,
447-
expectedResponses: [.renderNode(kind: .symbol, containing: "This is a description")]
449+
expectedResponses: ["0️⃣": .renderNode(kind: .symbol, containing: "This is a description")]
448450
)
449451

450452
// Change the content of the documentation comment
@@ -462,7 +464,7 @@ final class DoccDocumentationTests: XCTestCase {
462464
testClient: testClient,
463465
uri: uri,
464466
positions: positions,
465-
expectedResponses: [.renderNode(kind: .symbol, containing: "This is an amazing description")]
467+
expectedResponses: ["0️⃣": .renderNode(kind: .symbol, containing: "This is an amazing description")]
466468
)
467469
}
468470
}
@@ -474,7 +476,7 @@ fileprivate enum PartialConvertResponse {
474476

475477
fileprivate func renderDocumentation(
476478
swiftFile markedText: String,
477-
expectedResponses: [PartialConvertResponse],
479+
expectedResponses: [String: PartialConvertResponse],
478480
file: StaticString = #filePath,
479481
line: UInt = #line
480482
) async throws {
@@ -496,27 +498,22 @@ fileprivate func renderDocumentation(
496498
testClient: TestSourceKitLSPClient,
497499
uri: DocumentURI,
498500
positions: DocumentPositions,
499-
expectedResponses: [PartialConvertResponse],
501+
expectedResponses: [String: PartialConvertResponse],
500502
file: StaticString = #filePath,
501503
line: UInt = #line
502504
) async {
503-
guard expectedResponses.count == positions.allMarkers.count else {
504-
XCTFail(
505-
"the number of expected responses did not match the number of positions in the text document",
506-
file: file,
507-
line: line
508-
)
509-
return
510-
}
511-
512-
for (index, marker) in positions.allMarkers.enumerated() {
513-
let response = await testClient.sendWithRawResponse(
505+
for marker in positions.allMarkers {
506+
guard let expectedResponse = expectedResponses[marker] else {
507+
XCTFail("No expected response was given for marker \(marker)", file: file, line: line)
508+
return
509+
}
510+
let actualResponse = await testClient.sendWithRawResponse(
514511
DoccDocumentationRequest(
515512
textDocument: TextDocumentIdentifier(uri),
516513
position: positions[marker]
517514
)
518515
)
519-
switch response {
516+
switch actualResponse {
520517
case .success(let response):
521518
let renderNodeString = response.renderNode
522519
guard let renderNodeData = renderNodeString.data(using: .utf8),
@@ -525,7 +522,7 @@ fileprivate func renderDocumentation(
525522
XCTFail("failed to decode response from textDocument/doccDocumentation at position \(marker)")
526523
return
527524
}
528-
switch expectedResponses[index] {
525+
switch expectedResponse {
529526
case .renderNode(let expectedKind, let expectedPath, let expectedContents):
530527
XCTAssertEqual(
531528
renderNode.kind,
@@ -559,7 +556,7 @@ fileprivate func renderDocumentation(
559556
)
560557
}
561558
case .failure(let error):
562-
switch expectedResponses[index] {
559+
switch expectedResponse {
563560
case .renderNode:
564561
XCTFail(
565562
"textDocument/doccDocumentation failed at position \(marker): \(error.localizedDescription)",

0 commit comments

Comments
 (0)