forked from intitni/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFilespaceSuggestionInvalidationTests.swift
More file actions
168 lines (155 loc) · 6.09 KB
/
FilespaceSuggestionInvalidationTests.swift
File metadata and controls
168 lines (155 loc) · 6.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import Foundation
import SuggestionModel
import XCTest
@testable import Workspace
@testable import Service
class FilespaceSuggestionInvalidationTests: XCTestCase {
@WorkspaceActor
func prepare(suggestionText: String, cursorPosition: CursorPosition) async throws -> Filespace {
let pool = WorkspacePool()
let (_, filespace) = try await pool
.fetchOrCreateWorkspaceAndFilespace(fileURL: URL(fileURLWithPath: "file/path/to.swift"))
filespace.suggestions = [
.init(
text: suggestionText,
position: cursorPosition,
uuid: "",
range: .outOfScope,
displayText: ""
),
]
return filespace
}
func test_text_typing_suggestion_should_be_valid() async throws {
let filespace = try await prepare(
suggestionText: "hello man",
cursorPosition: .init(line: 1, character: 0)
)
let isValid = await filespace.validateSuggestions(
lines: ["\n", "hell\n", "\n"],
cursorPosition: .init(line: 1, character: 4)
)
XCTAssertTrue(isValid)
let suggestion = filespace.presentingSuggestion
XCTAssertNotNil(suggestion)
}
func test_text_typing_suggestion_in_the_middle_should_be_valid() async throws {
let filespace = try await prepare(
suggestionText: "hello man",
cursorPosition: .init(line: 1, character: 0)
)
let isValid = await filespace.validateSuggestions(
lines: ["\n", "hell man\n", "\n"],
cursorPosition: .init(line: 1, character: 4)
)
XCTAssertTrue(isValid)
let suggestion = filespace.presentingSuggestion
XCTAssertNotNil(suggestion)
}
func test_text_cursor_moved_to_another_line_should_invalidate() async throws {
let filespace = try await prepare(
suggestionText: "hello man",
cursorPosition: .init(line: 1, character: 0)
)
let isValid = await filespace.validateSuggestions(
lines: ["\n", "hell\n", "\n"],
cursorPosition: .init(line: 2, character: 0)
)
XCTAssertFalse(isValid)
let suggestion = filespace.presentingSuggestion
XCTAssertNil(suggestion)
}
func test_text_cursor_is_invalid_should_invalidate() async throws {
let filespace = try await prepare(
suggestionText: "hello man",
cursorPosition: .init(line: 100, character: 0)
)
let isValid = await filespace.validateSuggestions(
lines: ["\n", "hell\n", "\n"],
cursorPosition: .init(line: 100, character: 4)
)
XCTAssertFalse(isValid)
let suggestion = filespace.presentingSuggestion
XCTAssertNil(suggestion)
}
func test_line_content_does_not_match_input_should_invalidate() async throws {
let filespace = try await prepare(
suggestionText: "hello man",
cursorPosition: .init(line: 1, character: 0)
)
let isValid = await filespace.validateSuggestions(
lines: ["\n", "helo\n", "\n"],
cursorPosition: .init(line: 1, character: 4)
)
XCTAssertFalse(isValid)
let suggestion = filespace.presentingSuggestion
XCTAssertNil(suggestion)
}
func test_line_content_does_not_match_input_should_invalidate_index_out_of_scope() async throws {
let filespace = try await prepare(
suggestionText: "hello man",
cursorPosition: .init(line: 1, character: 0)
)
let isValid = await filespace.validateSuggestions(
lines: ["\n", "helo\n", "\n"],
cursorPosition: .init(line: 1, character: 100)
)
XCTAssertFalse(isValid)
let suggestion = filespace.presentingSuggestion
XCTAssertNil(suggestion)
}
func test_finish_typing_the_whole_single_line_suggestion_should_invalidate() async throws {
let filespace = try await prepare(
suggestionText: "hello man",
cursorPosition: .init(line: 1, character: 0)
)
let isValid = await filespace.validateSuggestions(
lines: ["\n", "hello man\n", "\n"],
cursorPosition: .init(line: 1, character: 9)
)
XCTAssertFalse(isValid)
let suggestion = filespace.presentingSuggestion
XCTAssertNil(suggestion)
}
func test_finish_typing_the_whole_single_line_suggestion_suggestion_is_incomplete_should_invalidate(
) async throws {
let filespace = try await prepare(
suggestionText: "hello man",
cursorPosition: .init(line: 1, character: 0)
)
let isValid = await filespace.validateSuggestions(
lines: ["\n", "hello man!!!!!\n", "\n"],
cursorPosition: .init(line: 1, character: 9)
)
XCTAssertFalse(isValid)
let suggestion = filespace.presentingSuggestion
XCTAssertNil(suggestion)
}
func test_finish_typing_the_whole_multiple_line_suggestion_should_be_valid() async throws {
let filespace = try await prepare(
suggestionText: "hello man\nhow are you?",
cursorPosition: .init(line: 1, character: 0)
)
let isValid = await filespace.validateSuggestions(
lines: ["\n", "hello man\n", "\n"],
cursorPosition: .init(line: 1, character: 9)
)
XCTAssertTrue(isValid)
let suggestion = filespace.presentingSuggestion
XCTAssertNotNil(suggestion)
}
func test_undo_text_to_a_state_before_the_suggestion_was_generated_should_invalidate(
) async throws {
let filespace = try await prepare(
suggestionText: "hello man",
cursorPosition: .init(line: 1, character: 5) // generating man from hello
)
let isValid = await filespace.validateSuggestions(
lines: ["\n", "hell\n", "\n"],
cursorPosition: .init(line: 1, character: 4)
)
XCTAssertFalse(isValid)
let suggestion = filespace.presentingSuggestion
XCTAssertNil(suggestion)
}
}