]>
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'; | |
de82bd00 | 7 | import {BufferSet} from './BufferSet'; |
f03d00a4 | 8 | import { MockTerminal } from './utils/TestUtils'; |
b81c165b DI |
9 | |
10 | class TestSelectionModel extends SelectionModel { | |
11 | constructor( | |
12 | terminal: ITerminal | |
13 | ) { | |
14 | super(terminal); | |
15 | } | |
b81c165b DI |
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(() => { | |
f03d00a4 DI |
26 | terminal = new MockTerminal(); |
27 | terminal.cols = 80; | |
28 | terminal.rows = 2; | |
de82bd00 OA |
29 | terminal.scrollback = 10; |
30 | terminal.buffers = new BufferSet(terminal); | |
31 | terminal.buffer = terminal.buffers.active; | |
32 | ||
b81c165b DI |
33 | model = new TestSelectionModel(terminal); |
34 | }); | |
35 | ||
36 | describe('clearSelection', () => { | |
37 | it('should clear the final selection', () => { | |
38 | model.selectionStart = [0, 0]; | |
39 | model.selectionEnd = [10, 2]; | |
40 | assert.deepEqual(model.finalSelectionStart, [0, 0]); | |
41 | assert.deepEqual(model.finalSelectionEnd, [10, 2]); | |
42 | model.clearSelection(); | |
43 | assert.deepEqual(model.finalSelectionStart, null); | |
44 | assert.deepEqual(model.finalSelectionEnd, null); | |
45 | }); | |
46 | }); | |
47 | ||
4b170ca4 | 48 | describe('areSelectionValuesReversed', () => { |
b81c165b DI |
49 | it('should return true when the selection end is before selection start', () => { |
50 | model.selectionStart = [1, 0]; | |
51 | model.selectionEnd = [0, 0]; | |
52 | assert.equal(model.areSelectionValuesReversed(), true); | |
53 | model.selectionStart = [10, 2]; | |
54 | model.selectionEnd = [0, 0]; | |
55 | assert.equal(model.areSelectionValuesReversed(), true); | |
56 | }); | |
57 | it('should return false when the selection end is after selection start', () => { | |
58 | model.selectionStart = [0, 0]; | |
59 | model.selectionEnd = [1, 0]; | |
60 | assert.equal(model.areSelectionValuesReversed(), false); | |
61 | model.selectionStart = [0, 0]; | |
62 | model.selectionEnd = [10, 2]; | |
63 | assert.equal(model.areSelectionValuesReversed(), false); | |
64 | }); | |
65 | }); | |
66 | ||
67 | describe('onTrim', () => { | |
68 | it('should trim a portion of the selection when a part of it is trimmed', () => { | |
69 | model.selectionStart = [0, 0]; | |
70 | model.selectionEnd = [10, 2]; | |
71 | model.onTrim(1); | |
72 | assert.deepEqual(model.finalSelectionStart, [0, 0]); | |
73 | assert.deepEqual(model.finalSelectionEnd, [10, 1]); | |
74 | model.onTrim(1); | |
75 | assert.deepEqual(model.finalSelectionStart, [0, 0]); | |
76 | assert.deepEqual(model.finalSelectionEnd, [10, 0]); | |
77 | }); | |
78 | it('should clear selection when it is trimmed in its entirety', () => { | |
79 | model.selectionStart = [0, 0]; | |
80 | model.selectionEnd = [10, 0]; | |
81 | model.onTrim(1); | |
82 | assert.deepEqual(model.finalSelectionStart, null); | |
83 | assert.deepEqual(model.finalSelectionEnd, null); | |
84 | }); | |
85 | }); | |
86 | ||
87 | describe('finalSelectionStart', () => { | |
88 | it('should return the start of the buffer if select all is active', () => { | |
89 | model.isSelectAllActive = true; | |
90 | assert.deepEqual(model.finalSelectionStart, [0, 0]); | |
91 | }); | |
92 | it('should return selection start if there is no selection end', () => { | |
93 | model.selectionStart = [2, 2]; | |
94 | assert.deepEqual(model.finalSelectionStart, [2, 2]); | |
95 | }); | |
96 | it('should return selection end if values are reversed', () => { | |
97 | model.selectionStart = [2, 2]; | |
98 | model.selectionEnd = [3, 2]; | |
99 | assert.deepEqual(model.finalSelectionStart, [2, 2]); | |
100 | model.selectionEnd = [1, 2]; | |
101 | assert.deepEqual(model.finalSelectionStart, [1, 2]); | |
102 | }); | |
103 | }); | |
104 | ||
105 | describe('finalSelectionEnd', () => { | |
106 | it('should return the end of the buffer if select all is active', () => { | |
107 | model.isSelectAllActive = true; | |
28ed7772 | 108 | assert.deepEqual(model.finalSelectionEnd, [80, 1]); |
b81c165b DI |
109 | }); |
110 | it('should return null if there is no selection start', () => { | |
111 | assert.equal(model.finalSelectionEnd, null); | |
112 | model.selectionEnd = [1, 2]; | |
113 | assert.equal(model.finalSelectionEnd, null); | |
114 | }); | |
115 | it('should return selection start + length if there is no selection end', () => { | |
116 | model.selectionStart = [2, 2]; | |
117 | model.selectionStartLength = 2; | |
118 | assert.deepEqual(model.finalSelectionEnd, [4, 2]); | |
119 | }); | |
120 | it('should return selection start + length if values are reversed', () => { | |
121 | model.selectionStart = [2, 2]; | |
122 | model.selectionStartLength = 2; | |
123 | model.selectionEnd = [2, 1]; | |
124 | assert.deepEqual(model.finalSelectionEnd, [4, 2]); | |
125 | }); | |
126 | it('should return selection start + length if selection end is inside the start selection', () => { | |
127 | model.selectionStart = [2, 2]; | |
128 | model.selectionStartLength = 2; | |
129 | model.selectionEnd = [3, 2]; | |
130 | assert.deepEqual(model.finalSelectionEnd, [4, 2]); | |
131 | }); | |
132 | it('should return selection end if selection end is after selection start + length', () => { | |
133 | model.selectionStart = [2, 2]; | |
134 | model.selectionStartLength = 2; | |
135 | model.selectionEnd = [5, 2]; | |
136 | assert.deepEqual(model.finalSelectionEnd, [5, 2]); | |
137 | }); | |
138 | }); | |
139 | }); |