forked from intitni/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRejectSuggestionTests.swift
More file actions
83 lines (75 loc) · 2.55 KB
/
RejectSuggestionTests.swift
File metadata and controls
83 lines (75 loc) · 2.55 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
import SuggestionModel
import XCTest
@testable import SuggestionInjector
final class RejectSuggestionTests: XCTestCase {
func test_rejecting_suggestion() async throws {
let content = """
struct Cat {
var name
/*========== Copilot Suggestion 1/10
^: String
var age: String
*///======== End of Copilot Suggestion
}
"""
var extraInfo = SuggestionInjector.ExtraInfo()
var lines = content.breakLines()
var cursor = CursorPosition(line: 1, character: 12)
SuggestionInjector().rejectCurrentSuggestions(
from: &lines,
cursorPosition: &cursor,
extraInfo: &extraInfo
)
XCTAssertTrue(extraInfo.didChangeContent)
XCTAssertFalse(extraInfo.didChangeCursorPosition)
XCTAssertNil(extraInfo.suggestionRange)
XCTAssertEqual(lines, content.breakLines().applying(extraInfo.modifications))
XCTAssertEqual(lines.joined(separator: ""), """
struct Cat {
var name
}
""")
XCTAssertEqual(
cursor,
.init(line: 1, character: 12),
"If cursor is above deletion, don't move it."
)
}
func test_broken_suggestion() async throws {
let content = """
struct Cat {
var name
/*========== Copilot Suggestion 1/10
^: String
var age: String
*///======== End of Copilot Suggestion
/*========== Copilot Suggestion 2/10
/*========== Copilot Suggestion 1/10
^: String
var age: String
*///======== End of Copilot Suggestion
"""
var extraInfo = SuggestionInjector.ExtraInfo()
var lines = content.breakLines()
var cursor = CursorPosition(line: 6, character: 0)
SuggestionInjector().rejectCurrentSuggestions(
from: &lines,
cursorPosition: &cursor,
extraInfo: &extraInfo
)
XCTAssertTrue(extraInfo.didChangeContent)
XCTAssertTrue(extraInfo.didChangeCursorPosition)
XCTAssertNil(extraInfo.suggestionRange)
XCTAssertEqual(lines, content.breakLines().applying(extraInfo.modifications))
XCTAssertEqual(lines.joined(separator: ""), """
struct Cat {
var name
/*========== Copilot Suggestion 2/10
""")
XCTAssertEqual(
cursor,
.init(line: 2, character: 0),
"If cursor is below deletion, move it up."
)
}
}