From 1a2e3fb9c02a4c32df3745b41e4ee71d33eb2f3b Mon Sep 17 00:00:00 2001 From: Paris Kasidiaris Date: Sat, 15 Jul 2017 11:40:20 +0300 Subject: [PATCH] Implement tests for `Buffer` and `BufferSet` --- src/Buffer.test.ts | 31 +++++++++++++++++++++++ src/BufferSet.test.ts | 49 ++++++++++++++++++++++++++++++++++++ src/SelectionManager.test.ts | 2 +- 3 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 src/Buffer.test.ts create mode 100644 src/BufferSet.test.ts diff --git a/src/Buffer.test.ts b/src/Buffer.test.ts new file mode 100644 index 0000000000..f68baa82ac --- /dev/null +++ b/src/Buffer.test.ts @@ -0,0 +1,31 @@ +/** + * @license MIT + */ +import { assert } from 'chai'; +import { ITerminal } from './Interfaces'; +import { Buffer } from './Buffer'; +import { CircularList } from './utils/CircularList'; + +describe('Buffer', () => { + let terminal: ITerminal; + let buffer: Buffer; + + beforeEach(() => { + terminal = { + cols: 80, + rows: 24, + scrollback: 1000 + }; + buffer = new Buffer(terminal); + }); + + describe('constructor', () => { + it('should create a CircularList with max length equal to scrollback, for its lines', () => { + assert.instanceOf(buffer.lines, CircularList); + assert.equal(buffer.lines.maxLength, terminal.scrollback); + }); + it('should set the Buffer\'s scrollBottom value equal to the terminal\'s rows -1', () => { + assert.equal(buffer.scrollBottom, terminal.rows - 1); + }); + }); +}); diff --git a/src/BufferSet.test.ts b/src/BufferSet.test.ts new file mode 100644 index 0000000000..2101fbc1f4 --- /dev/null +++ b/src/BufferSet.test.ts @@ -0,0 +1,49 @@ +/** + * @license MIT + */ +import { assert } from 'chai'; +import { ITerminal } from './Interfaces'; +import { BufferSet } from './BufferSet'; +import { Buffer } from './Buffer'; + +describe('BufferSet', () => { + let terminal: ITerminal; + let bufferSet: BufferSet; + + beforeEach(() => { + terminal = { + cols: 80, + rows: 24, + scrollback: 1000 + }; + bufferSet = new BufferSet(terminal); + }); + + describe('constructor', () => { + it('should create two different buffers: alt and normal', () => { + assert.instanceOf(bufferSet.normal, Buffer); + assert.instanceOf(bufferSet.alt, Buffer); + assert.notEqual(bufferSet.normal, bufferSet.alt); + }); + }); + + describe('activateNormalBuffer', () => { + beforeEach(() => { + bufferSet.activateNormalBuffer(); + }); + + it('should set the normal buffer as the currently active buffer', () => { + assert.equal(bufferSet.active, bufferSet.normal); + }); + }); + + describe('activateAltBuffer', () => { + beforeEach(() => { + bufferSet.activateAltBuffer(); + }); + + it('should set the alt buffer as the currently active buffer', () => { + assert.equal(bufferSet.active, bufferSet.alt); + }); + }); +}); diff --git a/src/SelectionManager.test.ts b/src/SelectionManager.test.ts index f710ecc0e4..66d692ddd6 100644 --- a/src/SelectionManager.test.ts +++ b/src/SelectionManager.test.ts @@ -8,7 +8,7 @@ import { CharMeasure } from './utils/CharMeasure'; import { CircularList } from './utils/CircularList'; import { SelectionManager } from './SelectionManager'; import { SelectionModel } from './SelectionModel'; -import {BufferSet} from './BufferSet'; +import { BufferSet } from './BufferSet'; class TestSelectionManager extends SelectionManager { constructor(