Add first API test

This commit is contained in:
Daniel Imms
2019-04-10 00:24:50 -07:00
parent b55bedc6af
commit 5362ea195c
3 changed files with 32 additions and 2 deletions
+30
View File
@@ -13,6 +13,7 @@ import * as path from 'path';
import * as pty from 'node-pty';
import { assert } from 'chai';
import { Terminal } from './Terminal';
import { Terminal as PublicTerminal } from './public/Terminal';
import { WHITESPACE_CELL_CHAR } from './Buffer';
import { IViewport } from './Types';
import { CellData } from './BufferLine';
@@ -78,6 +79,35 @@ function terminalToString(term: Terminal): string {
return result;
}
describe('API tests', () => {
let api: PublicTerminal;
let core: TestTerminal;
// expect files need terminal at 80x25!
const INIT_COLS = 80;
const INIT_ROWS = 25;
beforeEach(() => {
api = new PublicTerminal({ cols: INIT_COLS, rows: INIT_ROWS });
core = (api as any)._core;
core.innerWrite = () => (core as any)._innerWrite();
core.refresh = () => {};
core.viewport = <IViewport>{
syncScrollArea: () => {}
};
});
describe('buffer', () => {
it('IBufferLine.getLine', () => {
core.writeBuffer.push('abc\n\rdef');
core.innerWrite();
assert.equal(api.buffer.length, INIT_ROWS);
assert.equal(api.buffer.getLine(0).translateToString(true), 'abc');
assert.equal(api.buffer.getLine(1).translateToString(true), 'def');
});
});
});
// Skip tests on Windows since pty.open isn't supported
if (os.platform() !== 'win32') {
const consoleLog = console.log;
+1 -1
View File
@@ -176,7 +176,7 @@ class BufferLineApiView implements IBufferLineApi {
public get isWrapped(): boolean { return this._line.isWrapped; }
public getCell(x: number): IBufferCellApi { return new BufferCellApiView(this._line, x); }
public translateToString(trimRight: boolean, startColumn: number, endColumn: number): string {
public translateToString(trimRight?: boolean, startColumn?: number, endColumn?: number): string {
return this._line.translateToString(trimRight, startColumn, endColumn);
}
}
+1 -1
View File
@@ -834,7 +834,7 @@ declare module 'xterm' {
/**
* Gets the line
*/
translateToString(trimRight: boolean, startColumn: number, endColumn: number): string;
translateToString(trimRight?: boolean, startColumn?: number, endColumn?: number): string;
}
interface IBufferCell {