| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package misc |
| 6 |
|
| 7 |
import ( |
| 8 |
"os" |
| 9 |
"strings" |
| 10 |
"testing" |
| 11 |
|
| 12 |
"golang.org/x/telemetry/counter/countertest" |
| 13 |
"golang.org/x/tools/gopls/internal/protocol" |
| 14 |
. "golang.org/x/tools/gopls/internal/test/integration" |
| 15 |
"golang.org/x/tools/gopls/internal/util/bug" |
| 16 |
) |
| 17 |
|
| 18 |
func TestMain(m *testing.M) { |
| 19 |
bug.PanicOnBugs = true |
| 20 |
tmp, err := os.MkdirTemp("", "gopls-misc-test-counters") |
| 21 |
if err != nil { |
| 22 |
panic(err) |
| 23 |
} |
| 24 |
countertest.Open(tmp) |
| 25 |
code := Main(m) |
| 26 |
os.RemoveAll(tmp) |
| 27 |
os.Exit(code) |
| 28 |
} |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
func TestDocumentURIFix(t *testing.T) { |
| 36 |
const mod = ` |
| 37 |
-- go.mod -- |
| 38 |
module testdata |
| 39 |
go 1.18 |
| 40 |
|
| 41 |
-- a.go -- |
| 42 |
package a |
| 43 |
|
| 44 |
const K = 1 |
| 45 |
` |
| 46 |
Run(t, mod, func(t *testing.T, env *Env) { |
| 47 |
env.OpenFile("a.go") |
| 48 |
loc := env.RegexpSearch("a.go", "K") |
| 49 |
path := strings.TrimPrefix(string(loc.URI), "file://") |
| 50 |
|
| 51 |
check := func() { |
| 52 |
t.Helper() |
| 53 |
t.Logf("URI = %s", loc.URI) |
| 54 |
content, _ := env.Hover(loc) |
| 55 |
if content == nil || !strings.Contains(content.Value, "const K") { |
| 56 |
t.Errorf("wrong content: %#v", content) |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
check() |
| 62 |
|
| 63 |
|
| 64 |
loc.URI = protocol.DocumentURI("file://" + strings.Replace(path, "/a.go", "%2Fa.go", 1)) |
| 65 |
check() |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
}) |
| 72 |
} |