Skip to content

Commit 41bcfb0

Browse files
authored
Merge pull request #2803 from bhcleek/test-text-edits
Test text edits
2 parents ba3713a + 5bbf43b commit 41bcfb0

File tree

11 files changed

+72
-69
lines changed

11 files changed

+72
-69
lines changed

autoload/go/fmt_test.vim

-65
Original file line numberDiff line numberDiff line change
@@ -50,71 +50,6 @@ func! Test_goimports() abort
5050
call assert_equal(expected, actual)
5151
endfunc
5252

53-
func! Test_run_fmt_gopls() abort
54-
try
55-
let g:go_fmt_command = 'gopls'
56-
57-
let actual_file = tempname()
58-
call writefile(readfile("test-fixtures/fmt/hello.go"), actual_file)
59-
60-
let expected = join(readfile("test-fixtures/fmt/hello_golden.go"), "\n")
61-
62-
" run our code
63-
call go#fmt#run("gofmt", actual_file, "test-fixtures/fmt/hello.go")
64-
65-
" this should now contain the formatted code
66-
let actual = join(readfile(actual_file), "\n")
67-
68-
call assert_equal(expected, actual)
69-
finally
70-
unlet g:go_fmt_command
71-
endtry
72-
endfunc
73-
74-
func! Test_update_file_gopls() abort
75-
try
76-
let g:go_fmt_command = 'gopls'
77-
78-
let expected = join(readfile("test-fixtures/fmt/hello_golden.go"), "\n")
79-
let source_file = tempname()
80-
call writefile(readfile("test-fixtures/fmt/hello_golden.go"), source_file)
81-
82-
let target_file = tempname()
83-
call writefile([""], target_file)
84-
85-
" update_file now
86-
call go#fmt#update_file(source_file, target_file)
87-
88-
" this should now contain the formatted code
89-
let actual = join(readfile(target_file), "\n")
90-
91-
call assert_equal(expected, actual)
92-
finally
93-
unlet g:go_fmt_command
94-
endtry
95-
endfunc
96-
97-
func! Test_goimports_gopls() abort
98-
try
99-
let g:go_fmt_command = 'gopls'
100-
101-
let $GOPATH = 'test-fixtures/fmt/'
102-
let actual_file = tempname()
103-
call writefile(readfile("test-fixtures/fmt/src/imports/goimports.go"), actual_file)
104-
105-
let expected = join(readfile("test-fixtures/fmt/src/imports/goimports_golden.go"), "\n")
106-
107-
" run our code
108-
call go#fmt#run("goimports", actual_file, "test-fixtures/fmt/src/imports/goimports.go")
109-
110-
" this should now contain the formatted code
111-
let actual = join(readfile(actual_file), "\n")
112-
113-
call assert_equal(expected, actual)
114-
finally
115-
unlet g:go_fmt_command
116-
endtry
117-
endfunc
11853
" restore Vi compatibility settings
11954
let &cpo = s:cpo_save
12055
unlet s:cpo_save

autoload/go/lsp.vim

+3-3
Original file line numberDiff line numberDiff line change
@@ -1428,9 +1428,9 @@ function s:applyTextEdits(msg) abort
14281428
if l:msg.range.start.character > 0
14291429
let l:preSliceEnd = go#lsp#lsp#PositionOf(l:startcontent, l:msg.range.start.character-1) - 1
14301430
let l:startcontent = l:startcontent[:l:preSliceEnd]
1431-
elseif l:endline == l:startline && l:msg.range.end.character == 0
1432-
" l:startcontent should be the empty string when l:text is to be
1433-
" inserted at the beginning of the line.
1431+
elseif l:endline == l:startline && (l:msg.range.end.character == 0 || l:msg.range.start.character == 0)
1432+
" l:startcontent should be the empty string when l:text is a
1433+
" replacement at the beginning of the line.
14341434
let l:startcontent = ''
14351435
endif
14361436

autoload/go/lsp_test.vim

+32
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,38 @@ function! s:getinfo(str, name)
4242
endtry
4343
endfunction
4444

45+
func! Test_Format() abort
46+
try
47+
let expected = join(readfile("test-fixtures/lsp/fmt/format_golden.go"), "\n")
48+
let l:tmp = gotest#load_fixture('lsp/fmt/format.go')
49+
50+
call go#lsp#Format()
51+
52+
" this should now contain the formatted code
53+
let actual = join(go#util#GetLines(), "\n")
54+
55+
call assert_equal(expected, actual)
56+
finally
57+
call delete(l:tmp, 'rf')
58+
endtry
59+
endfunc
60+
61+
func! Test_Imports() abort
62+
try
63+
let expected = join(readfile("test-fixtures/lsp/imports/imports_golden.go"), "\n")
64+
let l:tmp = gotest#load_fixture('lsp/imports/imports.go')
65+
66+
call go#lsp#Imports()
67+
68+
" this should now contain the expected imports code
69+
let actual = join(go#util#GetLines(), "\n")
70+
71+
call assert_equal(expected, actual)
72+
finally
73+
call delete(l:tmp, 'rf')
74+
endtry
75+
endfunc
76+
4577
" restore Vi compatibility settings
4678
let &cpo = s:cpo_save
4779
unlet s:cpo_save

autoload/go/test-fixtures/fmt/src/imports

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package main
2+
3+
import "fmt"
4+
5+
func main() {
6+
fmt.Println("vim-go")
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package main
2+
3+
import "fmt"
4+
5+
func main() {
6+
fmt.Println("vim-go")
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
)
6+
7+
func main() {
8+
io.Copy(ioutil.Discard, os.Stdin)
9+
fmt.Println("vim-go")
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"io"
6+
"io/ioutil"
7+
"os"
8+
)
9+
10+
func main() {
11+
io.Copy(ioutil.Discard, os.Stdin)
12+
fmt.Println("vim-go")
13+
}

0 commit comments

Comments
 (0)