Files
wehub-resource-sync a06f331eb8
CI / benchmark (push) Has been skipped
install-script / posix-syntax (push) Successful in 6m1s
CI / build-onnx (push) Failing after 6m43s
init-smoke / dry-run (push) Failing after 15m57s
security / govulncheck (push) Has been cancelled
security / trivy-fs (push) Has been cancelled
CI / test (1.26, ubuntu-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
CI / test (1.26, macos-latest) (push) Has been cancelled
CI / build-windows (push) Has been cancelled
CI / lint (push) Has been cancelled
install-script / powershell-syntax (push) Has been cancelled
install-script / install (macos-14) (push) Has been cancelled
install-script / install (ubuntu-latest) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:33:42 +08:00

48 lines
1.7 KiB
Go

package main
import (
"reflect"
"strings"
"testing"
)
// TestFilesCmdTreeFormat covers the files verb's three layouts and the
// find_files path extraction.
func TestFilesCmdTreeFormat(t *testing.T) {
paths := []string{"internal/a/x.go", "internal/a/y.go", "internal/b/z.go", "main.go"}
// Tree: sorted, hierarchical, directories suffixed with "/".
wantTree := "internal/\n a/\n x.go\n y.go\n b/\n z.go\nmain.go\n"
if tree := renderFilesTree(paths); tree != wantTree {
t.Errorf("renderFilesTree =\n%q\nwant\n%q", tree, wantTree)
}
// Flat: one sorted path per line.
if flat := renderFilesFlat([]string{"b.go", "a.go"}); flat != "a.go\nb.go\n" {
t.Errorf("renderFilesFlat = %q, want \"a.go\\nb.go\\n\"", flat)
}
// Grouped: files under their parent directory; root files under "(root)".
grouped := renderFilesGrouped([]string{"internal/a/x.go", "main.go"})
if !strings.Contains(grouped, "internal/a/\n x.go\n") {
t.Errorf("grouped missing internal/a group:\n%s", grouped)
}
if !strings.Contains(grouped, "(root)/\n main.go\n") {
t.Errorf("grouped missing root group:\n%s", grouped)
}
// renderFiles dispatches by format.
if renderFiles(paths, "flat") != renderFilesFlat(paths) {
t.Error("renderFiles(flat) must match renderFilesFlat")
}
if renderFiles(paths, "anything-else") != renderFilesTree(paths) {
t.Error("renderFiles default must be the tree layout")
}
// parseFindFilesPaths extracts files[].path.
raw := []byte(`{"files":[{"path":"a.go"},{"path":"b.go"}],"truncated":false}`)
if got := parseFindFilesPaths(raw); !reflect.DeepEqual(got, []string{"a.go", "b.go"}) {
t.Errorf("parseFindFilesPaths = %v, want [a.go b.go]", got)
}
}