4 import { assert } from 'chai';
5 import { ITerminal } from './Interfaces';
6 import { SelectionModel } from './SelectionModel';
8 class TestSelectionModel extends SelectionModel {
15 public areSelectionValuesReversed(): boolean { return this._areSelectionValuesReversed(); }
18 describe('SelectionManager', () => {
20 let document: Document;
22 let terminal: ITerminal;
23 let model: TestSelectionModel;
26 terminal = <any>{ cols: 80, rows: 2, ybase: 0 };
27 model = new TestSelectionModel(terminal);
30 describe('clearSelection', () => {
31 it('should clear the final selection', () => {
32 model.selectionStart = [0, 0];
33 model.selectionEnd = [10, 2];
34 assert.deepEqual(model.finalSelectionStart, [0, 0]);
35 assert.deepEqual(model.finalSelectionEnd, [10, 2]);
36 model.clearSelection();
37 assert.deepEqual(model.finalSelectionStart, null);
38 assert.deepEqual(model.finalSelectionEnd, null);
42 describe('_areSelectionValuesReversed', () => {
43 it('should return true when the selection end is before selection start', () => {
44 model.selectionStart = [1, 0];
45 model.selectionEnd = [0, 0];
46 assert.equal(model.areSelectionValuesReversed(), true);
47 model.selectionStart = [10, 2];
48 model.selectionEnd = [0, 0];
49 assert.equal(model.areSelectionValuesReversed(), true);
51 it('should return false when the selection end is after selection start', () => {
52 model.selectionStart = [0, 0];
53 model.selectionEnd = [1, 0];
54 assert.equal(model.areSelectionValuesReversed(), false);
55 model.selectionStart = [0, 0];
56 model.selectionEnd = [10, 2];
57 assert.equal(model.areSelectionValuesReversed(), false);
61 describe('onTrim', () => {
62 it('should trim a portion of the selection when a part of it is trimmed', () => {
63 model.selectionStart = [0, 0];
64 model.selectionEnd = [10, 2];
66 assert.deepEqual(model.finalSelectionStart, [0, 0]);
67 assert.deepEqual(model.finalSelectionEnd, [10, 1]);
69 assert.deepEqual(model.finalSelectionStart, [0, 0]);
70 assert.deepEqual(model.finalSelectionEnd, [10, 0]);
72 it('should clear selection when it is trimmed in its entirety', () => {
73 model.selectionStart = [0, 0];
74 model.selectionEnd = [10, 0];
76 assert.deepEqual(model.finalSelectionStart, null);
77 assert.deepEqual(model.finalSelectionEnd, null);
81 describe('finalSelectionStart', () => {
82 it('should return the start of the buffer if select all is active', () => {
83 model.isSelectAllActive = true;
84 assert.deepEqual(model.finalSelectionStart, [0, 0]);
86 it('should return selection start if there is no selection end', () => {
87 model.selectionStart = [2, 2];
88 assert.deepEqual(model.finalSelectionStart, [2, 2]);
90 it('should return selection end if values are reversed', () => {
91 model.selectionStart = [2, 2];
92 model.selectionEnd = [3, 2];
93 assert.deepEqual(model.finalSelectionStart, [2, 2]);
94 model.selectionEnd = [1, 2];
95 assert.deepEqual(model.finalSelectionStart, [1, 2]);
99 describe('finalSelectionEnd', () => {
100 it('should return the end of the buffer if select all is active', () => {
101 model.isSelectAllActive = true;
102 assert.deepEqual(model.finalSelectionEnd, [79, 1]);
104 it('should return null if there is no selection start', () => {
105 assert.equal(model.finalSelectionEnd, null);
106 model.selectionEnd = [1, 2];
107 assert.equal(model.finalSelectionEnd, null);
109 it('should return selection start + length if there is no selection end', () => {
110 model.selectionStart = [2, 2];
111 model.selectionStartLength = 2;
112 assert.deepEqual(model.finalSelectionEnd, [4, 2]);
114 it('should return selection start + length if values are reversed', () => {
115 model.selectionStart = [2, 2];
116 model.selectionStartLength = 2;
117 model.selectionEnd = [2, 1];
118 assert.deepEqual(model.finalSelectionEnd, [4, 2]);
120 it('should return selection start + length if selection end is inside the start selection', () => {
121 model.selectionStart = [2, 2];
122 model.selectionStartLength = 2;
123 model.selectionEnd = [3, 2];
124 assert.deepEqual(model.finalSelectionEnd, [4, 2]);
126 it('should return selection end if selection end is after selection start + length', () => {
127 model.selectionStart = [2, 2];
128 model.selectionStartLength = 2;
129 model.selectionEnd = [5, 2];
130 assert.deepEqual(model.finalSelectionEnd, [5, 2]);