Skip to content

Test text edits #2803

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 0 additions & 65 deletions autoload/go/fmt_test.vim
Original file line number Diff line number Diff line change
Expand Up @@ -50,71 +50,6 @@ func! Test_goimports() abort
call assert_equal(expected, actual)
endfunc

func! Test_run_fmt_gopls() abort
try
let g:go_fmt_command = 'gopls'

let actual_file = tempname()
call writefile(readfile("test-fixtures/fmt/hello.go"), actual_file)

let expected = join(readfile("test-fixtures/fmt/hello_golden.go"), "\n")

" run our code
call go#fmt#run("gofmt", actual_file, "test-fixtures/fmt/hello.go")

" this should now contain the formatted code
let actual = join(readfile(actual_file), "\n")

call assert_equal(expected, actual)
finally
unlet g:go_fmt_command
endtry
endfunc

func! Test_update_file_gopls() abort
try
let g:go_fmt_command = 'gopls'

let expected = join(readfile("test-fixtures/fmt/hello_golden.go"), "\n")
let source_file = tempname()
call writefile(readfile("test-fixtures/fmt/hello_golden.go"), source_file)

let target_file = tempname()
call writefile([""], target_file)

" update_file now
call go#fmt#update_file(source_file, target_file)

" this should now contain the formatted code
let actual = join(readfile(target_file), "\n")

call assert_equal(expected, actual)
finally
unlet g:go_fmt_command
endtry
endfunc

func! Test_goimports_gopls() abort
try
let g:go_fmt_command = 'gopls'

let $GOPATH = 'test-fixtures/fmt/'
let actual_file = tempname()
call writefile(readfile("test-fixtures/fmt/src/imports/goimports.go"), actual_file)

let expected = join(readfile("test-fixtures/fmt/src/imports/goimports_golden.go"), "\n")

" run our code
call go#fmt#run("goimports", actual_file, "test-fixtures/fmt/src/imports/goimports.go")

" this should now contain the formatted code
let actual = join(readfile(actual_file), "\n")

call assert_equal(expected, actual)
finally
unlet g:go_fmt_command
endtry
endfunc
" restore Vi compatibility settings
let &cpo = s:cpo_save
unlet s:cpo_save
Expand Down
6 changes: 3 additions & 3 deletions autoload/go/lsp.vim
Original file line number Diff line number Diff line change
Expand Up @@ -1428,9 +1428,9 @@ function s:applyTextEdits(msg) abort
if l:msg.range.start.character > 0
let l:preSliceEnd = go#lsp#lsp#PositionOf(l:startcontent, l:msg.range.start.character-1) - 1
let l:startcontent = l:startcontent[:l:preSliceEnd]
elseif l:endline == l:startline && l:msg.range.end.character == 0
" l:startcontent should be the empty string when l:text is to be
" inserted at the beginning of the line.
elseif l:endline == l:startline && (l:msg.range.end.character == 0 || l:msg.range.start.character == 0)
" l:startcontent should be the empty string when l:text is a
" replacement at the beginning of the line.
let l:startcontent = ''
endif

Expand Down
32 changes: 32 additions & 0 deletions autoload/go/lsp_test.vim
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,38 @@ function! s:getinfo(str, name)
endtry
endfunction

func! Test_Format() abort
try
let expected = join(readfile("test-fixtures/lsp/fmt/format_golden.go"), "\n")
let l:tmp = gotest#load_fixture('lsp/fmt/format.go')

call go#lsp#Format()

" this should now contain the formatted code
let actual = join(go#util#GetLines(), "\n")

call assert_equal(expected, actual)
finally
call delete(l:tmp, 'rf')
endtry
endfunc

func! Test_Imports() abort
try
let expected = join(readfile("test-fixtures/lsp/imports/imports_golden.go"), "\n")
let l:tmp = gotest#load_fixture('lsp/imports/imports.go')

call go#lsp#Imports()

" this should now contain the expected imports code
let actual = join(go#util#GetLines(), "\n")

call assert_equal(expected, actual)
finally
call delete(l:tmp, 'rf')
endtry
endfunc

" restore Vi compatibility settings
let &cpo = s:cpo_save
unlet s:cpo_save
Expand Down
1 change: 0 additions & 1 deletion autoload/go/test-fixtures/fmt/src/imports

This file was deleted.

7 changes: 7 additions & 0 deletions autoload/go/test-fixtures/lsp/fmt/format.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "fmt"

func main() {
fmt.Println("vim-go")
}
7 changes: 7 additions & 0 deletions autoload/go/test-fixtures/lsp/fmt/format_golden.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "fmt"

func main() {
fmt.Println("vim-go")
}
10 changes: 10 additions & 0 deletions autoload/go/test-fixtures/lsp/imports/imports.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package main

import (
"fmt"
)

func main() {
io.Copy(ioutil.Discard, os.Stdin)
fmt.Println("vim-go")
}
13 changes: 13 additions & 0 deletions autoload/go/test-fixtures/lsp/imports/imports_golden.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package main

import (
"fmt"
"io"
"io/ioutil"
"os"
)

func main() {
io.Copy(ioutil.Discard, os.Stdin)
fmt.Println("vim-go")
}