diff --git a/src/Buffer.test.ts b/src/Buffer.test.ts index 1e5e2c3b..99bd6d0f 100644 --- a/src/Buffer.test.ts +++ b/src/Buffer.test.ts @@ -1,6 +1,7 @@ /** * @license MIT */ + import { assert } from 'chai'; import { ITerminal } from './Interfaces'; import { Buffer } from './Buffer'; diff --git a/src/BufferSet.test.ts b/src/BufferSet.test.ts index 78a19351..97c07995 100644 --- a/src/BufferSet.test.ts +++ b/src/BufferSet.test.ts @@ -1,6 +1,7 @@ /** * @license MIT */ + import { assert } from 'chai'; import { ITerminal } from './Interfaces'; import { BufferSet } from './BufferSet'; diff --git a/src/CompositionHelper.test.ts b/src/CompositionHelper.test.ts index 70b23183..0adb1719 100644 --- a/src/CompositionHelper.test.ts +++ b/src/CompositionHelper.test.ts @@ -1,3 +1,7 @@ +/** + * @license MIT + */ + import { assert } from 'chai'; import { CompositionHelper } from './CompositionHelper'; diff --git a/src/EventEmitter.test.ts b/src/EventEmitter.test.ts index 7ae381c8..d61f994a 100644 --- a/src/EventEmitter.test.ts +++ b/src/EventEmitter.test.ts @@ -1,3 +1,7 @@ +/** + * @license MIT + */ + import { assert } from 'chai'; import { EventEmitter } from './EventEmitter'; diff --git a/src/InputHandler.test.ts b/src/InputHandler.test.ts index b6b218df..043b7919 100644 --- a/src/InputHandler.test.ts +++ b/src/InputHandler.test.ts @@ -1,12 +1,18 @@ +/** + * @license MIT + */ + import { assert } from 'chai'; import { InputHandler } from './InputHandler'; import { wcwidth } from './InputHandler'; +import { MockInputHandlingTerminal } from './utils/TestUtils'; describe('InputHandler', () => { describe('save and restore cursor', () => { - let terminal = { buffer: { x: 1, y: 2 } }; - // TODO: Create proper mock IInputHandlingTerminal test util object - let inputHandler = new InputHandler(terminal); + let terminal = new MockInputHandlingTerminal(); + terminal.buffer.x = 1; + terminal.buffer.y = 2; + let inputHandler = new InputHandler(terminal); // Save cursor position inputHandler.saveCursor([]); assert.equal(terminal.buffer.x, 1); @@ -21,46 +27,42 @@ describe('InputHandler', () => { }); describe('setCursorStyle', () => { it('should call Terminal.setOption with correct params', () => { - let options = {}; - let terminal = { - setOption: (option, value) => options[option] = value - }; - let inputHandler = new InputHandler(terminal); + let terminal = new MockInputHandlingTerminal(); + let inputHandler = new InputHandler(terminal); inputHandler.setCursorStyle([0]); - assert.equal(options['cursorStyle'], 'block'); - assert.equal(options['cursorBlink'], true); + assert.equal(terminal.options['cursorStyle'], 'block'); + assert.equal(terminal.options['cursorBlink'], true); - options = {}; + terminal.options = {}; inputHandler.setCursorStyle([1]); - assert.equal(options['cursorStyle'], 'block'); - assert.equal(options['cursorBlink'], true); + assert.equal(terminal.options['cursorStyle'], 'block'); + assert.equal(terminal.options['cursorBlink'], true); - options = {}; + terminal.options = {}; inputHandler.setCursorStyle([2]); - assert.equal(options['cursorStyle'], 'block'); - assert.equal(options['cursorBlink'], false); + assert.equal(terminal.options['cursorStyle'], 'block'); + assert.equal(terminal.options['cursorBlink'], false); - options = {}; + terminal.options = {}; inputHandler.setCursorStyle([3]); - assert.equal(options['cursorStyle'], 'underline'); - assert.equal(options['cursorBlink'], true); + assert.equal(terminal.options['cursorStyle'], 'underline'); + assert.equal(terminal.options['cursorBlink'], true); - options = {}; + terminal.options = {}; inputHandler.setCursorStyle([4]); - assert.equal(options['cursorStyle'], 'underline'); - assert.equal(options['cursorBlink'], false); + assert.equal(terminal.options['cursorStyle'], 'underline'); + assert.equal(terminal.options['cursorBlink'], false); - options = {}; + terminal.options = {}; inputHandler.setCursorStyle([5]); - assert.equal(options['cursorStyle'], 'bar'); - assert.equal(options['cursorBlink'], true); + assert.equal(terminal.options['cursorStyle'], 'bar'); + assert.equal(terminal.options['cursorBlink'], true); - options = {}; + terminal.options = {}; inputHandler.setCursorStyle([6]); - assert.equal(options['cursorStyle'], 'bar'); - assert.equal(options['cursorBlink'], false); - + assert.equal(terminal.options['cursorStyle'], 'bar'); + assert.equal(terminal.options['cursorBlink'], false); }); }); }); diff --git a/src/InputHandler.ts b/src/InputHandler.ts index 91160134..5362cae9 100644 --- a/src/InputHandler.ts +++ b/src/InputHandler.ts @@ -15,7 +15,6 @@ import { CharData } from './Types'; * each function's header comment. */ export class InputHandler implements IInputHandler { - // TODO: We want to type _terminal when it's pulled into TS constructor(private _terminal: IInputHandlingTerminal) { } public addChar(char: string, code: number): void { diff --git a/src/Linkifier.test.ts b/src/Linkifier.test.ts index 414238f9..a4ed70db 100644 --- a/src/Linkifier.test.ts +++ b/src/Linkifier.test.ts @@ -1,6 +1,7 @@ /** * @license MIT */ + import jsdom = require('jsdom'); import { assert } from 'chai'; import { ITerminal, ILinkifier } from './Interfaces'; diff --git a/src/SelectionManager.test.ts b/src/SelectionManager.test.ts index a39c4dda..698cda7e 100644 --- a/src/SelectionManager.test.ts +++ b/src/SelectionManager.test.ts @@ -1,6 +1,7 @@ /** * @license MIT */ + import jsdom = require('jsdom'); import { assert } from 'chai'; import { ITerminal, ICircularList } from './Interfaces'; diff --git a/src/SelectionModel.test.ts b/src/SelectionModel.test.ts index 696d12f0..9da84478 100644 --- a/src/SelectionModel.test.ts +++ b/src/SelectionModel.test.ts @@ -1,6 +1,7 @@ /** * @license MIT */ + import { assert } from 'chai'; import { ITerminal } from './Interfaces'; import { SelectionModel } from './SelectionModel'; diff --git a/src/Viewport.test.ts b/src/Viewport.test.ts index 7c89da29..8c7a914b 100644 --- a/src/Viewport.test.ts +++ b/src/Viewport.test.ts @@ -1,3 +1,7 @@ +/** + * @license MIT + */ + import { assert } from 'chai'; import { Viewport } from './Viewport'; import {BufferSet} from './BufferSet'; diff --git a/src/utils/CharMeasure.test.ts b/src/utils/CharMeasure.test.ts index fd4954e0..68e1b6a7 100644 --- a/src/utils/CharMeasure.test.ts +++ b/src/utils/CharMeasure.test.ts @@ -1,6 +1,7 @@ /** * @license MIT */ + import jsdom = require('jsdom'); import { assert } from 'chai'; import { ICharMeasure, ITerminal } from '../Interfaces'; diff --git a/src/utils/CircularList.test.ts b/src/utils/CircularList.test.ts index aaa4a0d9..e27e7f7a 100644 --- a/src/utils/CircularList.test.ts +++ b/src/utils/CircularList.test.ts @@ -1,3 +1,7 @@ +/** + * @license MIT + */ + import { assert } from 'chai'; import { CircularList } from './CircularList'; diff --git a/src/utils/CircularList.ts b/src/utils/CircularList.ts index 54850ab7..373d78b0 100644 --- a/src/utils/CircularList.ts +++ b/src/utils/CircularList.ts @@ -4,6 +4,7 @@ * @module xterm/utils/CircularList * @license MIT */ + import { EventEmitter } from '../EventEmitter'; import { ICircularList } from '../Interfaces'; diff --git a/src/utils/DomElementObjectPool.test.ts b/src/utils/DomElementObjectPool.test.ts index 7298f192..5a5d8a78 100644 --- a/src/utils/DomElementObjectPool.test.ts +++ b/src/utils/DomElementObjectPool.test.ts @@ -1,3 +1,7 @@ +/** + * @license MIT + */ + import { assert } from 'chai'; import { DomElementObjectPool } from './DomElementObjectPool'; diff --git a/src/utils/TestUtils.ts b/src/utils/TestUtils.ts index 51caa8fe..fcff2dcd 100644 --- a/src/utils/TestUtils.ts +++ b/src/utils/TestUtils.ts @@ -1,4 +1,8 @@ -import { ITerminal, IBuffer, IBufferSet, IBrowser, ICharMeasure, ISelectionManager, ITerminalOptions, IListenerType } from '../Interfaces'; +/** + * @license MIT + */ + +import { ITerminal, IBuffer, IBufferSet, IBrowser, ICharMeasure, ISelectionManager, ITerminalOptions, IListenerType, IInputHandlingTerminal, IViewport, ICircularList } from '../Interfaces'; import { LineData } from '../Types'; export class MockTerminal implements ITerminal { @@ -20,7 +24,6 @@ export class MockTerminal implements ITerminal { scrollback: number; buffers: IBufferSet; buffer: IBuffer; - handler(data: string): void { throw new Error('Method not implemented.'); } @@ -56,3 +59,125 @@ export class MockTerminal implements ITerminal { return line; } } + +export class MockInputHandlingTerminal implements IInputHandlingTerminal { + element: HTMLElement; + options: ITerminalOptions = {}; + cols: number; + rows: number; + charset: { [key: string]: string; }; + gcharset: number; + glevel: number; + charsets: { [key: string]: string; }[]; + applicationKeypad: boolean; + applicationCursor: boolean; + originMode: boolean; + insertMode: boolean; + wraparoundMode: boolean; + defAttr: number; + curAttr: number; + prefix: string; + savedCols: number; + x10Mouse: boolean; + vt200Mouse: boolean; + normalMouse: boolean; + mouseEvents: boolean; + sendFocus: boolean; + utfMouse: boolean; + sgrMouse: boolean; + urxvtMouse: boolean; + cursorHidden: boolean; + buffers: IBufferSet; + buffer: IBuffer = new MockBuffer(); + viewport: IViewport; + selectionManager: ISelectionManager; + focus(): void { + throw new Error('Method not implemented.'); + } + convertEol: boolean; + updateRange(y: number): void { + throw new Error('Method not implemented.'); + } + scroll(isWrapped?: boolean): void { + throw new Error('Method not implemented.'); + } + nextStop(x?: number): number { + throw new Error('Method not implemented.'); + } + setgLevel(g: number): void { + throw new Error('Method not implemented.'); + } + eraseAttr() { + throw new Error('Method not implemented.'); + } + eraseRight(x: number, y: number): void { + throw new Error('Method not implemented.'); + } + eraseLine(y: number): void { + throw new Error('Method not implemented.'); + } + eraseLeft(x: number, y: number): void { + throw new Error('Method not implemented.'); + } + blankLine(cur?: boolean, isWrapped?: boolean): [number, string, number][] { + throw new Error('Method not implemented.'); + } + prevStop(x?: number): number { + throw new Error('Method not implemented.'); + } + is(term: string): boolean { + throw new Error('Method not implemented.'); + } + send(data: string): void { + throw new Error('Method not implemented.'); + } + setgCharset(g: number, charset: { [key: string]: string; }): void { + throw new Error('Method not implemented.'); + } + resize(x: number, y: number): void { + throw new Error('Method not implemented.'); + } + log(text: string, data?: any): void { + throw new Error('Method not implemented.'); + } + reset(): void { + throw new Error('Method not implemented.'); + } + showCursor(): void { + throw new Error('Method not implemented.'); + } + refresh(start: number, end: number): void { + throw new Error('Method not implemented.'); + } + matchColor(r1: number, g1: number, b1: number) { + throw new Error('Method not implemented.'); + } + error(text: string, data?: any): void { + throw new Error('Method not implemented.'); + } + setOption(key: string, value: any): void { + this.options[key] = value; + } + on(type: string, listener: IListenerType): void { + throw new Error('Method not implemented.'); + } + off(type: string, listener: IListenerType): void { + throw new Error('Method not implemented.'); + } + emit(type: string, data?: any): void { + throw new Error('Method not implemented.'); + } +} + +export class MockBuffer implements IBuffer { + lines: ICircularList<[number, string, number][]>; + ydisp: number; + ybase: number; + y: number; + x: number; + tabs: any; + scrollBottom: number; + scrollTop: number; + savedY: number; + savedX: number; +} diff --git a/src/xterm.ts b/src/xterm.ts index 0c2b7319..75751865 100644 --- a/src/xterm.ts +++ b/src/xterm.ts @@ -1,3 +1,7 @@ +/** + * @license MIT + */ + import { Terminal } from './Terminal'; module.exports = Terminal;