4
4
"context"
5
5
"io"
6
6
"os"
7
+
"path/filepath"
7
8
"testing"
8
9
9
10
"github.com/grafana/jsonnet-language-server/pkg/stdlib"
66
67
}
67
68
)
68
69
69
-
func TestHover(t *testing.T) {
70
+
func TestHoverOnStdLib(t *testing.T) {
70
71
logrus.SetOutput(io.Discard)
71
72
72
73
var testCases = []struct {
@@ -241,3 +242,94 @@ func TestHover(t *testing.T) {
241
242
})
242
243
}
243
244
}
245
+
246
+
func TestHover(t *testing.T) {
247
+
logrus.SetOutput(io.Discard)
248
+
249
+
testCases := []struct {
250
+
name string
251
+
filename string
252
+
position protocol.Position
253
+
expectedContent protocol.Hover
254
+
}{
255
+
{
256
+
name: "hover on nested attribute",
257
+
filename: "testdata/goto-indexes.jsonnet",
258
+
position: protocol.Position{Line: 9, Character: 16},
259
+
expectedContent: protocol.Hover{
260
+
Contents: protocol.MarkupContent{
261
+
Kind: protocol.Markdown,
262
+
Value: "```jsonnet\nbar: 'innerfoo',\n```\n",
263
+
},
264
+
Range: protocol.Range{
265
+
Start: protocol.Position{Line: 9, Character: 5},
266
+
End: protocol.Position{Line: 9, Character: 18},
267
+
},
268
+
},
269
+
},
270
+
{
271
+
name: "hover on multi-line string",
272
+
filename: "testdata/goto-indexes.jsonnet",
273
+
position: protocol.Position{Line: 8, Character: 9},
274
+
expectedContent: protocol.Hover{
275
+
Contents: protocol.MarkupContent{
276
+
Kind: protocol.Markdown,
277
+
Value: "```jsonnet\nobj = {\n foo: {\n bar: 'innerfoo',\n },\n bar: 'foo',\n}\n```\n",
278
+
},
279
+
Range: protocol.Range{
280
+
Start: protocol.Position{Line: 8, Character: 8},
281
+
End: protocol.Position{Line: 8, Character: 11},
282
+
},
283
+
},
284
+
},
285
+
}
286
+
287
+
for _, tc := range testCases {
288
+
t.Run(tc.name, func(t *testing.T) {
289
+
params := &protocol.HoverParams{
290
+
TextDocumentPositionParams: protocol.TextDocumentPositionParams{
291
+
TextDocument: protocol.TextDocumentIdentifier{
292
+
URI: protocol.URIFromPath(tc.filename),
293
+
},
294
+
Position: tc.position,
295
+
},
296
+
}
297
+
298
+
server := NewServer("any", "test version", nil, Configuration{
299
+
JPaths: []string{"testdata", filepath.Join(filepath.Dir(tc.filename), "vendor")},
300
+
})
301
+
serverOpenTestFile(t, server, tc.filename)
302
+
response, err := server.Hover(context.Background(), params)
303
+
304
+
require.NoError(t, err)
305
+
assert.Equal(t, &tc.expectedContent, response)
306
+
})
307
+
}
308
+
}
309
+
310
+
func TestHoverGoToDefinitionTests(t *testing.T) {
311
+
logrus.SetOutput(io.Discard)
312
+
313
+
for _, tc := range definitionTestCases {
314
+
t.Run(tc.name, func(t *testing.T) {
315
+
params := &protocol.HoverParams{
316
+
TextDocumentPositionParams: protocol.TextDocumentPositionParams{
317
+
TextDocument: protocol.TextDocumentIdentifier{
318
+
URI: protocol.URIFromPath(tc.filename),
319
+
},
320
+
Position: tc.position,
321
+
},
322
+
}
323
+
324
+
server := NewServer("any", "test version", nil, Configuration{
325
+
JPaths: []string{"testdata", filepath.Join(filepath.Dir(tc.filename), "vendor")},
326
+
})
327
+
serverOpenTestFile(t, server, tc.filename)
328
+
response, err := server.Hover(context.Background(), params)
329
+
330
+
// We only want to check that it found something. In combination with other tests, we can assume the content is OK.
331
+
require.NoError(t, err)
332
+
require.NotNil(t, response)
333
+
})
334
+
}
335
+
}
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4