package app import ( "bytes" "testing" ) func TestCursorShifterCUP(t *testing.T) { cs := newCursorShifter(1) got := cs.Shift([]byte("\x1b[H")) want := []byte("\x1b[2;1H") if !bytes.Equal(got, want) { t.Fatalf("CUP home: got %q want %q", got, want) } } func TestCursorShifterCUPRowCol(t *testing.T) { cs := newCursorShifter(1) got := cs.Shift([]byte("\x1b[10;5H")) if string(got) != "\x1b[11;5H" { t.Fatalf("CUP 10;5: got %q", got) } } func TestCursorShifterVPA(t *testing.T) { cs := newCursorShifter(1) got := cs.Shift([]byte("\x1b[7d")) if string(got) != "\x1b[8d" { t.Fatalf("VPA 7: got %q", got) } } func TestCursorShifterDECSTBM(t *testing.T) { cs := newCursorShifter(1) got := cs.Shift([]byte("\x1b[2;20r")) if string(got) != "\x1b[3;21r" { t.Fatalf("DECSTBM: got %q", got) } } func TestCursorShifterPrivateCSIPassthrough(t *testing.T) { cs := newCursorShifter(1) // Alt-screen toggle — private CSI. got := cs.Shift([]byte("\x1b[?1049h")) if string(got) != "\x1b[?1049h" { t.Fatalf("alt-screen: got %q", got) } } func TestCursorShifterSGRPassthrough(t *testing.T) { cs := newCursorShifter(1) got := cs.Shift([]byte("\x1b[1;31mhello\x1b[0m")) if string(got) != "\x1b[1;31mhello\x1b[0m" { t.Fatalf("SGR: got %q", got) } } func TestCursorShifterStraddleChunks(t *testing.T) { cs := newCursorShifter(1) a := cs.Shift([]byte("\x1b[")) b := cs.Shift([]byte("5;3H")) got := string(a) + string(b) if got != "\x1b[6;3H" { t.Fatalf("straddle: got %q", got) } } func TestCursorShifterOSCNotRewritten(t *testing.T) { cs := newCursorShifter(1) // OSC body containing what looks like a CSI cursor move — should // NOT be rewritten. in := []byte("\x1b]0;\x1b[5;3Htitle\x07") got := cs.Shift(in) if string(got) != string(in) { t.Fatalf("OSC: got %q want %q", got, in) } }