*/
import jsdom = require('jsdom');
import { assert } from 'chai';
-import { ITerminal } from './Interfaces';
+import { ITerminal, ICircularList } from './Interfaces';
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';
+import { MockTerminal } from './utils/TestUtils';
class TestSelectionManager extends SelectionManager {
constructor(
terminal: ITerminal,
- buffer: CircularList<any>,
+ buffer: ICircularList<[number, string, number][]>,
rowContainer: HTMLElement,
charMeasure: CharMeasure
) {
let document: Document;
let terminal: ITerminal;
- let bufferLines: CircularList<any>;
+ let bufferLines: ICircularList<[number, string, number][]>;
let rowContainer: HTMLElement;
let selectionManager: TestSelectionManager;
dom = new jsdom.JSDOM('');
window = dom.window;
document = window.document;
- terminal = <any>{ cols: 80, rows: 2 };
+ rowContainer = document.createElement('div');
+ terminal = new MockTerminal();
+ terminal.cols = 80;
+ terminal.rows = 2;
terminal.scrollback = 100;
terminal.buffers = new BufferSet(terminal);
terminal.buffer = terminal.buffers.active;
describe('_selectWordAt', () => {
it('should expand selection for normal width chars', () => {
- bufferLines.push(stringToRow('foo bar'));
+ bufferLines.set(0, stringToRow('foo bar'));
selectionManager.selectWordAt([0, 0]);
assert.equal(selectionManager.selectionText, 'foo');
selectionManager.selectWordAt([1, 0]);
assert.equal(selectionManager.selectionText, 'bar');
});
it('should expand selection for whitespace', () => {
- bufferLines.push(stringToRow('a b'));
+ bufferLines.set(0, stringToRow('a b'));
selectionManager.selectWordAt([0, 0]);
assert.equal(selectionManager.selectionText, 'a');
selectionManager.selectWordAt([1, 0]);
});
it('should expand selection for wide characters', () => {
// Wide characters use a special format
- bufferLines.push([
+ bufferLines.set(0, [
[null, '中', 2],
[null, '', 0],
[null, '文', 2],
assert.equal(selectionManager.selectionText, 'foo');
});
it('should select up to non-path characters that are commonly adjacent to paths', () => {
- bufferLines.push(stringToRow('(cd)[ef]{gh}\'ij"'));
+ bufferLines.set(0, stringToRow('(cd)[ef]{gh}\'ij"'));
selectionManager.selectWordAt([0, 0]);
assert.equal(selectionManager.selectionText, '(cd');
selectionManager.selectWordAt([1, 0]);
describe('_selectLineAt', () => {
it('should select the entire line', () => {
- bufferLines.push(stringToRow('foo bar'));
+ bufferLines.set(0, stringToRow('foo bar'));
selectionManager.selectLineAt(0);
assert.equal(selectionManager.selectionText, 'foo bar', 'The selected text is correct');
assert.deepEqual(selectionManager.model.finalSelectionStart, [0, 0]);
describe('selectAll', () => {
it('should select the entire buffer, beyond the viewport', () => {
- bufferLines.push(stringToRow('1'));
- bufferLines.push(stringToRow('2'));
- bufferLines.push(stringToRow('3'));
- bufferLines.push(stringToRow('4'));
- bufferLines.push(stringToRow('5'));
+ bufferLines.length = 5;
+ bufferLines.set(0, stringToRow('1'));
+ bufferLines.set(1, stringToRow('2'));
+ bufferLines.set(2, stringToRow('3'));
+ bufferLines.set(3, stringToRow('4'));
+ bufferLines.set(4, stringToRow('5'));
selectionManager.selectAll();
terminal.buffer.ybase = bufferLines.length - terminal.rows;
assert.equal(selectionManager.selectionText, '1\n2\n3\n4\n5');