1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
package app
import (
"os"
"path/filepath"
"strings"
"testing"
)
func TestListProjectFilesSkipsGitAndStopsAtTheLimit(t *testing.T) {
root := t.TempDir()
for _, name := range []string{"main.go", "app/menus.go", ".git/HEAD", ".turbo-x/settings.toml", "docs/en/README.md"} {
path := filepath.Join(root, filepath.FromSlash(name))
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(path, []byte("x"), 0o644); err != nil {
t.Fatal(err)
}
}
files := listProjectFiles(root, 100)
var names []string
for _, file := range files {
names = append(names, file.Name)
if !filepath.IsAbs(file.Path) || !strings.HasPrefix(file.Path, root) {
t.Errorf("Path %q is not absolute under the project", file.Path)
}
}
want := ".turbo-x/settings.toml app/menus.go docs/en/README.md main.go"
if got := strings.Join(names, " "); got != want {
t.Errorf("listProjectFiles = %q, want %q: the editor's own directory in, .git out, slashes forward", got, want)
}
if got := listProjectFiles(root, 2); len(got) != 2 {
t.Errorf("a limit of 2 returned %d files", len(got))
}
}
|