import { describe, expect, it } from 'vitest'; import { mouseWheelRows, outputBoundaryKey, stripMouseSequences } from '../src/term/mouseEvents.js'; describe('鼠标与输出边界序列解析', () => { it('SGR 滚轮上/下分别移动 3 行', () => { expect(mouseWheelRows('\x1b[<64;10;5M')).toBe(3); expect(mouseWheelRows('\x1b[<65;10;5M')).toBe(-3); }); it('支持 Ink 去除事件块首 ESC 后的形态及合并事件', () => { expect(mouseWheelRows('[<64;1;1M[<64;1;1M[<65;1;1M')).toBe(3); }); it('支持 X10 滚轮并忽略点击', () => { const x10Up = `\x1b[M${String.fromCharCode(96, 40, 10)}`; const x10Down = `\x1b[M${String.fromCharCode(97, 40, 10)}`; expect(mouseWheelRows(x10Up + x10Down)).toBe(0); expect(mouseWheelRows(`\x1b[M${String.fromCharCode(0, 40, 10)}`)).toBe(0); }); it('剥离鼠标事件但保留普通文本', () => { expect(stripMouseSequences('abc\x1b[<64;1;1Mdef')).toBe('abcdef'); }); it('识别 Home/End 的常见终端序列', () => { expect(outputBoundaryKey('\x1b[H')).toBe('home'); expect(outputBoundaryKey('\x1bOH')).toBe('home'); expect(outputBoundaryKey('\x1b[4~')).toBe('end'); expect(outputBoundaryKey('\x1bOF')).toBe('end'); expect(outputBoundaryKey('\x1b[A')).toBeNull(); }); });