| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package workspace |
| 6 |
|
| 7 |
import ( |
| 8 |
"runtime" |
| 9 |
"testing" |
| 10 |
|
| 11 |
"golang.org/x/tools/gopls/internal/test/compare" |
| 12 |
. "golang.org/x/tools/gopls/internal/test/integration" |
| 13 |
) |
| 14 |
|
| 15 |
|
| 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 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 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 |
|
| 55 |
|
| 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 |
} |