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