| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package protocol |
| 6 |
|
| 7 |
import ( |
| 8 |
"encoding/json" |
| 9 |
"testing" |
| 10 |
|
| 11 |
"github.com/google/go-cmp/cmp" |
| 12 |
) |
| 13 |
|
| 14 |
func TestInsertReplaceEdit_UnmarshalJSON(t *testing.T) { |
| 15 |
tests := []struct { |
| 16 |
name string |
| 17 |
in any |
| 18 |
wantErr bool |
| 19 |
}{ |
| 20 |
{ |
| 21 |
name: "TextEdit", |
| 22 |
in: TextEdit{NewText: "new text", Range: Range{Start: Position{Line: 1}}}, |
| 23 |
}, |
| 24 |
{ |
| 25 |
name: "InsertReplaceEdit", |
| 26 |
in: InsertReplaceEdit{NewText: "new text", Insert: Range{Start: Position{Line: 100}}, Replace: Range{End: Position{Line: 200}}}, |
| 27 |
}, |
| 28 |
} |
| 29 |
for _, tt := range tests { |
| 30 |
t.Run(tt.name, func(t *testing.T) { |
| 31 |
data, err := json.MarshalIndent(Or_CompletionItem_textEdit{Value: tt.in}, "", " ") |
| 32 |
if err != nil { |
| 33 |
t.Fatalf("failed to marshal: %v", err) |
| 34 |
} |
| 35 |
var decoded Or_CompletionItem_textEdit |
| 36 |
if err := json.Unmarshal(data, &decoded); err != nil { |
| 37 |
t.Fatalf("failed to unmarshal: %v", err) |
| 38 |
} |
| 39 |
if diff := cmp.Diff(tt.in, decoded.Value); diff != "" { |
| 40 |
t.Errorf("unmarshal returns unexpected result: (-want +got):\n%s", diff) |
| 41 |
} |
| 42 |
}) |
| 43 |
} |
| 44 |
} |