-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathvariable-segment.vim
More file actions
451 lines (387 loc) · 10.7 KB
/
variable-segment.vim
File metadata and controls
451 lines (387 loc) · 10.7 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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
filetype plugin on
runtime! plugin/textobj/variable-segment.vim
describe 'iv'
it 'selects between underscores'
put! = 'foo_bar_baz'
normal! 6|
normal civquux
Expect getline(1) == 'foo_quux_baz'
end
it 'selects leading sections'
put! = 'bag_of_spam'
normal! 2|
normal civjar
Expect getline(1) == 'jar_of_spam'
end
it 'selects ending sections'
put! = 'bag_of_spam'
normal! 9|
normal civbeans
Expect getline(1) == 'bag_of_beans'
end
it 'selects between small camels'
put! = 'eggsAndCheese'
normal! 6|
normal civOr
Expect getline(1) == 'eggsOrCheese'
end
it 'considers numbers to be capitals on the left boundary'
put! = '22Skidoo'
normal! 5|
normal civProblemsButThisTestAintOne
Expect getline(1) == '22ProblemsButThisTestAintOne'
end
it 'considers numbers to be capitals on the right boundary'
put! = 'Catch22'
normal! 2|
normal civSplit
Expect getline(1) == 'Split22'
end
it 'considers numbers to be a single group'
put! = 'ABC123DEF'
normal! 5|
normal civ456
Expect getline(1) == 'ABC456DEF'
end
it 'recognizes weird capital runs considering the last to be a new group'
put! = 'MyHTMLParser'
normal! 4|
normal civXML
Expect getline(1) == 'MyXMLParser'
end
it 'recognizes weird capital runs on the left'
put! = 'MyHTMLParser'
normal! 7|
normal civNightmare
Expect getline(1) == 'MyHTMLNightmare'
end
it 'ignores leading snake underscores'
put! = '_spam_eggs'
normal! 3|
normal civquux
Expect getline(1) == '_quux_eggs'
end
it 'ignores leading camel underscores'
put! = '_doCoolThings'
normal! 3|
normal civhowMany
Expect getline(1) == '_howManyCoolThings'
end
it 'ignores multiple leading underscores'
put! = '__doCoolThings'
normal! 3|
normal civhowMany
Expect getline(1) == '__howManyCoolThings'
end
it 'selects leading small camels and does not swap case'
put! = 'greatQuuxThings'
normal! 3|
normal civdecent
Expect getline(1) == 'decentQuuxThings'
end
it 'selects leading large camels and preserves case'
put! = 'BigCat'
normal! 2|
normal civSmall
Expect getline(1) == 'SmallCat'
end
it 'works on CONSTANT_SECTIONS'
put! = 'SPAM_AND_EGGS'
normal! 7|
normal civOR
Expect getline(1) == 'SPAM_OR_EGGS'
end
it 'works on mixed variables'
put! = 'getFoo_AndBar'
normal! 10|
normal civOr
Expect getline(1) == 'getFoo_OrBar'
end
it 'can match on the underscore'
put! = 'hello_world'
normal! 6|
normal civstrange
Expect getline(1) == 'strange_world'
end
it 'can match on the left snake boundary'
put! = 'hello_world'
normal! 0
normal civgoodbye_cruel
Expect getline(1) == 'goodbye_cruel_world'
end
it 'can match on the right snake boundary'
put! = 'hello_world'
normal! $
normal civhello
Expect getline(1) == 'hello_hello'
end
it 'can match on the left camel boundary'
put! = 'helloWorld'
normal! 0
normal civgoodbyeCruel
Expect getline(1) == 'goodbyeCruelWorld'
end
it 'can match on the right camel boundary'
put! = 'helloWorld'
normal! $
normal civBeautiful
Expect getline(1) == 'helloBeautiful'
end
it 'selects single letter snake case sections'
put! = 'a_thing_I_like'
normal! 0
normal civthe
Expect getline(1) == 'the_thing_I_like'
end
it 'selects single letter camel sections'
put! = 'aThingILike'
normal! 0
normal civthe
Expect getline(1) == 'theThingILike'
end
it 'selects segments after single letter snake case sections'
put! = 'a_thing_I_like'
normal! 3|
normal civtest
Expect getline(1) == 'a_test_I_like'
end
it 'selects segments after single letter camel sections'
put! = 'aThingILike'
normal! 2|
normal civTest
Expect getline(1) == 'aTestILike'
end
it 'does not cross left snake boundaries'
put! = 'foo_bar baz_quux'
normal! 10|
normal civspaz
Expect getline(1) == 'foo_bar spaz_quux'
end
it 'does not cross right snake boundaries'
put! = 'foo_bar baz_quux'
normal! 6|
normal civlala
Expect getline(1) == 'foo_lala baz_quux'
end
it 'does not cross left camel boundaries'
put! = 'fooBar bazQuux'
normal! 10|
normal civFez
Expect getline(1) == 'fooBar FezQuux'
end
it 'does not cross right camel boundaries'
put! = 'fooBar bazQuux'
normal! 6|
normal civtHill
Expect getline(1) == 'footHill bazQuux'
end
it 'supports counts'
put! = 'foo_bar_baz_quux_spam'
normal! 6|
normal c3iveggs
Expect getline(1) == 'foo_eggs_spam'
end
it 'works in the degenerate case'
put! = 'thing another'
normal 2|
normal civone
Expect getline(1) == 'one another'
end
it 'respects &iskeyword'
let original = &iskeyword
set iskeyword=a-z,_,'
put! = 'bag_of_spam'' stuff'
normal! 9|
normal civeggs_n'
Expect getline(1) == "bag_of_eggs_n' stuff"
let &iskeyword = original
end
end
describe 'av'
it 'selects between underscores'
put! = 'foo_bar_baz'
normal! 6|
normal dav
Expect getline(1) == 'foo_baz'
end
it 'selects leading sections'
put! = 'bag_of_spam'
normal! 2|
normal dav
Expect getline(1) == 'of_spam'
end
it 'selects ending sections'
put! = 'bag_of_spam'
normal! 9|
normal dav
Expect getline(1) == 'bag_of'
end
it 'selects between small camels'
put! = 'eggsAndCheese'
normal! 6|
normal dav
Expect getline(1) == 'eggsCheese'
end
it 'considers numbers to be capitals on the left boundary'
put! = '22Skidoo'
normal! 5|
normal dav
Expect getline(1) == '22'
end
it 'considers numbers to be capitals on the right boundary'
put! = 'Catch22'
normal! 2|
normal dav
Expect getline(1) == '22'
end
it 'considers numbers to be a single group'
put! = 'ABC123DEF'
normal! 5|
normal dav
Expect getline(1) == 'ABCDEF'
end
it 'recognizes weird capital runs considering the last to be a new group'
put! = 'MyHTMLParser'
normal! 4|
normal dav
Expect getline(1) == 'MyParser'
end
it 'recognizes weird capital runs on the left'
put! = 'MyHTMLParser'
normal! 7|
normal dav
Expect getline(1) == 'MyHTML'
end
it 'ignores leading snake underscores'
put! = '_spam_eggs'
normal! 3|
normal dav
Expect getline(1) == '_eggs'
end
it 'ignores leading camel underscores'
put! = '_doCoolThings'
normal! 5|
normal dav
Expect getline(1) == '_doThings'
end
it 'ignores multiple leading underscores'
put! = '__doCoolThings'
normal! 3|
normal dav
Expect getline(1) == '__coolThings'
end
it 'selects leading small camels and swaps case'
put! = 'greatQuuxThings'
normal! 3|
normal dav
Expect getline(1) == 'quuxThings'
end
it 'selects leading small camels and swaps case even with underscores'
put! = '_greatQuuxThings'
normal! 3|
normal dav
Expect getline(1) == '_quuxThings'
end
it 'selects leading large camels and preserves case'
put! = 'BigCat'
normal! 2|
normal dav
Expect getline(1) == 'Cat'
end
it 'works on CONSTANT_SECTIONS'
put! = 'SPAM_AND_EGGS'
normal! 7|
normal dav
Expect getline(1) == 'SPAM_EGGS'
end
it 'works on mixed variables'
put! = 'bathRobe_AndBody'
normal! 5|
normal dav
Expect getline(1) == 'bathAndBody'
end
it 'can match on the underscore'
put! = 'hello_world'
normal! 6|
normal dav
Expect getline(1) == 'world'
end
it 'can match on the left snake boundary'
put! = 'hello_world'
normal! 0
normal dav
Expect getline(1) == 'world'
end
it 'can match on the right snake boundary'
put! = 'hello_world'
normal! $
normal dav
Expect getline(1) == 'hello'
end
it 'can match on the left camel boundary'
put! = 'helloWorld'
normal! 0
normal dav
Expect getline(1) == 'world'
end
it 'can match on the right camel boundary'
put! = 'helloWorld'
normal! $
normal dav
Expect getline(1) == 'hello'
end
it 'selects single letter camel sections'
put! = 'aThingILike'
normal! 0
normal dav
Expect getline(1) == 'thingILike'
end
it 'does not cross left snake boundaries'
put! = 'foo_bar baz_quux'
normal! 10|
normal dav
Expect getline(1) == 'foo_bar quux'
end
it 'does not cross right snake boundaries'
put! = 'foo_bar baz_quux'
normal! 6|
normal dav
Expect getline(1) == 'foo baz_quux'
end
it 'does not cross left camel boundaries'
put! = 'fooBar bazQuux'
normal! 10|
normal dav
Expect getline(1) == 'fooBar quux'
end
it 'supports counts'
put! = 'foo_bar_baz_quux_spam'
normal! 6|
normal d3av
Expect getline(1) == 'foo_spam'
end
it 'does not cross right camel boundaries'
put! = 'fooBar bazQuux'
normal! 6|
normal dav
Expect getline(1) == 'foo bazQuux'
end
it 'selects leading small camels and swaps case even with tildeop'
set tildeop " Vim default is notildeop
put! = 'fooBarQuux'
normal! 0
normal dav
Expect getline(1) == 'barQuux'
Expect &tildeop == 1
set notildeop
end
it 'respects &iskeyword'
let original = &iskeyword
set iskeyword=a-z,_,'
put! = 'bag_of_spam'' stuff'
normal! 9|
normal dav
Expect getline(1) == "bag_of stuff"
let &iskeyword = original
end
end