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