forked from charmbracelet/ultraviolet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransformline_bug_test.go
More file actions
49 lines (44 loc) · 1.38 KB
/
Copy pathtransformline_bug_test.go
File metadata and controls
49 lines (44 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package uv
import (
"testing"
"time"
)
// TestTransformLine_IsZeroInfiniteLoop reproduces and verifies the fix for
// the infinite loop in TerminalRenderer.transformLine at terminal_renderer.go:937.
//
// The bug: the for loop read `next` once before the loop, then looped on
// `next.IsZero()` while incrementing `n`, but never re-read `next` from
// the buffer. If next.IsZero() returned true, the loop never terminated.
//
// The fix: add `next = newLine.At(n + 1)` inside the loop body.
func TestTransformLine_IsZeroInfiniteLoop(t *testing.T) {
newLine := Line{
{Content: "世", Width: 2}, // wide char at index 0
{}, // zero cell at index 1 (trailing)
{}, // zero cell at index 2
{Content: "a", Width: 1}, // normal char at index 3
}
n := 0
next := newLine.At(n + 1) // reads trailing cell (zero)
// The FIXED loop — updates `next` inside the loop
done := make(chan struct{})
go func() {
defer func() {
recover()
close(done)
}()
for next != nil && next.IsZero() {
n++
next = newLine.At(n + 1) // fix: re-read from buffer
}
}()
select {
case <-done:
if n != 2 {
t.Errorf("Expected loop to skip 2 zero cells, got %d", n)
}
t.Logf("Fix verified: loop correctly skipped %d zero cells and stopped at non-zero cell", n)
case <-time.After(2 * time.Second):
t.Fatal("Loop still hangs — fix did not work")
}
}