@@ -162,31 +162,26 @@ func TestFormattingOnSave(t *testing.T) {
162
162
})
163
163
}
164
164
165
- // Reproduce golang/go#41057.
166
- func TestCRLF (t * testing.T ) {
167
- runner .Run (t , "-- main.go --" , func (t * testing.T , env * Env ) {
168
- want := `package main
165
+ // Tests various possibilities for comments in files with CRLF line endings.
166
+ // Import organization in these files has historically been a source of bugs.
167
+ func TestCRLFLineEndings (t * testing.T ) {
168
+ for _ , tt := range []struct {
169
+ issue , want string
170
+ }{
171
+ {
172
+ issue : "41057" ,
173
+ want : `package main
169
174
170
175
/*
171
176
Hi description
172
177
*/
173
178
func Hi() {
174
179
}
175
- `
176
- crlf := strings .ReplaceAll (want , "\n " , "\r \n " )
177
- env .CreateBuffer ("main.go" , crlf )
178
- env .Await (CompletedWork (lsp .DiagnosticWorkTitle (lsp .FromDidOpen ), 1 ))
179
- env .SaveBuffer ("main.go" )
180
- got := env .Editor .BufferText ("main.go" )
181
- if want != got {
182
- t .Errorf ("unexpected content after save:\n %s" , tests .Diff (want , got ))
183
- }
184
- })
185
- }
186
-
187
- func TestCRLF_42646 (t * testing.T ) {
188
- runner .Run (t , "-- main.go --" , func (t * testing.T , env * Env ) {
189
- want := `package main
180
+ ` ,
181
+ },
182
+ {
183
+ issue : "42646" ,
184
+ want : `package main
190
185
191
186
import (
192
187
"fmt"
@@ -211,15 +206,32 @@ func main() {
211
206
const server_port = 8080
212
207
fmt.Printf("port: %d\n", server_port)
213
208
}
214
- `
215
- crlf := strings .ReplaceAll (want , "\n " , "\r \n " )
216
- env .CreateBuffer ("main.go" , crlf )
217
- env .Await (CompletedWork (lsp .DiagnosticWorkTitle (lsp .FromDidOpen ), 1 ))
218
- env .OrganizeImports ("main.go" )
219
- got := env .Editor .BufferText ("main.go" )
220
- got = strings .ReplaceAll (got , "\r \n " , "\n " ) // convert everything to LF for simplicity
221
- if want != got {
222
- t .Errorf ("unexpected content after save:\n %s" , tests .Diff (want , got ))
223
- }
224
- })
209
+ ` ,
210
+ },
211
+ {
212
+ issue : "42923" ,
213
+ want : `package main
214
+
215
+ // Line 1.
216
+ // aa
217
+ type Tree struct {
218
+ arr []string
219
+ }
220
+ ` ,
221
+ },
222
+ } {
223
+ t .Run (tt .issue , func (t * testing.T ) {
224
+ run (t , "-- main.go --" , func (t * testing.T , env * Env ) {
225
+ crlf := strings .ReplaceAll (tt .want , "\n " , "\r \n " )
226
+ env .CreateBuffer ("main.go" , crlf )
227
+ env .Await (CompletedWork (lsp .DiagnosticWorkTitle (lsp .FromDidOpen ), 1 ))
228
+ env .OrganizeImports ("main.go" )
229
+ got := env .Editor .BufferText ("main.go" )
230
+ got = strings .ReplaceAll (got , "\r \n " , "\n " ) // convert everything to LF for simplicity
231
+ if tt .want != got {
232
+ t .Errorf ("unexpected content after save:\n %s" , tests .Diff (tt .want , got ))
233
+ }
234
+ })
235
+ })
236
+ }
225
237
}
0 commit comments