From 5362ea195ce81ce2707540473c5b7d9d7f4f0eba Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Wed, 10 Apr 2019 00:24:50 -0700 Subject: [PATCH] Add first API test --- src/Terminal.integration.ts | 30 ++++++++++++++++++++++++++++++ src/public/Terminal.ts | 2 +- typings/xterm.d.ts | 2 +- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/Terminal.integration.ts b/src/Terminal.integration.ts index 10043006..e0dad377 100644 --- a/src/Terminal.integration.ts +++ b/src/Terminal.integration.ts @@ -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 = { + 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; diff --git a/src/public/Terminal.ts b/src/public/Terminal.ts index bc82d235..35423b80 100644 --- a/src/public/Terminal.ts +++ b/src/public/Terminal.ts @@ -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); } } diff --git a/typings/xterm.d.ts b/typings/xterm.d.ts index 3a656eab..7f87cb12 100644 --- a/typings/xterm.d.ts +++ b/typings/xterm.d.ts @@ -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 {