mirror of
https://github.com/wavetermdev/xterm.js.git
synced 2026-08-05 13:43:48 -07:00
Add first API test
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user