Skip to content

Commit

Permalink
fmt: add tests for gopls formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
bhcleek committed Feb 18, 2020
1 parent 8a8824f commit 9fd8254
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions autoload/go/fmt_test.vim
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,71 @@ 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

0 comments on commit 9fd8254

Please sign in to comment.