Skip to content

Commit d500b0f

Browse files
committed
inputhandler tests
1 parent 9985ae2 commit d500b0f

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

src/common/InputHandler.test.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { DEFAULT_OPTIONS } from 'common/services/OptionsService';
1717
import { clone } from 'common/Clone';
1818
import { BufferService } from 'common/services/BufferService';
1919
import { CoreService } from 'common/services/CoreService';
20+
import { OscHandler } from 'common/parser/OscParser';
2021

2122
function getCursor(bufferService: IBufferService): number[] {
2223
return [
@@ -1805,3 +1806,61 @@ describe('InputHandler', () => {
18051806
});
18061807
});
18071808
});
1809+
1810+
1811+
describe('InputHandler - async handlers', () => {
1812+
let bufferService: IBufferService;
1813+
let coreService: ICoreService;
1814+
let optionsService: MockOptionsService;
1815+
let inputHandler: TestInputHandler;
1816+
1817+
beforeEach(() => {
1818+
optionsService = new MockOptionsService();
1819+
bufferService = new BufferService(optionsService);
1820+
bufferService.resize(80, 30);
1821+
coreService = new CoreService(() => {}, bufferService, new MockLogService(), optionsService);
1822+
coreService.onData(data => { console.log(data); });
1823+
1824+
inputHandler = new TestInputHandler(bufferService, new MockCharsetService(), coreService, new MockDirtyRowService(), new MockLogService(), optionsService, new MockCoreMouseService(), new MockUnicodeService());
1825+
});
1826+
1827+
it('async CUP with CPR check', async () => {
1828+
const cup: number[][] = [];
1829+
const cpr: number[][] = [];
1830+
inputHandler.registerCsiHandler({final: 'H'}, async params => {
1831+
cup.push(params.toArray() as number[]);
1832+
await new Promise(res => setTimeout(res, 50));
1833+
// late call of real repositioning
1834+
return inputHandler.cursorPosition(params);
1835+
});
1836+
coreService.onData(data => {
1837+
const m = data.match(/\x1b\[(.*?);(.*?)R/);
1838+
if (m) {
1839+
cpr.push([parseInt(m[1]), parseInt(m[2])]);
1840+
}
1841+
});
1842+
await inputHandler.parseP('aaa\x1b[3;4H\x1b[6nbbb\x1b[6;8H\x1b[6n');
1843+
assert.deepEqual(cup, cpr);
1844+
});
1845+
it('async OSC between', async () => {
1846+
inputHandler.registerOscHandler(1000, async data => {
1847+
await new Promise(res => setTimeout(res, 50));
1848+
assert.deepEqual(getLines(bufferService, 2), ['hello world!', '']);
1849+
assert.equal(data, 'some data');
1850+
return true;
1851+
});
1852+
await inputHandler.parseP('hello world!\r\n\x1b]1000;some data\x07second line');
1853+
assert.deepEqual(getLines(bufferService, 2), ['hello world!', 'second line']);
1854+
});
1855+
it('async DCS between', async () => {
1856+
inputHandler.registerDcsHandler({final: 'a'}, async (data, params) => {
1857+
await new Promise(res => setTimeout(res, 50));
1858+
assert.deepEqual(getLines(bufferService, 2), ['hello world!', '']);
1859+
assert.equal(data, 'some data');
1860+
assert.deepEqual(params.toArray(), [1, 2]);
1861+
return true;
1862+
});
1863+
await inputHandler.parseP('hello world!\r\n\x1bP1;2asome data\x1b\\second line');
1864+
assert.deepEqual(getLines(bufferService, 2), ['hello world!', 'second line']);
1865+
});
1866+
});

0 commit comments

Comments
 (0)