Skip to content

Commit ead2e73

Browse files
committed
Apply stylistic suggestions regarding semantic token tests
- Update expectaction handling in SemanticTokensTests - Use different variable/number lengths in ranged token test - Move up SemanticTokensTests.testIntArrayCoding
1 parent 09b66ee commit ead2e73

File tree

1 file changed

+28
-31
lines changed

1 file changed

+28
-31
lines changed

Tests/SourceKitLSPTests/SemanticTokensTests.swift

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ final class SemanticTokensTests: XCTestCase {
5454

5555
// We wait for the first refresh request to make sure that the semantic tokens are ready
5656

57-
let expectation = XCTestExpectation(description: "performSemanticTokensRequest - refresh received")
57+
let refreshExpectation = expectation(description: "performSemanticTokensRequest - refresh received")
5858
sk.handleNextRequest { (req: Request<WorkspaceSemanticTokensRefreshRequest>) in
59-
expectation.fulfill()
59+
refreshExpectation.fulfill()
6060
req.reply(VoidResponse())
6161
}
6262

@@ -67,10 +67,7 @@ final class SemanticTokensTests: XCTestCase {
6767
text: text
6868
)))
6969

70-
let waitResult = XCTWaiter.wait(for: [expectation], timeout: 15)
71-
if waitResult != .completed {
72-
fatalError("error \(waitResult) while waiting for semantic token refresh")
73-
}
70+
wait(for: [refreshExpectation], timeout: 15)
7471

7572
let textDocument = TextDocumentIdentifier(url)
7673
let response: DocumentSemanticTokensResponse!
@@ -84,31 +81,6 @@ final class SemanticTokensTests: XCTestCase {
8481
return [SyntaxHighlightingToken](lspEncodedTokens: response.data)
8582
}
8683

87-
func testEmpty() {
88-
let text = ""
89-
let tokens = performSemanticTokensRequest(text: text)
90-
XCTAssertEqual(tokens, [])
91-
}
92-
93-
func testRanged() {
94-
let text = """
95-
let x = 1
96-
let y = 2
97-
let z = 3
98-
let w = 4
99-
"""
100-
let start = Position(line: 1, utf16index: 0)
101-
let end = Position(line: 2, utf16index: 5)
102-
let tokens = performSemanticTokensRequest(text: text, range: start..<end)
103-
XCTAssertEqual(tokens, [
104-
SyntaxHighlightingToken(start: Position(line: 1, utf16index: 0), length: 3, kind: .keyword),
105-
SyntaxHighlightingToken(start: Position(line: 1, utf16index: 4), length: 1, kind: .variable, modifiers: .declaration),
106-
SyntaxHighlightingToken(start: Position(line: 1, utf16index: 8), length: 1, kind: .number),
107-
SyntaxHighlightingToken(start: Position(line: 2, utf16index: 0), length: 3, kind: .keyword),
108-
SyntaxHighlightingToken(start: Position(line: 2, utf16index: 4), length: 1, kind: .variable, modifiers: .declaration),
109-
])
110-
}
111-
11284
func testIntArrayCoding() {
11385
let tokens = [
11486
SyntaxHighlightingToken(
@@ -143,6 +115,31 @@ final class SemanticTokensTests: XCTestCase {
143115
XCTAssertEqual(decoded, tokens)
144116
}
145117

118+
func testEmpty() {
119+
let text = ""
120+
let tokens = performSemanticTokensRequest(text: text)
121+
XCTAssertEqual(tokens, [])
122+
}
123+
124+
func testRanged() {
125+
let text = """
126+
let x = 1
127+
let test = 20
128+
let abc = 333
129+
let y = 4
130+
"""
131+
let start = Position(line: 1, utf16index: 0)
132+
let end = Position(line: 2, utf16index: 5)
133+
let tokens = performSemanticTokensRequest(text: text, range: start..<end)
134+
XCTAssertEqual(tokens, [
135+
SyntaxHighlightingToken(start: Position(line: 1, utf16index: 0), length: 3, kind: .keyword),
136+
SyntaxHighlightingToken(start: Position(line: 1, utf16index: 4), length: 4, kind: .variable, modifiers: .declaration),
137+
SyntaxHighlightingToken(start: Position(line: 1, utf16index: 11), length: 2, kind: .number),
138+
SyntaxHighlightingToken(start: Position(line: 2, utf16index: 0), length: 3, kind: .keyword),
139+
SyntaxHighlightingToken(start: Position(line: 2, utf16index: 4), length: 3, kind: .variable, modifiers: .declaration),
140+
])
141+
}
142+
146143
func testSyntacticTokens() {
147144
let text = """
148145
let x = 3

0 commit comments

Comments
 (0)