(t *testing.T)
| 12 | ) |
| 13 | |
| 14 | func TestFormatting(t *testing.T) { |
| 15 | s := startServer() |
| 16 | |
| 17 | client := bytes.NewBuffer(make([]byte, 0, 1024)) |
| 18 | server := bytes.NewBuffer(make([]byte, 0, 1024)) |
| 19 | serverStream := &TestStream{incoming: server, outgoing: client, closed: false} |
| 20 | defer serverStream.Close() |
| 21 | go s.ServeStream(serverStream) |
| 22 | |
| 23 | clientStream := jsonrpc2.NewBufferedStream(&TestStream{incoming: client, outgoing: server, closed: false}, jsonrpc2.VSCodeObjectCodec{}) |
| 24 | defer clientStream.Close() |
| 25 | conn := jsonrpc2.NewConn(context.Background(), clientStream, &ConfigurationHandler{t: t}) |
| 26 | initialize(t, conn, protocol.InitializeParams{}) |
| 27 | |
| 28 | homedir, err := os.UserHomeDir() |
| 29 | require.NoError(t, err) |
| 30 | |
| 31 | testCases := []struct { |
| 32 | name string |
| 33 | content string |
| 34 | edits []protocol.TextEdit |
| 35 | }{ |
| 36 | { |
| 37 | name: "truncate whitespace before a block type", |
| 38 | content: " target t {\n}", |
| 39 | edits: []protocol.TextEdit{ |
| 40 | { |
| 41 | NewText: "", |
| 42 | Range: protocol.Range{ |
| 43 | Start: protocol.Position{Line: 0, Character: 0}, |
| 44 | End: protocol.Position{Line: 0, Character: 1}, |
| 45 | }, |
| 46 | }, |
| 47 | }, |
| 48 | }, |
| 49 | } |
| 50 | |
| 51 | for _, tc := range testCases { |
| 52 | t.Run(tc.name, func(t *testing.T) { |
| 53 | didOpen := createDidOpenTextDocumentParams(homedir, t.Name()+".hcl", tc.content, "dockerbake") |
| 54 | err := conn.Notify(context.Background(), protocol.MethodTextDocumentDidOpen, didOpen) |
| 55 | require.NoError(t, err) |
| 56 | |
| 57 | var edits []protocol.TextEdit |
| 58 | err = conn.Call(context.Background(), protocol.MethodTextDocumentFormatting, protocol.HoverParams{ |
| 59 | TextDocumentPositionParams: protocol.TextDocumentPositionParams{ |
| 60 | TextDocument: protocol.TextDocumentIdentifier{URI: didOpen.TextDocument.URI}, |
| 61 | Position: protocol.Position{Line: 0, Character: 3}, |
| 62 | }, |
| 63 | }, &edits) |
| 64 | require.NoError(t, err) |
| 65 | require.Equal(t, tc.edits, edits) |
| 66 | }) |
| 67 | } |
| 68 | |
| 69 | } |
nothing calls this directly
no test coverage detected