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)) } }