|
5 | 5 | // Created by Khan Winter on 12/26/24.
|
6 | 6 | //
|
7 | 7 |
|
8 |
| -import XCTest |
| 8 | +import Foundation |
| 9 | +import Testing |
9 | 10 | import CodeEditSourceEditor
|
10 | 11 | import LanguageServerProtocol
|
11 | 12 | @testable import CodeEdit
|
12 | 13 |
|
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 { |
15 | 61 | 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 | + ] |
20 | 73 | )
|
| 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 | + } |
21 | 87 | }
|
22 | 88 | }
|
0 commit comments