Files
iris-context/tests/cursor_test.go
T
VERSE c7960aac46 fix(ui): menu deboucing (#14)
Fixed menu keep moving/debouncing while move up/down
2026-07-02 15:41:44 +07:00

51 lines
926 B
Go

package tests
import (
"testing"
"github.com/versenilvis/iris/integration"
)
func TestComputeCursorCol(t *testing.T) {
tests := []struct {
name string
data []byte
want int
}{
{
name: "Simple prompt",
data: []byte("λ "),
want: 2,
},
{
name: "ANSI color prompt",
data: []byte("\033[32mλ \033[0m"),
want: 2,
},
{
name: "Carriage return and move right",
data: []byte("λ \033[140G...22 chars right prompt...\r\033[2C"),
want: 2,
},
{
name: "OSC sequence before prompt",
data: []byte("\033]0;iris on fix/menu-debouncing\007λ "),
want: 2,
},
{
name: "CSI Horizontal Absolute",
data: []byte("abc\033[10Gde"),
want: 11,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := integration.ComputeCursorCol(tt.data)
if got != tt.want {
t.Errorf("ComputeCursorCol(%q) = %d, want %d", tt.data, got, tt.want)
}
})
}
}