-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtsinsertreplaceedit_test.go
More file actions
44 lines (40 loc) · 1.15 KB
/
tsinsertreplaceedit_test.go
File metadata and controls
44 lines (40 loc) · 1.15 KB
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
// Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package lsp
import (
"encoding/json"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestInsertReplaceEdit_UnmarshalJSON(t *testing.T) {
tests := []struct {
name string
in any
wantErr bool
}{
{
name: "TextEdit",
in: TextEdit{NewText: "new text", Range: Range{Start: Position{Line: 1}}},
},
{
name: "InsertReplaceEdit",
in: InsertReplaceEdit{NewText: "new text", Insert: Range{Start: Position{Line: 100}}, Replace: Range{End: Position{Line: 200}}},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
data, err := json.MarshalIndent(Or_CompletionItem_textEdit{Value: tt.in}, "", " ")
if err != nil {
t.Fatalf("failed to marshal: %v", err)
}
var decoded Or_CompletionItem_textEdit
if err := json.Unmarshal(data, &decoded); err != nil {
t.Fatalf("failed to unmarshal: %v", err)
}
if diff := cmp.Diff(tt.in, decoded.Value); diff != "" {
t.Errorf("unmarshal returns unexpected result: (-want +got):\n%s", diff)
}
})
}
}