golang.org/x/tools/gopls@v0.15.3/internal/test/integration/workspace/misspelling_test.go (about) 1 // Copyright 2023 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package workspace 6 7 import ( 8 "runtime" 9 "testing" 10 11 . "golang.org/x/tools/gopls/internal/test/integration" 12 "golang.org/x/tools/gopls/internal/test/compare" 13 ) 14 15 // Test for golang/go#57081. 16 func TestFormattingMisspelledURI(t *testing.T) { 17 if runtime.GOOS != "windows" && runtime.GOOS != "darwin" { 18 t.Skip("golang/go#57081 only reproduces on case-insensitive filesystems.") 19 } 20 const files = ` 21 -- go.mod -- 22 module mod.test 23 24 go 1.19 25 -- foo.go -- 26 package foo 27 28 const C = 2 // extra space is intentional 29 ` 30 31 Run(t, files, func(t *testing.T, env *Env) { 32 env.OpenFile("Foo.go") 33 env.FormatBuffer("Foo.go") 34 want := env.BufferText("Foo.go") 35 36 if want == "" { 37 t.Fatalf("Foo.go is empty") 38 } 39 40 // In golang/go#57081, we observed that if overlay cases don't match, gopls 41 // will find (and format) the on-disk contents rather than the overlay, 42 // resulting in invalid edits. 43 // 44 // Verify that this doesn't happen, by confirming that formatting is 45 // idempotent. 46 env.FormatBuffer("Foo.go") 47 got := env.BufferText("Foo.go") 48 if diff := compare.Text(want, got); diff != "" { 49 t.Errorf("invalid content after second formatting:\n%s", diff) 50 } 51 }) 52 } 53 54 // Test that we can find packages for open files with different spelling on 55 // case-insensitive file systems. 56 func TestPackageForMisspelledURI(t *testing.T) { 57 t.Skip("golang/go#57081: this test fails because the Go command does not load Foo.go correctly") 58 if runtime.GOOS != "windows" && runtime.GOOS != "darwin" { 59 t.Skip("golang/go#57081 only reproduces on case-insensitive filesystems.") 60 } 61 const files = ` 62 -- go.mod -- 63 module mod.test 64 65 go 1.19 66 -- foo.go -- 67 package foo 68 69 const C = D 70 -- bar.go -- 71 package foo 72 73 const D = 2 74 ` 75 76 Run(t, files, func(t *testing.T, env *Env) { 77 env.OpenFile("Foo.go") 78 env.AfterChange(NoDiagnostics()) 79 }) 80 }