@@ -16,191 +16,139 @@ import SKTestSupport
16
16
import XCTest
17
17
18
18
final class HoverTests : XCTestCase {
19
- func testHover( ) async throws {
19
+ func testBasic( ) async throws {
20
+ try await assertHover (
21
+ """
22
+ /// This is a doc comment for S.
23
+ ///
24
+ /// Details.
25
+ struct 1️⃣S {}
26
+ """ ,
27
+ expectedContent: """
28
+ S
29
+ ```swift
30
+ struct S
31
+ ```
32
+
33
+ ---
34
+ This is a doc comment for S.
35
+
36
+ ### Discussion
37
+
38
+ Details.
39
+ """
40
+ )
41
+ }
42
+
43
+ func testHoverTriggeredFromComment( ) async throws {
20
44
let testClient = try await TestSourceKitLSPClient ( )
21
45
let url = URL ( fileURLWithPath: " / \( UUID ( ) ) /a.swift " )
22
46
let uri = DocumentURI ( url)
23
47
24
- testClient. openDocument (
48
+ let positions = testClient. openDocument (
25
49
"""
26
- /// This is a doc comment for S.
50
+ /// Thi1️⃣s is a doc comment for S.
27
51
///
28
52
/// Details.
29
53
struct S {}
30
54
""" ,
31
55
uri: uri
32
56
)
33
57
34
- do {
35
- let resp = try await testClient. send (
36
- HoverRequest (
37
- textDocument: TextDocumentIdentifier ( url) ,
38
- position: Position ( line: 3 , utf16index: 7 )
39
- )
40
- )
41
-
42
- XCTAssertNotNil ( resp)
43
- if let hover = resp {
44
- XCTAssertNil ( hover. range)
45
- guard case . markupContent( let content) = hover. contents else {
46
- XCTFail ( " hover.contents is not .markupContents " )
47
- return
48
- }
49
- XCTAssertEqual ( content. kind, . markdown)
50
- XCTAssertEqual (
51
- content. value,
52
- """
53
- S
54
- ```swift
55
- struct S
56
- ```
57
-
58
- ---
59
- This is a doc comment for S.
60
-
61
- ### Discussion
62
-
63
- Details.
64
- """
65
- )
66
- }
67
- }
68
-
69
- do {
70
- let resp = try await testClient. send (
71
- HoverRequest (
72
- textDocument: TextDocumentIdentifier ( url) ,
73
- position: Position ( line: 0 , utf16index: 7 )
74
- )
75
- )
76
-
77
- XCTAssertNil ( resp)
78
- }
58
+ let response = try await testClient. send (
59
+ HoverRequest ( textDocument: TextDocumentIdentifier ( url) , position: positions [ " 1️⃣ " ] )
60
+ )
61
+
62
+ XCTAssertNil ( response)
79
63
}
80
64
81
65
func testMultiCursorInfoResultsHover( ) async throws {
82
- let testClient = try await TestSourceKitLSPClient ( )
83
- let uri = DocumentURI . for ( . swift)
84
-
85
- let positions = testClient. openDocument (
66
+ try await assertHover (
86
67
"""
87
68
struct Foo {
88
69
init() {}
89
70
}
90
71
_ = 1️⃣Foo()
91
72
""" ,
92
- uri: uri
93
- )
94
-
95
- let response = try await testClient. send (
96
- HoverRequest (
97
- textDocument: TextDocumentIdentifier ( uri) ,
98
- position: positions [ " 1️⃣ " ]
99
- )
100
- )
73
+ expectedContent: """
74
+ Foo
75
+ ```swift
76
+ struct Foo
77
+ ```
101
78
102
- guard case . markupContent( let content) = response? . contents else {
103
- XCTFail ( " hover.contents is not .markupContents " )
104
- return
105
- }
106
- XCTAssertEqual ( content. kind, . markdown)
107
- XCTAssertEqual (
108
- content. value,
109
- """
110
- Foo
111
- ```swift
112
- struct Foo
113
- ```
79
+ ---
114
80
115
- ---
81
+ # Alternative result
82
+ init()
83
+ ```swift
84
+ init()
85
+ ```
116
86
117
- # Alternative result
118
- init()
119
- ```swift
120
- init()
121
- ```
87
+ ---
122
88
123
- ---
89
+ """
90
+ )
91
+ }
124
92
93
+ func testHoverNameEscapingOnFunction( ) async throws {
94
+ try await assertHover (
125
95
"""
96
+ /// this is **bold** documentation
97
+ func 1️⃣test(_ a: Int, _ b: Int) { }
98
+ """ ,
99
+ expectedContent: ##"""
100
+ test(\_:\_:)
101
+ ```swift
102
+ func test(_ a: Int, _ b: Int)
103
+ ```
104
+
105
+ ---
106
+ this is **bold** documentation
107
+ """##
126
108
)
127
109
}
128
110
129
- func testHoverNameEscaping( ) async throws {
130
- let testClient = try await TestSourceKitLSPClient ( )
131
- let uri = DocumentURI . for ( . swift)
132
-
133
- testClient. openDocument (
111
+ func testHoverNameEscapingOnOperator( ) async throws {
112
+ try await assertHover (
134
113
"""
135
- /// this is **bold** documentation
136
- func test(_ a: Int, _ b: Int) { }
137
114
/// this is *italic* documentation
138
- func *%*(lhs: String, rhs: String) { }
115
+ func 1️⃣ *%*(lhs: String, rhs: String) { }
139
116
""" ,
140
- uri: uri
117
+ expectedContent: ##"""
118
+ \*%\*(\_:\_:)
119
+ ```swift
120
+ func *%* (lhs: String, rhs: String)
121
+ ```
122
+
123
+ ---
124
+ this is *italic* documentation
125
+ """##
141
126
)
127
+ }
128
+ }
142
129
143
- do {
144
- let resp = try await testClient. send (
145
- HoverRequest (
146
- textDocument: TextDocumentIdentifier ( uri) ,
147
- position: Position ( line: 1 , utf16index: 7 )
148
- )
149
- )
150
-
151
- XCTAssertNotNil ( resp)
152
- if let hover = resp {
153
- XCTAssertNil ( hover. range)
154
- guard case . markupContent( let content) = hover. contents else {
155
- XCTFail ( " hover.contents is not .markupContents " )
156
- return
157
- }
158
- XCTAssertEqual ( content. kind, . markdown)
159
- XCTAssertEqual (
160
- content. value,
161
- ##"""
162
- test(\_:\_:)
163
- ```swift
164
- func test(_ a: Int, _ b: Int)
165
- ```
166
-
167
- ---
168
- this is **bold** documentation
169
- """##
170
- )
171
- }
172
- }
173
-
174
- do {
175
- let resp = try await testClient. send (
176
- HoverRequest (
177
- textDocument: TextDocumentIdentifier ( uri) ,
178
- position: Position ( line: 3 , utf16index: 7 )
179
- )
180
- )
181
-
182
- XCTAssertNotNil ( resp)
183
- if let hover = resp {
184
- XCTAssertNil ( hover. range)
185
- guard case . markupContent( let content) = hover. contents else {
186
- XCTFail ( " hover.contents is not .markupContents " )
187
- return
188
- }
189
- XCTAssertEqual ( content. kind, . markdown)
190
- XCTAssertEqual (
191
- content. value,
192
- ##"""
193
- \*%\*(\_:\_:)
194
- ```swift
195
- func *%* (lhs: String, rhs: String)
196
- ```
197
-
198
- ---
199
- this is *italic* documentation
200
- """##
201
- )
202
- }
203
- }
130
+ private func assertHover(
131
+ _ markedSource: String ,
132
+ expectedContent: String ,
133
+ file: StaticString = #file,
134
+ line: UInt = #line
135
+ ) async throws {
136
+ let testClient = try await TestSourceKitLSPClient ( )
137
+ let uri = DocumentURI . for ( . swift)
138
+
139
+ let positions = testClient. openDocument ( markedSource, uri: uri)
140
+
141
+ let response = try await testClient. send (
142
+ HoverRequest ( textDocument: TextDocumentIdentifier ( uri) , position: positions [ " 1️⃣ " ] )
143
+ )
144
+
145
+ let hover = try XCTUnwrap ( response, file: file, line: line)
146
+ XCTAssertNil ( hover. range, file: file, line: line)
147
+ guard case . markupContent( let content) = hover. contents else {
148
+ XCTFail ( " hover.contents is not .markupContents " , file: file, line: line)
149
+ return
204
150
}
151
+ XCTAssertEqual ( content. kind, . markdown, file: file, line: line)
152
+ XCTAssertEqual ( content. value, expectedContent, file: file, line: line)
205
153
206
154
}
0 commit comments