1 // Copyright 2020 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.
13 "golang.org/x/tools/internal/lsp/fake"
14 "golang.org/x/tools/internal/span"
17 func TestCaseInsensitiveFilesystem(t *testing.T) {
18 base, err := ioutil.TempDir("", t.Name())
23 inner := filepath.Join(base, "a/B/c/DEFgh")
24 if err := os.MkdirAll(inner, 0777); err != nil {
27 file := filepath.Join(inner, "f.go")
28 if err := ioutil.WriteFile(file, []byte("hi"), 0777); err != nil {
31 if _, err := os.Stat(filepath.Join(inner, "F.go")); err != nil {
32 t.Skip("filesystem is case-sensitive")
40 {filepath.Join(inner, "F.go"), true},
41 {filepath.Join(base, "a/b/c/defgh/f.go"), true},
43 for _, tt := range tests {
44 err := checkPathCase(tt.path)
45 if err != nil != tt.err {
46 t.Errorf("checkPathCase(%q) = %v, wanted error: %v", tt.path, err, tt.err)
51 func TestFindWorkspaceRoot(t *testing.T) {
62 module d-goplsworkspace
66 dir, err := fake.Tempdir(workspace)
70 defer os.RemoveAll(dir)
84 for _, test := range tests {
85 ctx := context.Background()
86 rel := fake.RelativeTo(dir)
87 folderURI := span.URIFromPath(rel.AbsPath(test.folder))
88 got, err := findWorkspaceRoot(ctx, folderURI, osFileSource{})
92 if rel.RelPath(got.Filename()) != test.want {
93 t.Errorf("fileWorkspaceRoot(%q) = %q, want %q", test.folder, got, test.want)
98 func TestInVendor(t *testing.T) {
99 for _, tt := range []struct {
104 path: "foo/vendor/x.go",
108 path: "foo/vendor/x/x.go",
116 if got := inVendor(span.URIFromPath(tt.path)); got != tt.inVendor {
117 t.Errorf("expected %s inVendor %v, got %v", tt.path, tt.inVendor, got)