]> git.proxmox.com Git - mirror_xterm.js.git/blob - src/SelectionModel.test.ts
Merge remote-tracking branch 'ups/master' into 687_macos_ci
[mirror_xterm.js.git] / src / SelectionModel.test.ts
1 /**
2 * @license MIT
3 */
4 import { assert } from 'chai';
5 import { ITerminal } from './Interfaces';
6 import { SelectionModel } from './SelectionModel';
7
8 class TestSelectionModel extends SelectionModel {
9 constructor(
10 terminal: ITerminal
11 ) {
12 super(terminal);
13 }
14 }
15
16 describe('SelectionManager', () => {
17 let window: Window;
18 let document: Document;
19
20 let terminal: ITerminal;
21 let model: TestSelectionModel;
22
23 beforeEach(() => {
24 terminal = <any>{ cols: 80, rows: 2, ybase: 0 };
25 model = new TestSelectionModel(terminal);
26 });
27
28 describe('clearSelection', () => {
29 it('should clear the final selection', () => {
30 model.selectionStart = [0, 0];
31 model.selectionEnd = [10, 2];
32 assert.deepEqual(model.finalSelectionStart, [0, 0]);
33 assert.deepEqual(model.finalSelectionEnd, [10, 2]);
34 model.clearSelection();
35 assert.deepEqual(model.finalSelectionStart, null);
36 assert.deepEqual(model.finalSelectionEnd, null);
37 });
38 });
39
40 describe('areSelectionValuesReversed', () => {
41 it('should return true when the selection end is before selection start', () => {
42 model.selectionStart = [1, 0];
43 model.selectionEnd = [0, 0];
44 assert.equal(model.areSelectionValuesReversed(), true);
45 model.selectionStart = [10, 2];
46 model.selectionEnd = [0, 0];
47 assert.equal(model.areSelectionValuesReversed(), true);
48 });
49 it('should return false when the selection end is after selection start', () => {
50 model.selectionStart = [0, 0];
51 model.selectionEnd = [1, 0];
52 assert.equal(model.areSelectionValuesReversed(), false);
53 model.selectionStart = [0, 0];
54 model.selectionEnd = [10, 2];
55 assert.equal(model.areSelectionValuesReversed(), false);
56 });
57 });
58
59 describe('onTrim', () => {
60 it('should trim a portion of the selection when a part of it is trimmed', () => {
61 model.selectionStart = [0, 0];
62 model.selectionEnd = [10, 2];
63 model.onTrim(1);
64 assert.deepEqual(model.finalSelectionStart, [0, 0]);
65 assert.deepEqual(model.finalSelectionEnd, [10, 1]);
66 model.onTrim(1);
67 assert.deepEqual(model.finalSelectionStart, [0, 0]);
68 assert.deepEqual(model.finalSelectionEnd, [10, 0]);
69 });
70 it('should clear selection when it is trimmed in its entirety', () => {
71 model.selectionStart = [0, 0];
72 model.selectionEnd = [10, 0];
73 model.onTrim(1);
74 assert.deepEqual(model.finalSelectionStart, null);
75 assert.deepEqual(model.finalSelectionEnd, null);
76 });
77 });
78
79 describe('finalSelectionStart', () => {
80 it('should return the start of the buffer if select all is active', () => {
81 model.isSelectAllActive = true;
82 assert.deepEqual(model.finalSelectionStart, [0, 0]);
83 });
84 it('should return selection start if there is no selection end', () => {
85 model.selectionStart = [2, 2];
86 assert.deepEqual(model.finalSelectionStart, [2, 2]);
87 });
88 it('should return selection end if values are reversed', () => {
89 model.selectionStart = [2, 2];
90 model.selectionEnd = [3, 2];
91 assert.deepEqual(model.finalSelectionStart, [2, 2]);
92 model.selectionEnd = [1, 2];
93 assert.deepEqual(model.finalSelectionStart, [1, 2]);
94 });
95 });
96
97 describe('finalSelectionEnd', () => {
98 it('should return the end of the buffer if select all is active', () => {
99 model.isSelectAllActive = true;
100 assert.deepEqual(model.finalSelectionEnd, [80, 1]);
101 });
102 it('should return null if there is no selection start', () => {
103 assert.equal(model.finalSelectionEnd, null);
104 model.selectionEnd = [1, 2];
105 assert.equal(model.finalSelectionEnd, null);
106 });
107 it('should return selection start + length if there is no selection end', () => {
108 model.selectionStart = [2, 2];
109 model.selectionStartLength = 2;
110 assert.deepEqual(model.finalSelectionEnd, [4, 2]);
111 });
112 it('should return selection start + length if values are reversed', () => {
113 model.selectionStart = [2, 2];
114 model.selectionStartLength = 2;
115 model.selectionEnd = [2, 1];
116 assert.deepEqual(model.finalSelectionEnd, [4, 2]);
117 });
118 it('should return selection start + length if selection end is inside the start selection', () => {
119 model.selectionStart = [2, 2];
120 model.selectionStartLength = 2;
121 model.selectionEnd = [3, 2];
122 assert.deepEqual(model.finalSelectionEnd, [4, 2]);
123 });
124 it('should return selection end if selection end is after selection start + length', () => {
125 model.selectionStart = [2, 2];
126 model.selectionStartLength = 2;
127 model.selectionEnd = [5, 2];
128 assert.deepEqual(model.finalSelectionEnd, [5, 2]);
129 });
130 });
131 });