]>
Commit | Line | Data |
---|---|---|
b81c165b DI |
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 | public areSelectionValuesReversed(): boolean { return this._areSelectionValuesReversed(); } | |
16 | } | |
17 | ||
18 | describe('SelectionManager', () => { | |
19 | let window: Window; | |
20 | let document: Document; | |
21 | ||
22 | let terminal: ITerminal; | |
23 | let model: TestSelectionModel; | |
24 | ||
25 | beforeEach(() => { | |
26 | terminal = <any>{ cols: 80, rows: 2, ybase: 0 }; | |
27 | model = new TestSelectionModel(terminal); | |
28 | }); | |
29 | ||
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); | |
39 | }); | |
40 | }); | |
41 | ||
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); | |
50 | }); | |
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); | |
58 | }); | |
59 | }); | |
60 | ||
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]; | |
65 | model.onTrim(1); | |
66 | assert.deepEqual(model.finalSelectionStart, [0, 0]); | |
67 | assert.deepEqual(model.finalSelectionEnd, [10, 1]); | |
68 | model.onTrim(1); | |
69 | assert.deepEqual(model.finalSelectionStart, [0, 0]); | |
70 | assert.deepEqual(model.finalSelectionEnd, [10, 0]); | |
71 | }); | |
72 | it('should clear selection when it is trimmed in its entirety', () => { | |
73 | model.selectionStart = [0, 0]; | |
74 | model.selectionEnd = [10, 0]; | |
75 | model.onTrim(1); | |
76 | assert.deepEqual(model.finalSelectionStart, null); | |
77 | assert.deepEqual(model.finalSelectionEnd, null); | |
78 | }); | |
79 | }); | |
80 | ||
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]); | |
85 | }); | |
86 | it('should return selection start if there is no selection end', () => { | |
87 | model.selectionStart = [2, 2]; | |
88 | assert.deepEqual(model.finalSelectionStart, [2, 2]); | |
89 | }); | |
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]); | |
96 | }); | |
97 | }); | |
98 | ||
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]); | |
103 | }); | |
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); | |
108 | }); | |
a047359f DI |
109 | it('should return null if there is no selection end or selection start length', () => { |
110 | model.selectionStart = [1, 2]; | |
111 | assert.equal(model.finalSelectionEnd, null); | |
112 | }); | |
b81c165b DI |
113 | it('should return selection start + length if there is no selection end', () => { |
114 | model.selectionStart = [2, 2]; | |
115 | model.selectionStartLength = 2; | |
116 | assert.deepEqual(model.finalSelectionEnd, [4, 2]); | |
117 | }); | |
118 | it('should return selection start + length if values are reversed', () => { | |
119 | model.selectionStart = [2, 2]; | |
120 | model.selectionStartLength = 2; | |
121 | model.selectionEnd = [2, 1]; | |
122 | assert.deepEqual(model.finalSelectionEnd, [4, 2]); | |
123 | }); | |
124 | it('should return selection start + length if selection end is inside the start selection', () => { | |
125 | model.selectionStart = [2, 2]; | |
126 | model.selectionStartLength = 2; | |
127 | model.selectionEnd = [3, 2]; | |
128 | assert.deepEqual(model.finalSelectionEnd, [4, 2]); | |
129 | }); | |
130 | it('should return selection end if selection end is after selection start + length', () => { | |
131 | model.selectionStart = [2, 2]; | |
132 | model.selectionStartLength = 2; | |
133 | model.selectionEnd = [5, 2]; | |
134 | assert.deepEqual(model.finalSelectionEnd, [5, 2]); | |
135 | }); | |
136 | }); | |
137 | }); |