okami.mom/ultraviolet
git clone https://git.nkp.pet/okami.mom/ultraviolet
c7cac3e
main
1package uv 2 3import ( 4"testing" 5 6"github.com/charmbracelet/x/ansi" 7) 8 9// TestStyledWideCellPlaceholderDetection reproduces the placeholder-detection 10// inconsistency introduced by PR #124. 11// 12// Line.Set marks the continuation columns of a wide cell with Width == 0 13// placeholders. The PR makes those placeholders inherit the wide cell's Style 14// and Link. The renderer detects placeholders two different ways: 15// 16// - putAttrCell (terminal_renderer.go:490) uses cell.Width == 0 17// - putRange / transformLine (terminal_renderer.go:694,942,950) use IsZero() 18// 19// For an unstyled wide cell both agree, because the placeholder equals Cell{}. 20// For a styled wide cell the placeholder is no longer zero, so IsZero() stops 21// recognizing it while Width == 0 still does. The two checks disagree, which is 22// how transformLine can pick a move/insert point inside a wide glyph. 23func TestStyledWideCellPlaceholderDetection (t * testing.T ) { 24t .Run ("unstyled wide cell: both checks agree" ,func (t * testing.T ) { 25l := make (Line ,5 ) 26l .Set (0 ,& Cell {Content :"你" ,Width :2 }) 27 28ph := l .At (1 ) 29if ph .Width != 0 { 30t .Fatalf ("expected placeholder Width == 0, got %d" ,ph .Width ) 31 } 32if ! ph .IsZero () { 33t .Errorf ("expected unstyled placeholder to be IsZero()" ) 34 } 35 }) 36 37t .Run ("styled wide cell: checks disagree (regression)" ,func (t * testing.T ) { 38l := make (Line ,5 ) 39l .Set (0 ,& Cell {Content :"你" ,Width :2 ,Style :Style {Bg :ansi .Red }}) 40 41ph := l .At (1 ) 42if ph .Width != 0 { 43t .Fatalf ("expected placeholder Width == 0, got %d" ,ph .Width ) 44 } 45// This is the bug: the Width==0 placeholder is no longer IsZero(), so 46// every renderer path still keyed on IsZero() fails to skip it. 47if ph .IsZero () { 48t .Skip ("placeholder is zero; PR #124 style inheritance not present" ) 49 } 50t .Errorf ("styled wide-cell placeholder has Width==0 but IsZero()==false: " + 51"renderer paths using IsZero() (terminal_renderer.go:694,942,950) " + 52"will not recognize it; placeholder=%+v" ,* ph ) 53 }) 54}