-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuffer_test.go
More file actions
232 lines (212 loc) · 5.98 KB
/
buffer_test.go
File metadata and controls
232 lines (212 loc) · 5.98 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
package preditor
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestSearch(t *testing.T) {
matched := matchPatternCaseInsensitive([]byte("Hello World"), []byte("Hell"))
assert.Equal(t, [][]int{{0, 3}}, matched)
}
// func Test_Gotoline(t *testing.T) {}
// ///////////// These are the buggy ones
func Test_BufferInsertChar(t *testing.T) {
bufferView := BufferView{
Buffer: &Buffer{
File: "",
Content: []byte("12"),
CRLF: false,
},
Cursor: Cursor{
Point: 0,
Mark: 0,
},
ActionStack: NewStack[BufferAction](10),
}
BufferInsertChar(&bufferView, '0')
assert.Equal(t, []byte("012"), bufferView.Buffer.Content)
bufferView.Cursor.SetBoth(3)
BufferInsertChar(&bufferView, '3')
assert.Equal(t, []byte("0123"), bufferView.Buffer.Content)
RevertLastBufferAction(&bufferView)
assert.Equal(t, []byte("012"), bufferView.Buffer.Content)
RevertLastBufferAction(&bufferView)
assert.Equal(t, []byte("12"), bufferView.Buffer.Content)
}
func Test_RemoveRange(t *testing.T) {
bufferView := BufferView{
Buffer: &Buffer{
File: "",
Content: []byte("012345678\n012345678"),
CRLF: false,
},
Cursor: Cursor{
Point: 2,
Mark: 2,
},
ActionStack: NewStack[BufferAction](10),
}
bufferView.RemoveRange(3, 8, true)
assert.Equal(t, "0128\n012345678", string(bufferView.Buffer.Content))
RevertLastBufferAction(&bufferView)
assert.Equal(t, "012345678\n012345678", string(bufferView.Buffer.Content))
}
func Test_KillLine(t *testing.T) {
bufferView := BufferView{
Buffer: &Buffer{
File: "",
Content: []byte("012345678\n012345678"),
CRLF: false,
},
Cursor: Cursor{
Point: 2,
Mark: 2,
},
ActionStack: NewStack[BufferAction](10),
}
bufferView.calcRenderState()
KillLine(&bufferView)
assert.Equal(t, "01\n012345678", string(bufferView.Buffer.Content))
RevertLastBufferAction(&bufferView)
assert.Equal(t, "012345678\n012345678", string(bufferView.Buffer.Content))
}
func Test_Copy(t *testing.T) {
t.Run("test_copy_selection", func(t *testing.T) {
bufferView := BufferView{
Buffer: &Buffer{
File: "",
Content: []byte("012345678\n012345678"),
CRLF: false,
},
Cursor: Cursor{
Point: 2,
Mark: 5,
},
ActionStack: NewStack[BufferAction](10),
}
Copy(&bufferView)
copiedValue := GetClipboardContent()
assert.Equal(t, "2345", string(copiedValue))
})
t.Run("test_copy_line", func(t *testing.T) {
bufferView := BufferView{
Buffer: &Buffer{
File: "",
Content: []byte("012345678\n012345678"),
CRLF: false,
},
Cursor: Cursor{
Point: 2,
Mark: 2,
},
ActionStack: NewStack[BufferAction](10),
}
bufferView.calcRenderState()
Copy(&bufferView)
copiedValue := GetClipboardContent()
assert.Equal(t, "012345678\n", string(copiedValue))
})
}
func Test_Paste(t *testing.T) {
bufferView := BufferView{
Buffer: &Buffer{
File: "",
Content: []byte("01\n012345678"),
CRLF: false,
},
Cursor: Cursor{
Point: 2,
Mark: 2,
},
ActionStack: NewStack[BufferAction](10),
}
WriteToClipboard([]byte("2345678"))
Paste(&bufferView)
assert.Equal(t, "012345678\n012345678", string(bufferView.Buffer.Content))
RevertLastBufferAction(&bufferView)
assert.Equal(t, "01\n012345678", string(bufferView.Buffer.Content))
}
func Test_DeleteCharBackward(t *testing.T) {
bufferView := BufferView{
Buffer: &Buffer{
File: "",
Content: []byte("012345678\n012345678"),
CRLF: false,
},
Cursor: Cursor{
Point: 2,
Mark: 2,
},
ActionStack: NewStack[BufferAction](10),
}
DeleteCharBackward(&bufferView)
assert.Equal(t, "02345678\n012345678", string(bufferView.Buffer.Content))
RevertLastBufferAction(&bufferView)
assert.Equal(t, "012345678\n012345678", string(bufferView.Buffer.Content))
}
func Test_DeleteCharForeward(t *testing.T) {
bufferView := BufferView{
Buffer: &Buffer{
File: "",
Content: []byte("012345678\n012345678"),
CRLF: false,
},
Cursor: Cursor{
Point: 2,
Mark: 2,
},
ActionStack: NewStack[BufferAction](10),
}
DeleteCharForward(&bufferView)
assert.Equal(t, "01345678\n012345678", string(bufferView.Buffer.Content))
RevertLastBufferAction(&bufferView)
assert.Equal(t, "012345678\n012345678", string(bufferView.Buffer.Content))
}
func Test_WordAtPoint(t *testing.T) {
bufferView := BufferView{
Buffer: &Buffer{
File: "",
Content: []byte("hello world"),
CRLF: false,
},
Cursor: Cursor{
Point: 2,
Mark: 2,
},
ActionStack: NewStack[BufferAction](10),
}
start, end := WordAtPoint(&bufferView)
assert.Equal(t, 0, start)
assert.Equal(t, 4, end)
}
//func Test_LeftWord(t *testing.T) {}
//func Test_RightWord(t *testing.T) {}
//func Test_DeleteWordBackward(t *testing.T) {}
//func Test_Indent(t *testing.T) {}
//func Test_ScrollUp(t *testing.T) {}
//func Test_ScrollToTop(t *testing.T) {}
//func Test_ScrollToBottom(t *testing.T) {}
//func Test_ScrollDown(t *testing.T) {}
//func Test_PointLeft(t *testing.T) {}
//func Test_PointRight(t *testing.T) {}
//func Test_PointUp(t *testing.T) {}
//func Test_PointDown(t *testing.T) {}
//func Test_CentralizePoint(t *testing.T) {}
//func Test_PointToBeginningOfLine(t *testing.T) {}
//func Test_PointToEndOfLine(t *testing.T) {}
//func Test_PointToMatchingChar(t *testing.T) {}
//func Test_MarkRight(t *testing.T) {}
//func Test_MarkLeft(t *testing.T) {}
//func Test_MarkUp(t *testing.T) {}
//func Test_MarkDown(t *testing.T) {}
//func Test_MarkPreviousWord(t *testing.T) {}
//func Test_MarkNextWord(t *testing.T) {}
//func Test_MarkToEndOfLine(t *testing.T) {}
//func Test_MarkToBeginningOfLine(t *testing.T) {}
//func Test_MarkToMatchingChar(t *testing.T) {}
//func Test_PointForwardWord(t *testing.T) {}
//func Test_PointBackwardWord(t *testing.T) {}
//func Test_Copy(t *testing.T) {}
//func Test_Search(t *testing.T) {}
//func Test_QueryReplace(t *testing.T) {}
//func Test_IsvalidCursorPosition(t *testing.T) {}
//func Test_AnotherSelectionOnMatch(t *testing.T) {}