mirror of
https://github.com/wavetermdev/xterm.js.git
synced 2026-08-05 13:43:48 -07:00
Fix invalid index check, add api tests
This commit is contained in:
@@ -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文')`);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user