diff --git a/gopls/internal/regtest/misc/formatting_test.go b/gopls/internal/regtest/misc/formatting_test.go index 52d89e4ba2..1e14237afc 100644 --- a/gopls/internal/regtest/misc/formatting_test.go +++ b/gopls/internal/regtest/misc/formatting_test.go @@ -171,7 +171,7 @@ func TestFormattingOnSave(t *testing.T) { // Import organization in these files has historically been a source of bugs. func TestCRLFLineEndings(t *testing.T) { for _, tt := range []struct { - issue, want string + issue, input, want string }{ { issue: "41057", @@ -222,12 +222,40 @@ func main() { type Tree struct { arr []string } +`, + }, + { + issue: "47200", + input: `package main + +import "fmt" + +func main() { + math.Sqrt(9) + fmt.Println("hello") +} +`, + want: `package main + +import ( + "fmt" + "math" +) + +func main() { + math.Sqrt(9) + fmt.Println("hello") +} `, }, } { t.Run(tt.issue, func(t *testing.T) { Run(t, "-- main.go --", func(t *testing.T, env *Env) { - crlf := strings.ReplaceAll(tt.want, "\n", "\r\n") + input := tt.input + if input == "" { + input = tt.want + } + crlf := strings.ReplaceAll(input, "\n", "\r\n") env.CreateBuffer("main.go", crlf) env.Await(env.DoneWithOpen()) env.OrganizeImports("main.go")