Fix invalid index check, add api tests

This commit is contained in:
Daniel Imms
2019-05-11 20:58:51 -07:00
parent 49574be510
commit 70ba349a85
2 changed files with 18 additions and 3 deletions
+10 -1
View File
@@ -300,6 +300,13 @@ describe('API Integration Tests', () => {
});
describe('getLine', () => {
it('invalid index', async function(): Promise<any> {
this.timeout(10000);
await openTerminal({ rows: 5 });
assert.equal(await page.evaluate(`window.term.buffer.getLine(-1)`), undefined);
assert.equal(await page.evaluate(`window.term.buffer.getLine(5)`), undefined);
});
it('isWrapped', async function(): Promise<any> {
this.timeout(10000);
await openTerminal({ cols: 5 });
@@ -331,7 +338,9 @@ describe('API Integration Tests', () => {
it('getCell', async function(): Promise<any> {
this.timeout(10000);
await openTerminal();
await openTerminal({ cols: 5 });
assert.equal(await page.evaluate(`window.term.buffer.getLine(0).getCell(-1)`), undefined);
assert.equal(await page.evaluate(`window.term.buffer.getLine(0).getCell(5)`), undefined);
assert.equal(await page.evaluate(`window.term.buffer.getLine(0).getCell(0).char`), '');
assert.equal(await page.evaluate(`window.term.buffer.getLine(0).getCell(0).width`), 1);
await page.evaluate(`window.term.write('a文')`);
+8 -2
View File
@@ -180,7 +180,13 @@ class BufferApiView implements IBufferApi {
public get viewportY(): number { return this._buffer.ydisp; }
public get baseY(): number { return this._buffer.ybase; }
public get length(): number { return this._buffer.lines.length; }
public getLine(y: number): IBufferLineApi | undefined { return new BufferLineApiView(this._buffer.lines.get(y)); }
public getLine(y: number): IBufferLineApi | undefined {
const line = this._buffer.lines.get(y);
if (!line) {
return undefined;
}
return new BufferLineApiView(line);
}
}
class BufferLineApiView implements IBufferLineApi {
@@ -188,7 +194,7 @@ class BufferLineApiView implements IBufferLineApi {
public get isWrapped(): boolean { return this._line.isWrapped; }
public getCell(x: number): IBufferCellApi | undefined {
if (x < 0 && x >= this._line.length) {
if (x < 0 || x >= this._line.length) {
return undefined;
}
return new BufferCellApiView(this._line, x);