Debian Codegraph @

internal/core/gitfeedback/git_test.go

raw
1 package gitfeedback
2
3 import (
4 "fmt"
5 "strings"
6 "testing"
7 )
8
9 func TestTruncateSummaryKeepsChangedFilesPathOnly(t *testing.T) {
10 files := make([]string, 0, maxFiles+2)
11 for i := 0; i < maxFiles+2; i++ {
12 files = append(files, fmt.Sprintf("file-%02d.txt", i))
13 }
14
15 gotFiles, gotDiff := truncateSummary(files, "")
16 if len(gotFiles) != maxFiles {
17 t.Fatalf("len(gotFiles) = %d, want %d", len(gotFiles), maxFiles)
18 }
19 for _, path := range gotFiles {
20 if strings.HasPrefix(path, "... (") {
21 t.Fatalf("changed files should not contain truncation marker, got %q", path)
22 }
23 }
24 if !strings.Contains(gotDiff, "2 more files omitted") {
25 t.Fatalf("diff note = %q, want omitted-files marker", gotDiff)
26 }
27 }
28
29 func TestTruncateSummaryKeepsOmittedFilesMarkerUnderDiffCap(t *testing.T) {
30 files := make([]string, 0, maxFiles+3)
31 for i := 0; i < maxFiles+3; i++ {
32 files = append(files, fmt.Sprintf("file-%02d.txt", i))
33 }
34 diff := strings.Repeat("x", maxDiffSize)
35
36 _, gotDiff := truncateSummary(files, diff)
37 if !strings.Contains(gotDiff, "3 more files omitted") {
38 t.Fatalf("diff note = %q, want omitted-files marker", gotDiff)
39 }
40 if !strings.Contains(gotDiff, diffTruncatedMarker) {
41 t.Fatalf("diff note = %q, want diff truncation marker", gotDiff)
42 }
43 if len(gotDiff) > maxDiffSize {
44 t.Fatalf("len(gotDiff) = %d, want <= %d", len(gotDiff), maxDiffSize)
45 }
46 }