Skip to content

Commit

Permalink
wip: prepare test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
kyoh86 committed Jul 13, 2024
1 parent d1e5344 commit 06c04f5
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
)

require (
github.com/google/go-cmp v0.6.0 // indirect
github.com/kr/pretty v0.1.0 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM=
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/haya14busa/go-checkstyle v0.0.0-20170303121022-5e9d09f51fa1/go.mod h1:RsN5RGgVYeXpcXNtWyztD5VIe7VNSEqpJvF2iEH7QvI=
Expand Down
61 changes: 61 additions & 0 deletions langserver/diff_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package langserver_test

import (
"testing"

"github.com/google/go-cmp/cmp"
"github.com/mattn/efm-langserver/langserver"
)

func TestComputeEdits(t *testing.T) {
cases := []struct {
name string
before, after string
want []langserver.TextEdit
}{
{
name: "Empty",
before: "", after: "", want: []langserver.TextEdit{},
},
{
name: "Empty to one line",
before: "", after: "foo", want: []langserver.TextEdit{
{NewText: "foo"},
},
},
{
name: "One line to another",
before: "foo", after: "bar", want: []langserver.TextEdit{
{Range: langserver.Range{End: langserver.Position{Line: 1}}},
{Range: langserver.Range{Start: langserver.Position{Line: 1}, End: langserver.Position{Line: 1}}, NewText: "bar"},
},
},
{
name: "Replace multi lines (issue 281)",
before: "foo\nbar\nbaz\n", after: "one\ntwo\nthree\n",
want: []langserver.TextEdit{
{Range: langserver.Range{End: langserver.Position{Line: 3}}},
{
Range: langserver.Range{Start: langserver.Position{Line: 3}, End: langserver.Position{Line: 3}},
NewText: "three\n",
},
{
Range: langserver.Range{Start: langserver.Position{Line: 3}, End: langserver.Position{Line: 3}},
NewText: "two\n",
},
{
Range: langserver.Range{Start: langserver.Position{Line: 3}, End: langserver.Position{Line: 3}},
NewText: "one\n",
},
},
},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
edits := langserver.ComputeEdits("", c.before, c.after)
if diff := cmp.Diff(c.want, edits); diff != "" {
t.Errorf("unexpected edits (-want +got):\n%s", diff)
}
})
}
}

0 comments on commit 06c04f5

Please sign in to comment.