1 // Copyright 2020 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
12 func TestApplyEdit(t *testing.T) {
21 label: "empty content",
30 label: "unicode edit",
31 content: "hello, 日本語",
33 Start: Pos{Line: 0, Column: 7},
34 End: Pos{Line: 0, Column: 10},
41 content: "ABC\nDEF\nGHI\nJKL",
43 Start: Pos{Line: 1, Column: 1},
44 End: Pos{Line: 2, Column: 3},
47 want: "ABC\nD12\n345\nJKL",
50 label: "end before start",
51 content: "ABC\nDEF\nGHI\nJKL",
53 End: Pos{Line: 1, Column: 1},
54 Start: Pos{Line: 2, Column: 3},
60 label: "out of bounds line",
61 content: "ABC\nDEF\nGHI\nJKL",
63 Start: Pos{Line: 1, Column: 1},
64 End: Pos{Line: 4, Column: 3},
70 label: "out of bounds column",
71 content: "ABC\nDEF\nGHI\nJKL",
73 Start: Pos{Line: 1, Column: 4},
74 End: Pos{Line: 2, Column: 3},
81 for _, test := range tests {
83 t.Run(test.label, func(t *testing.T) {
84 lines := strings.Split(test.content, "\n")
85 newLines, err := editContent(lines, test.edits)
86 if (err != nil) != test.wantErr {
87 t.Errorf("got err %v, want error: %t", err, test.wantErr)
92 if got := strings.Join(newLines, "\n"); got != test.want {
93 t.Errorf("got %q, want %q", got, test.want)