forked from github/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSourceEditorCacheTests.swift
More file actions
45 lines (35 loc) · 1.34 KB
/
SourceEditorCacheTests.swift
File metadata and controls
45 lines (35 loc) · 1.34 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
import Foundation
import XCTest
@testable import XcodeInspector
class SourceEditorCacheTests: XCTestCase {
func test_source_editor_cache_get_content_thread_safe() {
func randomContent() -> String {
String(repeating: """
struct Cat: Animal {
var name: String
}
""", count: Int.random(in: 2...10))
}
func randomSelectionRange() -> ClosedRange<Int> {
let random = Int.random(in: 0...20)
return random...random
}
let cache = SourceEditor.Cache()
let max = 5000
let exp = expectation(description: "test_source_editor_cache_get_content_thread_safe")
DispatchQueue.concurrentPerform(iterations: max) { count in
let content = randomContent()
let selectionRange = randomSelectionRange()
let result = cache.get(content: content, selectedTextRange: selectionRange)
XCTAssertEqual(result.lines, content.breakLines(appendLineBreakToLastLine: false))
XCTAssertEqual(result.selections, [SourceEditor.convertRangeToCursorRange(
selectionRange,
in: result.lines
)])
if max == count + 1 {
exp.fulfill()
}
}
wait(for: [exp], timeout: 10)
}
}