fmt_test.vim 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. func! Test_run_fmt() abort
  2. let actual_file = tempname()
  3. call writefile(readfile("test-fixtures/fmt/hello.go"), actual_file)
  4. let expected = join(readfile("test-fixtures/fmt/hello_golden.go"), "\n")
  5. " run our code
  6. call go#fmt#run("gofmt", actual_file, "test-fixtures/fmt/hello.go")
  7. " this should now contain the formatted code
  8. let actual = join(readfile(actual_file), "\n")
  9. call assert_equal(expected, actual)
  10. endfunc
  11. func! Test_update_file() abort
  12. let expected = join(readfile("test-fixtures/fmt/hello_golden.go"), "\n")
  13. let source_file = tempname()
  14. call writefile(readfile("test-fixtures/fmt/hello_golden.go"), source_file)
  15. let target_file = tempname()
  16. call writefile([""], target_file)
  17. " update_file now
  18. call go#fmt#update_file(source_file, target_file)
  19. " this should now contain the formatted code
  20. let actual = join(readfile(target_file), "\n")
  21. call assert_equal(expected, actual)
  22. endfunc
  23. func! Test_goimports() abort
  24. let $GOPATH = 'test-fixtures/fmt/'
  25. let actual_file = tempname()
  26. call writefile(readfile("test-fixtures/fmt/src/imports/goimports.go"), actual_file)
  27. let expected = join(readfile("test-fixtures/fmt/src/imports/goimports_golden.go"), "\n")
  28. " run our code
  29. call go#fmt#run("goimports", actual_file, "test-fixtures/fmt/src/imports/goimports.go")
  30. " this should now contain the formatted code
  31. let actual = join(readfile(actual_file), "\n")
  32. call assert_equal(expected, actual)
  33. endfunc
  34. " vim: sw=2 ts=2 et