-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathSelection.spec.js
82 lines (68 loc) · 2.21 KB
/
Selection.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
describe("Selection", function() {
var CanvasTextEditor = require('../lib/CanvasTextEditor'),
Document = require('../lib/Document'),
testText = 'Line1\nLine2\nLine3',
selection;
beforeEach(function(){
selection = (new CanvasTextEditor(new Document(testText))).getSelection();
});
it("should be possible to move cursor", function() {
var pos = selection.getPosition();
// Initial position
expect(pos[0]).toEqual(0);
expect(pos[1]).toEqual(0);
// Moving in all directions clockwise
selection.moveRight(1);
pos = selection.getPosition();
expect(pos[0]).toEqual(1);
expect(pos[1]).toEqual(0);
selection.moveDown(1);
pos = selection.getPosition();
expect(pos[0]).toEqual(1);
expect(pos[1]).toEqual(1);
selection.moveLeft(1);
pos = selection.getPosition();
expect(pos[0]).toEqual(0);
expect(pos[1]).toEqual(1);
});
it("should respect document bounds", function() {
selection.moveUp(1);
var pos = selection.getPosition();
expect(pos[0]).toEqual(0);
expect(pos[1]).toEqual(0);
selection.moveLeft(1);
pos = selection.getPosition();
expect(pos[0]).toEqual(0);
expect(pos[1]).toEqual(0);
});
it("should wrap from one line to another when moving left or right", function(){
selection.moveDown(1);
selection.moveLeft(1);
var pos = selection.getPosition();
expect(pos[0]).toEqual(5);
expect(pos[1]).toEqual(0);
selection.moveRight(1);
pos = selection.getPosition();
expect(pos[0]).toEqual(0);
expect(pos[1]).toEqual(1);
});
it("should support text selection", function(){
selection.moveRight(1);
selection.moveRight(2, true);
var ranges = selection.lineRanges();
expect(ranges[0][0]).toEqual(1);
expect(ranges[0][1]).toEqual(3);
selection.moveDown(1, true);
ranges = selection.lineRanges();
expect(ranges[1][0]).toEqual(0);
expect(ranges[1][1]).toEqual(3);
selection.moveLeft(3, true);
ranges = selection.lineRanges();
expect(ranges[1][0]).toEqual(0);
expect(ranges[1][1]).toEqual(0);
selection.moveLeft(1, true);
ranges = selection.lineRanges();
expect(ranges[0][0]).toEqual(1);
expect(ranges[0][1]).toEqual(5);
});
});