forked from intitni/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnknownLanguageFocusedCodeFinderTests.swift
More file actions
100 lines (93 loc) · 4.12 KB
/
UnknownLanguageFocusedCodeFinderTests.swift
File metadata and controls
100 lines (93 loc) · 4.12 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
import XCTest
import Foundation
import FocusedCodeFinder
@testable import ActiveDocumentChatContextCollector
class UnknownLanguageFocusedCodeFinderTests: XCTestCase {
func context(code: String) -> ActiveDocumentContext {
.init(
filePath: "",
relativePath: "",
language: .builtIn(.swift),
fileContent: code,
lines: code.components(separatedBy: "\n").map { "\($0)\n" },
selectedCode: "", selectionRange: .zero,
lineAnnotations: [],
imports: []
)
}
func test_the_code_is_long_enough_for_the_search_range() {
let code = stride(from: 0, through: 100, by: 1).map { "\($0)\n" }.joined()
let context = UnknownLanguageFocusedCodeFinder(proposedSearchRange: 5)
.findFocusedCode(
containingRange: .init(startPair: (50, 0), endPair: (50, 0)),
activeDocumentContext: self.context(code: code)
)
XCTAssertEqual(context, .init(
scope: .top,
contextRange: .init(startPair: (40, 0), endPair: (60, 3)),
focusedRange: .init(startPair: (45, 0), endPair: (55, 3)),
focusedCode: stride(from: 45, through: 55, by: 1).map { "\($0)\n" }.joined(),
imports: []
))
}
func test_the_upper_side_is_not_long_enough_expand_the_lower_end() {
let code = stride(from: 0, through: 100, by: 1).map { "\($0)\n" }.joined()
let context = UnknownLanguageFocusedCodeFinder(proposedSearchRange: 5)
.findFocusedCode(
containingRange: .init(startPair: (2, 0), endPair: (2, 0)),
activeDocumentContext: self.context(code: code)
)
XCTAssertEqual(context, .init(
scope: .top,
contextRange: .init(startPair: (0, 0), endPair: (15, 3)),
focusedRange: .init(startPair: (0, 0), endPair: (10, 3)),
focusedCode: stride(from: 0, through: 10, by: 1).map { "\($0)\n" }.joined(),
imports: []
))
}
func test_the_lower_side_is_not_long_enough_do_not_expand_the_upper_end() {
let code = stride(from: 0, through: 100, by: 1).map { "\($0)\n" }.joined()
let context = UnknownLanguageFocusedCodeFinder(proposedSearchRange: 5)
.findFocusedCode(
containingRange: .init(startPair: (99, 0), endPair: (99, 0)),
activeDocumentContext: self.context(code: code)
)
XCTAssertEqual(context, .init(
scope: .top,
contextRange: .init(startPair: (89, 0), endPair: (101, 1)),
focusedRange: .init(startPair: (94, 0), endPair: (101, 1)),
focusedCode: stride(from: 94, through: 100, by: 1).map { "\($0)\n" }.joined() + "\n",
imports: []
))
}
func test_both_sides_are_just_long_enough() {
let code = stride(from: 0, through: 10, by: 1).map { "\($0)\n" }.joined()
let context = UnknownLanguageFocusedCodeFinder(proposedSearchRange: 5)
.findFocusedCode(
containingRange: .init(startPair: (5, 0), endPair: (5, 0)),
activeDocumentContext: self.context(code: code)
)
XCTAssertEqual(context, .init(
scope: .top,
contextRange: .init(startPair: (0, 0), endPair: (11, 1)),
focusedRange: .init(startPair: (0, 0), endPair: (10, 3)),
focusedCode: code,
imports: []
))
}
func test_both_sides_are_not_long_enough() {
let code = stride(from: 0, through: 4, by: 1).map { "\($0)\n" }.joined()
let context = UnknownLanguageFocusedCodeFinder(proposedSearchRange: 5)
.findFocusedCode(
containingRange: .init(startPair: (3, 0), endPair: (3, 0)),
activeDocumentContext: self.context(code: code)
)
XCTAssertEqual(context, .init(
scope: .top,
contextRange: .init(startPair: (0, 0), endPair: (5, 1)),
focusedRange: .init(startPair: (0, 0), endPair: (5, 1)),
focusedCode: code + "\n",
imports: []
))
}
}