This repository was archived by the owner on May 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathCursorTest.re
More file actions
129 lines (98 loc) · 3.56 KB
/
Copy pathCursorTest.re
File metadata and controls
129 lines (98 loc) · 3.56 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
open EditorCoreTypes;
open Vim;
open TestFramework;
let resetBuffer = () => Helpers.resetBuffer("test/lines_100.txt");
let input = s => ignore(Vim.input(s));
describe("Cursor", ({describe, _}) => {
describe("setLocation", ({test, _}) => {
test("cursor location gets updated", ({expect}) => {
let _ = resetBuffer();
Cursor.setLocation(~line=Index.zero, ~column=Index.(zero + 1));
expect.int((Cursor.getLine() :> int)).toBe(0);
expect.int((Cursor.getColumn() :> int)).toBe(1);
Cursor.setLocation(
~line=Index.fromOneBased(3),
~column=Index.fromZeroBased(4),
);
expect.int((Cursor.getLine() :> int)).toBe(2);
expect.int((Cursor.getColumn() :> int)).toBe(4);
});
test(
"topline should be updated when moving outside the viewport",
({expect}) => {
let _ = resetBuffer();
let topLineEvents = ref([]);
let unsubscribe =
Window.onTopLineChanged(topline =>
topLineEvents := [topline, ...topLineEvents^]
);
Window.setWidth(80);
Window.setHeight(40);
Window.setTopLeft(1, 1);
Cursor.setLocation(~line=Index.zero, ~column=Index.(zero + 1));
Cursor.setLocation(
~line=Index.fromOneBased(90),
~column=Index.(zero + 1),
);
expect.int(Window.getTopLine()).toBe(61);
expect.int(List.length(topLineEvents^)).toBe(1);
expect.int(List.hd(topLineEvents^)).toBe(61);
unsubscribe();
});
test(
"topline should not be updated when moving inside the viewport",
({expect}) => {
Window.setWidth(80);
Window.setHeight(40);
let _ = resetBuffer();
Window.setTopLeft(71, 4);
Cursor.setLocation(
~line=Index.fromOneBased(90),
~column=Index.(zero + 1),
);
expect.int(Window.getTopLine()).toBe(71);
});
});
describe("normal mode", ({test, _}) => {
test("j / k", ({expect}) => {
let _ = resetBuffer();
let cursorMoves: ref(list(Location.t)) = ref([]);
let dispose = Cursor.onMoved(p => cursorMoves := [p, ...cursorMoves^]);
expect.int((Cursor.getLine() :> int)).toBe(0);
expect.int((Cursor.getColumn() :> int)).toBe(0);
expect.int(List.length(cursorMoves^)).toBe(0);
input("j");
expect.int((Cursor.getLine() :> int)).toBe(1);
expect.int((Cursor.getColumn() :> int)).toBe(0);
expect.int(List.length(cursorMoves^)).toBe(1);
input("j");
expect.int((Cursor.getLine() :> int)).toBe(2);
expect.int((Cursor.getColumn() :> int)).toBe(0);
expect.int(List.length(cursorMoves^)).toBe(2);
input("2");
input("k");
expect.int((Cursor.getLine() :> int)).toBe(0);
expect.int((Cursor.getColumn() :> int)).toBe(0);
expect.int(List.length(cursorMoves^)).toBe(3);
dispose();
});
test("gg / G", ({expect}) => {
let _ = resetBuffer();
let cursorMoves: ref(list(Location.t)) = ref([]);
let dispose = Cursor.onMoved(p => cursorMoves := [p, ...cursorMoves^]);
expect.int((Cursor.getLine() :> int)).toBe(0);
expect.int((Cursor.getColumn() :> int)).toBe(0);
expect.int(List.length(cursorMoves^)).toBe(0);
input("G");
expect.int((Cursor.getLine() :> int)).toBe(99);
expect.int((Cursor.getColumn() :> int)).toBe(0);
expect.int(List.length(cursorMoves^)).toBe(1);
input("g");
input("g");
expect.int((Cursor.getLine() :> int)).toBe(0);
expect.int((Cursor.getColumn() :> int)).toBe(0);
expect.int(List.length(cursorMoves^)).toBe(2);
dispose();
});
});
});