Skip to content

Commit 29afe7e

Browse files
committed
Update tests
1 parent 824ad01 commit 29afe7e

File tree

2 files changed

+31
-43
lines changed

2 files changed

+31
-43
lines changed
Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,15 @@
11
import AppKit
22
import Client
3-
import SuggestionModel
4-
import GitHubCopilotService
53
import Environment
64
import Foundation
5+
import GitHubCopilotService
6+
import SuggestionModel
7+
import Workspace
78
import XCTest
89
import XPCShared
910

1011
@testable import Service
1112

12-
@ServiceActor func clearEnvironment() {
13-
workspaces = [:]
14-
15-
Environment.now = { Date() }
16-
17-
Environment.fetchCurrentProjectRootURLFromXcode = {
18-
URL(fileURLWithPath: "/path/to/project")
19-
}
20-
21-
Environment.fetchCurrentFileURL = {
22-
URL(fileURLWithPath: "/path/to/project/file.swift")
23-
}
24-
25-
Environment.triggerAction = { _ in }
26-
27-
Environment.guessProjectRootURLForFile = { $0 }
28-
}
29-
3013
func completion(text: String, range: CursorRange, uuid: String = "") -> CodeSuggestion {
3114
.init(text: text, position: range.start, uuid: uuid, range: range, displayText: text)
3215
}
@@ -35,27 +18,27 @@ class MockSuggestionService: GitHubCopilotSuggestionServiceType {
3518
func terminate() async {
3619
fatalError()
3720
}
38-
21+
3922
func cancelRequest() async {
4023
fatalError()
4124
}
42-
25+
4326
func notifyOpenTextDocument(fileURL: URL, content: String) async throws {
4427
fatalError()
4528
}
46-
29+
4730
func notifyChangeTextDocument(fileURL: URL, content: String) async throws {
4831
fatalError()
4932
}
50-
33+
5134
func notifyCloseTextDocument(fileURL: URL) async throws {
5235
fatalError()
5336
}
54-
37+
5538
func notifySaveTextDocument(fileURL: URL) async throws {
5639
fatalError()
5740
}
58-
41+
5942
var completions = [CodeSuggestion]()
6043
var accepted: String?
6144
var rejected: [String] = []
@@ -85,3 +68,4 @@ class MockSuggestionService: GitHubCopilotSuggestionServiceType {
8568
rejected = completions.map(\.uuid)
8669
}
8770
}
71+

Core/Tests/ServiceTests/FilespaceSuggestionInvalidationTests.swift

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
11
import Foundation
2-
import XCTest
32
import SuggestionModel
3+
import Workspace
4+
import XCTest
45

56
@testable import Service
67

78
class FilespaceSuggestionInvalidationTests: XCTestCase {
8-
@ServiceActor
9+
@WorkspaceActor
910
func prepare(suggestionText: String, cursorPosition: CursorPosition) async throws -> Filespace {
10-
let (_, filespace) = try await Workspace
11-
.fetchOrCreateWorkspaceIfNeeded(fileURL: URL(fileURLWithPath: "file/path/to.swift"))
11+
let pool = WorkspacePool()
12+
let (_, filespace) = try await pool
13+
.fetchOrCreateWorkspaceAndFilespace(fileURL: URL(fileURLWithPath: "file/path/to.swift"))
1214
filespace.suggestions = [
1315
.init(
1416
text: suggestionText,
1517
position: cursorPosition,
1618
uuid: "",
1719
range: .outOfScope,
1820
displayText: ""
19-
)
21+
),
2022
]
2123
return filespace
2224
}
23-
25+
2426
func test_text_typing_suggestion_should_be_valid() async throws {
2527
let filespace = try await prepare(
2628
suggestionText: "hello man",
@@ -34,7 +36,7 @@ class FilespaceSuggestionInvalidationTests: XCTestCase {
3436
let suggestion = await filespace.presentingSuggestion
3537
XCTAssertNotNil(suggestion)
3638
}
37-
39+
3840
func test_text_typing_suggestion_in_the_middle_should_be_valid() async throws {
3941
let filespace = try await prepare(
4042
suggestionText: "hello man",
@@ -48,7 +50,7 @@ class FilespaceSuggestionInvalidationTests: XCTestCase {
4850
let suggestion = await filespace.presentingSuggestion
4951
XCTAssertNotNil(suggestion)
5052
}
51-
53+
5254
func test_text_cursor_moved_to_another_line_should_invalidate() async throws {
5355
let filespace = try await prepare(
5456
suggestionText: "hello man",
@@ -62,7 +64,7 @@ class FilespaceSuggestionInvalidationTests: XCTestCase {
6264
let suggestion = await filespace.presentingSuggestion
6365
XCTAssertNil(suggestion)
6466
}
65-
67+
6668
func test_text_cursor_is_invalid_should_invalidate() async throws {
6769
let filespace = try await prepare(
6870
suggestionText: "hello man",
@@ -76,7 +78,7 @@ class FilespaceSuggestionInvalidationTests: XCTestCase {
7678
let suggestion = await filespace.presentingSuggestion
7779
XCTAssertNil(suggestion)
7880
}
79-
81+
8082
func test_line_content_does_not_match_input_should_invalidate() async throws {
8183
let filespace = try await prepare(
8284
suggestionText: "hello man",
@@ -90,7 +92,7 @@ class FilespaceSuggestionInvalidationTests: XCTestCase {
9092
let suggestion = await filespace.presentingSuggestion
9193
XCTAssertNil(suggestion)
9294
}
93-
95+
9496
func test_line_content_does_not_match_input_should_invalidate_index_out_of_scope() async throws {
9597
let filespace = try await prepare(
9698
suggestionText: "hello man",
@@ -104,7 +106,7 @@ class FilespaceSuggestionInvalidationTests: XCTestCase {
104106
let suggestion = await filespace.presentingSuggestion
105107
XCTAssertNil(suggestion)
106108
}
107-
109+
108110
func test_finish_typing_the_whole_single_line_suggestion_should_invalidate() async throws {
109111
let filespace = try await prepare(
110112
suggestionText: "hello man",
@@ -118,8 +120,9 @@ class FilespaceSuggestionInvalidationTests: XCTestCase {
118120
let suggestion = await filespace.presentingSuggestion
119121
XCTAssertNil(suggestion)
120122
}
121-
122-
func test_finish_typing_the_whole_single_line_suggestion_suggestion_is_incomplete_should_invalidate() async throws {
123+
124+
func test_finish_typing_the_whole_single_line_suggestion_suggestion_is_incomplete_should_invalidate(
125+
) async throws {
123126
let filespace = try await prepare(
124127
suggestionText: "hello man",
125128
cursorPosition: .init(line: 1, character: 0)
@@ -132,7 +135,7 @@ class FilespaceSuggestionInvalidationTests: XCTestCase {
132135
let suggestion = await filespace.presentingSuggestion
133136
XCTAssertNil(suggestion)
134137
}
135-
138+
136139
func test_finish_typing_the_whole_multiple_line_suggestion_should_be_valid() async throws {
137140
let filespace = try await prepare(
138141
suggestionText: "hello man\nhow are you?",
@@ -146,8 +149,9 @@ class FilespaceSuggestionInvalidationTests: XCTestCase {
146149
let suggestion = await filespace.presentingSuggestion
147150
XCTAssertNotNil(suggestion)
148151
}
149-
150-
func test_undo_text_to_a_state_before_the_suggestion_was_generated_should_invalidate() async throws {
152+
153+
func test_undo_text_to_a_state_before_the_suggestion_was_generated_should_invalidate(
154+
) async throws {
151155
let filespace = try await prepare(
152156
suggestionText: "hello man",
153157
cursorPosition: .init(line: 1, character: 5) // generating man from hello

0 commit comments

Comments
 (0)