2017-11-24 08:54:40 -05:00
|
|
|
func! Test_run_fmt() abort
|
2017-02-11 08:01:38 -05:00
|
|
|
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
|
|
|
|
|
2017-11-24 08:54:40 -05:00
|
|
|
func! Test_update_file() abort
|
2017-02-11 08:01:38 -05:00
|
|
|
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
|
2017-07-06 08:57:35 -04:00
|
|
|
|
2017-11-24 08:54:40 -05:00
|
|
|
func! Test_goimports() abort
|
2017-07-06 08:57:35 -04:00
|
|
|
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)
|
|
|
|
endfunc
|
2017-11-24 08:54:40 -05:00
|
|
|
|
|
|
|
" vim: sw=2 ts=2 et
|