Skip to content

Commit baafd2e

Browse files
committed
Add Some Tests
1 parent 12f92c0 commit baafd2e

File tree

2 files changed

+74
-8
lines changed

2 files changed

+74
-8
lines changed

CodeEditTests/Features/LSP/SemanticTokens/SemanticTokenMapTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import CodeEditSourceEditor
1010
import LanguageServerProtocol
1111
@testable import CodeEdit
1212

13-
final class SemanticTokenMapTestsTests: XCTestCase {
13+
final class SemanticTokenMapTests: XCTestCase {
1414
// Ignores the line parameter and just returns a range from the char and length for testing
1515
struct MockRangeProvider: SemanticTokenMapRangeProvider {
1616
func nsRangeFrom(line: UInt32, char: UInt32, length: UInt32) -> NSRange? {

CodeEditTests/Features/LSP/SemanticTokens/SemanticTokenStorageTests.swift

Lines changed: 73 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,84 @@
55
// Created by Khan Winter on 12/26/24.
66
//
77

8-
import XCTest
8+
import Foundation
9+
import Testing
910
import CodeEditSourceEditor
1011
import LanguageServerProtocol
1112
@testable import CodeEdit
1213

13-
final class SemanticTokenStorageTests: XCTestCase {
14-
func testInvalidation() {
14+
// For easier comparison while setting semantic tokens
15+
extension SemanticToken: @retroactive Equatable {
16+
public static func == (lhs: SemanticToken, rhs: SemanticToken) -> Bool {
17+
lhs.type == rhs.type
18+
&& lhs.modifiers == rhs.modifiers
19+
&& lhs.line == rhs.line
20+
&& lhs.char == rhs.char
21+
&& lhs.length == rhs.length
22+
}
23+
}
24+
25+
@Suite
26+
struct SemanticTokenStorageTests {
27+
let storage = SemanticTokenStorage()
28+
29+
let semanticTokens = [
30+
SemanticToken(line: 0, char: 0, length: 10, type: 0, modifiers: 0),
31+
SemanticToken(line: 1, char: 2, length: 5, type: 2, modifiers: 3),
32+
SemanticToken(line: 3, char: 8, length: 10, type: 1, modifiers: 0)
33+
]
34+
35+
@Test
36+
func initialState() async throws {
37+
#expect(storage.state == nil)
38+
#expect(storage.hasTokens == false)
39+
#expect(storage.lastResultId == nil)
40+
}
41+
42+
@Test
43+
func setData() async throws {
44+
storage.setData(
45+
SemanticTokens(
46+
resultId: "1234",
47+
tokens: semanticTokens
48+
)
49+
)
50+
51+
let state = try #require(storage.state)
52+
#expect(state.tokens == semanticTokens)
53+
#expect(state.resultId == "1234")
54+
55+
#expect(storage.lastResultId == "1234")
56+
#expect(storage.hasTokens == true)
57+
}
58+
59+
@Suite("ApplyDeltas")
60+
struct TokensDeltasTests {
1561
let storage = SemanticTokenStorage()
16-
storage.state = SemanticTokenStorage.CurrentState(
17-
resultId: nil,
18-
tokenData: [0, 0, 2, 0, 0],
19-
tokens: [SemanticToken(line: 0, char: 0, length: 2, type: 0, modifiers: 0)]
62+
63+
let semanticTokens = [
64+
SemanticToken(line: 0, char: 0, length: 10, type: 0, modifiers: 0),
65+
SemanticToken(line: 1, char: 2, length: 5, type: 2, modifiers: 3),
66+
SemanticToken(line: 3, char: 8, length: 10, type: 1, modifiers: 0)
67+
]
68+
69+
@Test(
70+
arguments: [
71+
#"{ "resultId": "1", "edits": [{"start": 0, "deleteCount": 0, "data": [0, 2, 3, 0, 1] }] }"#
72+
]
2073
)
74+
func applyDeltas(deltasJSON: String) async throws {
75+
// This is unfortunate, but there's no public initializer for these structs.
76+
// So we have to decode them from JSON strings
77+
let decoder = JSONDecoder()
78+
let deltas = try decoder.decode(SemanticTokensDelta.self, from: Data(deltasJSON.utf8))
79+
80+
81+
}
82+
83+
@Test
84+
func invalidatedRanges() {
85+
86+
}
2187
}
2288
}

0 commit comments

Comments
 (0)