2019-06-03 14:58:18 +00:00
|
|
|
" don't spam the user when Vim is started in Vi compatibility mode
|
|
|
|
let s:cpo_save = &cpo
|
|
|
|
set cpo&vim
|
|
|
|
|
2018-05-06 15:45:27 +00:00
|
|
|
func! Test_run_fmt() abort
|
|
|
|
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)
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
func! Test_update_file() abort
|
|
|
|
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)
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
func! Test_goimports() abort
|
2020-10-28 13:35:24 +00:00
|
|
|
let $GOPATH = printf('%s/%s', fnamemodify(getcwd(), ':p'), 'test-fixtures/fmt')
|
2018-05-06 15:45:27 +00:00
|
|
|
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)
|
|
|
|
endfunc
|
|
|
|
|
2019-06-03 14:58:18 +00:00
|
|
|
" restore Vi compatibility settings
|
|
|
|
let &cpo = s:cpo_save
|
|
|
|
unlet s:cpo_save
|
|
|
|
|
2018-05-06 15:45:27 +00:00
|
|
|
" vim: sw=2 ts=2 et
|