-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdocumentSymbol_test.go
66 lines (57 loc) · 1.9 KB
/
documentSymbol_test.go
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
package server_test
import (
"bytes"
"context"
"os"
"testing"
"github.com/docker/docker-language-server/internal/tliron/glsp/protocol"
"github.com/sourcegraph/jsonrpc2"
"github.com/stretchr/testify/require"
)
func TestDocumentSymbol(t *testing.T) {
s := startServer()
client := bytes.NewBuffer(make([]byte, 0, 1024))
server := bytes.NewBuffer(make([]byte, 0, 1024))
serverStream := &TestStream{incoming: server, outgoing: client, closed: false}
defer serverStream.Close()
go s.ServeStream(serverStream)
clientStream := jsonrpc2.NewBufferedStream(&TestStream{incoming: client, outgoing: server, closed: false}, jsonrpc2.VSCodeObjectCodec{})
defer clientStream.Close()
conn := jsonrpc2.NewConn(context.Background(), clientStream, &ConfigurationHandler{t: t})
initialize(t, conn, protocol.InitializeParams{})
homedir, err := os.UserHomeDir()
require.NoError(t, err)
testCases := []struct {
name string
content string
symbols []*protocol.DocumentSymbol
}{
{
name: "target \"api\" {}",
content: "target \"api\" {}",
symbols: []*protocol.DocumentSymbol{
{
Name: "api",
Kind: protocol.SymbolKindFunction,
Range: protocol.Range{
Start: protocol.Position{Line: 0, Character: 0},
End: protocol.Position{Line: 0, Character: 0},
},
},
},
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
didOpen := createDidOpenTextDocumentParams(homedir, t.Name()+".hcl", tc.content, "dockerbake")
err := conn.Notify(context.Background(), protocol.MethodTextDocumentDidOpen, didOpen)
require.NoError(t, err)
var symbols []*protocol.DocumentSymbol
err = conn.Call(context.Background(), protocol.MethodTextDocumentDocumentSymbol, protocol.DocumentSymbolParams{
TextDocument: protocol.TextDocumentIdentifier{URI: didOpen.TextDocument.URI},
}, &symbols)
require.NoError(t, err)
require.Equal(t, tc.symbols, symbols)
})
}
}