1+ import CopilotForXcodeKit
12import LanguageServerProtocol
23import XCTest
34
45@testable import GitHubCopilotService
56
7+ struct TestServiceLocator : ServiceLocatorType {
8+ let server : GitHubCopilotLSP
9+ func getService( from workspace: WorkspaceInfo ) async -> GitHubCopilotService ? {
10+ . init( designatedServer: server)
11+ }
12+ }
13+
614final class FetchSuggestionTests : XCTestCase {
715 func test_process_suggestions_from_server( ) async throws {
816 struct TestServer : GitHubCopilotLSP {
917 func sendNotification( _: LanguageServerProtocol . ClientNotification ) async throws {
10- fatalError ( )
18+ throw CancellationError ( )
1119 }
1220
1321 func sendRequest< E> ( _: E ) async throws -> E . Response where E: GitHubCopilotRequestType {
14- return GitHubCopilotRequest . GetCompletionsCycling . Response ( completions : [
22+ return GitHubCopilotRequest . InlineCompletion . Response ( items : [
1523 . init(
16- text: " Hello World \n " ,
17- position: . init( ( 0 , 0 ) ) ,
18- uuid: " uuid " ,
24+ insertText: " Hello World \n " ,
25+ filterText: nil ,
1926 range: . init( start: . init( ( 0 , 0 ) ) , end: . init( ( 0 , 4 ) ) ) ,
20- displayText : " "
27+ command : nil
2128 ) ,
2229 . init(
23- text: " " ,
24- position: . init( ( 0 , 0 ) ) ,
25- uuid: " uuid " ,
30+ insertText: " " ,
31+ filterText: nil ,
2632 range: . init( start: . init( ( 0 , 0 ) ) , end: . init( ( 0 , 1 ) ) ) ,
27- displayText : " "
33+ command : nil
2834 ) ,
2935 . init(
30- text: " \n " ,
31- position: . init( ( 0 , 0 ) ) ,
32- uuid: " uuid " ,
36+ insertText: " \n " ,
37+ filterText: nil ,
3338 range: . init( start: . init( ( 0 , 0 ) ) , end: . init( ( 0 , 2 ) ) ) ,
34- displayText : " "
39+ command : nil
3540 ) ,
3641 ] ) as! E . Response
3742 }
3843 }
39- let service = GitHubCopilotSuggestionService ( designatedServer: TestServer ( ) )
40- let completions = try await service. getCompletions (
41- fileURL: . init( fileURLWithPath: " /file.swift " ) ,
42- content: " " ,
43- cursorPosition: . outOfScope,
44- tabSize: 4 ,
45- indentSize: 4 ,
46- usesTabsForIndentation: false
44+ let service =
45+ GitHubCopilotSuggestionService ( serviceLocator: TestServiceLocator ( server: TestServer ( ) ) )
46+ let completions = try await service. getSuggestions (
47+ . init(
48+ fileURL: . init( fileURLWithPath: " /file.swift " ) ,
49+ relativePath: " " ,
50+ language: . builtIn( . swift) ,
51+ content: " " ,
52+ originalContent: " " ,
53+ cursorPosition: . outOfScope,
54+ tabSize: 4 ,
55+ indentSize: 4 ,
56+ usesTabsForIndentation: false ,
57+ relevantCodeSnippets: [ ]
58+ ) ,
59+ workspace: . init(
60+ workspaceURL: . init( fileURLWithPath: " / " ) ,
61+ projectURL: . init( fileURLWithPath: " /file.swift " )
62+ )
4763 )
4864 XCTAssertEqual ( completions. count, 3 )
4965 }
@@ -55,26 +71,36 @@ final class FetchSuggestionTests: XCTestCase {
5571 }
5672
5773 func sendRequest< E> ( _: E ) async throws -> E . Response where E: GitHubCopilotRequestType {
58- return GitHubCopilotRequest . GetCompletionsCycling . Response ( completions : [
74+ return GitHubCopilotRequest . InlineCompletion . Response ( items : [
5975 . init(
60- text: " Hello World \n " ,
61- position: . init( ( 0 , 0 ) ) ,
62- uuid: " uuid " ,
76+ insertText: " Hello World \n " ,
77+ filterText: nil ,
6378 range: . init( start: . init( ( 0 , 0 ) ) , end: . init( ( 0 , 4 ) ) ) ,
64- displayText : " "
79+ command : nil
6580 ) ,
6681 ] ) as! E . Response
6782 }
6883 }
6984 let testServer = TestServer ( )
70- let service = GitHubCopilotSuggestionService ( designatedServer: testServer)
71- let completions = try await service. getCompletions (
72- fileURL: . init( fileURLWithPath: " / " ) ,
73- content: " " ,
74- cursorPosition: . outOfScope,
75- tabSize: 4 ,
76- indentSize: 4 ,
77- usesTabsForIndentation: false
85+ let service =
86+ GitHubCopilotSuggestionService ( serviceLocator: TestServiceLocator ( server: testServer) )
87+ let completions = try await service. getSuggestions (
88+ . init(
89+ fileURL: . init( fileURLWithPath: " / " ) ,
90+ relativePath: " " ,
91+ language: . builtIn( . swift) ,
92+ content: " " ,
93+ originalContent: " " ,
94+ cursorPosition: . outOfScope,
95+ tabSize: 4 ,
96+ indentSize: 4 ,
97+ usesTabsForIndentation: false ,
98+ relevantCodeSnippets: [ ]
99+ ) ,
100+ workspace: . init(
101+ workspaceURL: . init( fileURLWithPath: " / " ) ,
102+ projectURL: . init( fileURLWithPath: " /file.swift " )
103+ )
78104 )
79105 XCTAssertEqual ( completions. count, 1 )
80106 XCTAssertEqual ( completions. first? . text, " Hello World \n " )
0 commit comments