]> git.r.bdr.sh - rbdr/dotfiles/blob - atom/packages/vim-mode/spec/text-objects-spec.coffee
Remove vim-unimpaired plugin
[rbdr/dotfiles] / atom / packages / vim-mode / spec / text-objects-spec.coffee
1 helpers = require './spec-helper'
2
3 describe "TextObjects", ->
4 [editor, editorElement, vimState] = []
5
6 beforeEach ->
7 vimMode = atom.packages.loadPackage('vim-mode')
8 vimMode.activateResources()
9
10 helpers.getEditorElement (element) ->
11 editorElement = element
12 editor = editorElement.getModel()
13 vimState = editorElement.vimState
14 vimState.activateNormalMode()
15 vimState.resetNormalMode()
16
17 keydown = (key, options={}) ->
18 options.element ?= editorElement
19 helpers.keydown(key, options)
20
21 describe "Text Object commands in normal mode not preceded by an operator", ->
22 beforeEach ->
23 vimState.activateNormalMode()
24
25 it "selects the appropriate text", ->
26 editor.setText("<html> text </html>")
27 editor.setCursorScreenPosition([0, 7])
28 # Users could dispatch it via the command palette
29 atom.commands.dispatch(editorElement, "vim-mode:select-inside-tags")
30 expect(editor.getSelectedScreenRange()).toEqual [[0, 6], [0, 12]]
31
32 describe "the 'iw' text object", ->
33 beforeEach ->
34 editor.setText("12345 abcde ABCDE")
35 editor.setCursorScreenPosition([0, 9])
36
37 it "applies operators inside the current word in operator-pending mode", ->
38 keydown('d')
39 keydown('i')
40 keydown('w')
41
42 expect(editor.getText()).toBe "12345 ABCDE"
43 expect(editor.getCursorScreenPosition()).toEqual [0, 6]
44 expect(vimState.getRegister('"').text).toBe "abcde"
45 expect(editorElement.classList.contains('operator-pending-mode')).toBe(false)
46 expect(editorElement.classList.contains('normal-mode')).toBe(true)
47
48 it "selects inside the current word in visual mode", ->
49 keydown('v')
50 keydown('i')
51 keydown('w')
52
53 expect(editor.getSelectedScreenRange()).toEqual [[0, 6], [0, 11]]
54
55 it "expands an existing selection in visual mode", ->
56 keydown('v')
57 keydown('l')
58 keydown('l')
59 keydown('l')
60 keydown('i')
61 keydown('w')
62
63 expect(editor.getSelectedScreenRange()).toEqual [[0, 9], [0, 17]]
64
65 it "works with multiple cursors", ->
66 editor.addCursorAtBufferPosition([0, 1])
67 keydown("v")
68 keydown("i")
69 keydown("w")
70 expect(editor.getSelectedBufferRanges()).toEqual [
71 [[0, 6], [0, 11]]
72 [[0, 0], [0, 5]]
73 ]
74
75 describe "the 'iW' text object", ->
76 beforeEach ->
77 editor.setText("12(45 ab'de ABCDE")
78 editor.setCursorScreenPosition([0, 9])
79
80 it "applies operators inside the current whole word in operator-pending mode", ->
81 keydown('d')
82 keydown('i')
83 keydown('W', shift: true)
84
85 expect(editor.getText()).toBe "12(45 ABCDE"
86 expect(editor.getCursorScreenPosition()).toEqual [0, 6]
87 expect(vimState.getRegister('"').text).toBe "ab'de"
88 expect(editorElement.classList.contains('operator-pending-mode')).toBe(false)
89 expect(editorElement.classList.contains('normal-mode')).toBe(true)
90
91 it "selects inside the current whole word in visual mode", ->
92 keydown('v')
93 keydown('i')
94 keydown('W', shift: true)
95
96 expect(editor.getSelectedScreenRange()).toEqual [[0, 6], [0, 11]]
97
98 it "expands an existing selection in visual mode", ->
99 keydown('v')
100 keydown('l')
101 keydown('l')
102 keydown('l')
103 keydown('i')
104 keydown('W', shift: true)
105
106 expect(editor.getSelectedScreenRange()).toEqual [[0, 9], [0, 17]]
107
108 describe "the 'i(' text object", ->
109 beforeEach ->
110 editor.setText("( something in here and in (here) )")
111 editor.setCursorScreenPosition([0, 9])
112
113 it "applies operators inside the current word in operator-pending mode", ->
114 keydown('d')
115 keydown('i')
116 keydown('(')
117 expect(editor.getText()).toBe "()"
118 expect(editor.getCursorScreenPosition()).toEqual [0, 1]
119 expect(editorElement.classList.contains('operator-pending-mode')).toBe(false)
120 expect(editorElement.classList.contains('normal-mode')).toBe(true)
121
122 it "applies operators inside the current word in operator-pending mode (second test)", ->
123 editor.setCursorScreenPosition([0, 29])
124 keydown('d')
125 keydown('i')
126 keydown('(')
127 expect(editor.getText()).toBe "( something in here and in () )"
128 expect(editor.getCursorScreenPosition()).toEqual [0, 28]
129 expect(editorElement.classList.contains('operator-pending-mode')).toBe(false)
130 expect(editorElement.classList.contains('normal-mode')).toBe(true)
131
132 it "works with multiple cursors", ->
133 editor.setText("( a b ) cde ( f g h ) ijk")
134 editor.setCursorBufferPosition([0, 2])
135 editor.addCursorAtBufferPosition([0, 18])
136
137 keydown("v")
138 keydown("i")
139 keydown("(")
140
141 expect(editor.getSelectedBufferRanges()).toEqual [
142 [[0, 1], [0, 6]]
143 [[0, 13], [0, 20]]
144 ]
145
146 it "expands an existing selection in visual mode", ->
147 editor.setCursorScreenPosition([0, 25])
148 keydown('v')
149 keydown('l')
150 keydown('l')
151 keydown('l')
152 keydown('l')
153 keydown('i')
154 keydown('(')
155
156 expect(editor.getSelectedScreenRange()).toEqual [[0, 25], [0, 32]]
157
158 describe "the 'i{' text object", ->
159 beforeEach ->
160 editor.setText("{ something in here and in {here} }")
161 editor.setCursorScreenPosition([0, 9])
162
163 it "applies operators inside the current word in operator-pending mode", ->
164 keydown('d')
165 keydown('i')
166 keydown('{')
167 expect(editor.getText()).toBe "{}"
168 expect(editor.getCursorScreenPosition()).toEqual [0, 1]
169 expect(editorElement.classList.contains('operator-pending-mode')).toBe(false)
170 expect(editorElement.classList.contains('normal-mode')).toBe(true)
171
172 it "applies operators inside the current word in operator-pending mode (second test)", ->
173 editor.setCursorScreenPosition([0, 29])
174 keydown('d')
175 keydown('i')
176 keydown('{')
177 expect(editor.getText()).toBe "{ something in here and in {} }"
178 expect(editor.getCursorScreenPosition()).toEqual [0, 28]
179 expect(editorElement.classList.contains('operator-pending-mode')).toBe(false)
180 expect(editorElement.classList.contains('normal-mode')).toBe(true)
181
182 it "expands an existing selection in visual mode", ->
183 editor.setCursorScreenPosition([0, 25])
184 keydown('v')
185 keydown('l')
186 keydown('l')
187 keydown('l')
188 keydown('l')
189 keydown('i')
190 keydown('{')
191
192 expect(editor.getSelectedScreenRange()).toEqual [[0, 25], [0, 32]]
193
194 describe "the 'i<' text object", ->
195 beforeEach ->
196 editor.setText("< something in here and in <here> >")
197 editor.setCursorScreenPosition([0, 9])
198
199 it "applies operators inside the current word in operator-pending mode", ->
200 keydown('d')
201 keydown('i')
202 keydown('<')
203 expect(editor.getText()).toBe "<>"
204 expect(editor.getCursorScreenPosition()).toEqual [0, 1]
205 expect(editorElement.classList.contains('operator-pending-mode')).toBe(false)
206 expect(editorElement.classList.contains('normal-mode')).toBe(true)
207
208 it "applies operators inside the current word in operator-pending mode (second test)", ->
209 editor.setCursorScreenPosition([0, 29])
210 keydown('d')
211 keydown('i')
212 keydown('<')
213 expect(editor.getText()).toBe "< something in here and in <> >"
214 expect(editor.getCursorScreenPosition()).toEqual [0, 28]
215 expect(editorElement.classList.contains('operator-pending-mode')).toBe(false)
216 expect(editorElement.classList.contains('normal-mode')).toBe(true)
217
218 it "expands an existing selection in visual mode", ->
219 editor.setCursorScreenPosition([0, 25])
220 keydown('v')
221 keydown('l')
222 keydown('l')
223 keydown('l')
224 keydown('l')
225 keydown('i')
226 keydown('<')
227
228 expect(editor.getSelectedScreenRange()).toEqual [[0, 25], [0, 32]]
229
230 describe "the 'it' text object", ->
231 beforeEach ->
232 editor.setText("<something>here</something><again>")
233 editor.setCursorScreenPosition([0, 5])
234
235 it "applies only if in the value of a tag", ->
236 keydown('d')
237 keydown('i')
238 keydown('t')
239 expect(editor.getText()).toBe "<something>here</something><again>"
240 expect(editor.getCursorScreenPosition()).toEqual [0, 5]
241 expect(editorElement.classList.contains('operator-pending-mode')).toBe(false)
242 expect(editorElement.classList.contains('normal-mode')).toBe(true)
243
244 it "applies operators inside the current word in operator-pending mode", ->
245 editor.setCursorScreenPosition([0, 13])
246 keydown('d')
247 keydown('i')
248 keydown('t')
249 expect(editor.getText()).toBe "<something></something><again>"
250 expect(editor.getCursorScreenPosition()).toEqual [0, 11]
251 expect(editorElement.classList.contains('operator-pending-mode')).toBe(false)
252 expect(editorElement.classList.contains('normal-mode')).toBe(true)
253
254 it "expands an existing selection in visual mode", ->
255 editor.setCursorScreenPosition([0, 7])
256 keydown('v')
257 keydown('6')
258 keydown('l')
259 keydown('i')
260 keydown('t')
261
262 expect(editor.getSelectedScreenRange()).toEqual [[0, 7], [0, 15]]
263
264 describe "the 'ip' text object", ->
265 beforeEach ->
266 editor.setText("\nParagraph-1\nParagraph-1\nParagraph-1\n\n")
267 editor.setCursorBufferPosition([2, 2])
268
269 it "applies operators inside the current paragraph in operator-pending mode", ->
270 keydown('y')
271 keydown('i')
272 keydown('p')
273
274 expect(editor.getText()).toBe "\nParagraph-1\nParagraph-1\nParagraph-1\n\n"
275 expect(editor.getCursorScreenPosition()).toEqual [1, 0]
276 expect(vimState.getRegister('"').text).toBe "Paragraph-1\nParagraph-1\nParagraph-1\n"
277 expect(editorElement.classList.contains('operator-pending-mode')).toBe(false)
278 expect(editorElement.classList.contains('normal-mode')).toBe(true)
279
280 it "selects inside the current paragraph in visual mode", ->
281 keydown('v')
282 keydown('i')
283 keydown('p')
284
285 expect(editor.getSelectedScreenRange()).toEqual [[1, 0], [4, 0]]
286
287 it "selects between paragraphs in visual mode if invoked on a empty line", ->
288 editor.setText("text\n\n\n\ntext\n")
289 editor.setCursorBufferPosition([1, 0])
290
291 keydown('v')
292 keydown('i')
293 keydown('p')
294
295 expect(editor.getSelectedScreenRange()).toEqual [[1, 0], [4, 0]]
296
297 it "selects all the lines", ->
298 editor.setText("text\ntext\ntext\n")
299 editor.setCursorBufferPosition([0, 0])
300
301 keydown('v')
302 keydown('i')
303 keydown('p')
304
305 expect(editor.getSelectedScreenRange()).toEqual [[0, 0], [3, 0]]
306
307 it "expands an existing selection in visual mode", ->
308 editor.setText("\nParagraph-1\nParagraph-1\nParagraph-1\n\n\nParagraph-2\nParagraph-2\nParagraph-2\n")
309 editor.setCursorBufferPosition([2, 2])
310
311 keydown('v')
312 keydown('i')
313 keydown('p')
314
315 keydown('j')
316 keydown('j')
317 keydown('j')
318 keydown('i')
319 keydown('p')
320
321 expect(editor.getSelectedScreenRange()).toEqual [[1, 0], [9, 0]]
322
323 describe "the 'ap' text object", ->
324 beforeEach ->
325 editor.setText("text\n\nParagraph-1\nParagraph-1\nParagraph-1\n\n\nmoretext")
326 editor.setCursorScreenPosition([3, 2])
327
328 it "applies operators around the current paragraph in operator-pending mode", ->
329 keydown('y')
330 keydown('a')
331 keydown('p')
332
333 expect(editor.getText()).toBe "text\n\nParagraph-1\nParagraph-1\nParagraph-1\n\n\nmoretext"
334 expect(editor.getCursorScreenPosition()).toEqual [2, 0]
335 expect(vimState.getRegister('"').text).toBe "Paragraph-1\nParagraph-1\nParagraph-1\n\n\n"
336 expect(editorElement.classList.contains('operator-pending-mode')).toBe(false)
337 expect(editorElement.classList.contains('normal-mode')).toBe(true)
338
339 it "selects around the current paragraph in visual mode", ->
340 keydown('v')
341 keydown('a')
342 keydown('p')
343
344 expect(editor.getSelectedScreenRange()).toEqual [[2, 0], [7, 0]]
345
346 it "applies operators around the next paragraph in operator-pending mode when started from a blank/only-whitespace line", ->
347 editor.setText("text\n\n\n\nParagraph-1\nParagraph-1\nParagraph-1\n\n\nmoretext")
348 editor.setCursorBufferPosition([1, 0])
349
350 keydown('y')
351 keydown('a')
352 keydown('p')
353
354 expect(editor.getText()).toBe "text\n\n\n\nParagraph-1\nParagraph-1\nParagraph-1\n\n\nmoretext"
355 expect(editor.getCursorScreenPosition()).toEqual [1, 0]
356 expect(vimState.getRegister('"').text).toBe "\n\n\nParagraph-1\nParagraph-1\nParagraph-1\n"
357 expect(editorElement.classList.contains('operator-pending-mode')).toBe(false)
358 expect(editorElement.classList.contains('normal-mode')).toBe(true)
359
360 it "selects around the next paragraph in visual mode when started from a blank/only-whitespace line", ->
361 editor.setText("text\n\n\n\nparagraph-1\nparagraph-1\nparagraph-1\n\n\nmoretext")
362 editor.setCursorBufferPosition([1, 0])
363
364 keydown('v')
365 keydown('a')
366 keydown('p')
367
368 expect(editor.getSelectedScreenRange()).toEqual [[1, 0], [7, 0]]
369
370 it "expands an existing selection in visual mode", ->
371 editor.setText("text\n\n\n\nparagraph-1\nparagraph-1\nparagraph-1\n\n\n\nparagraph-2\nparagraph-2\nparagraph-2\n\n\nmoretext")
372 editor.setCursorBufferPosition([5, 0])
373
374 keydown('v')
375 keydown('a')
376 keydown('p')
377
378 keydown('j')
379 keydown('j')
380 keydown('j')
381 keydown('i')
382 keydown('p')
383
384 expect(editor.getSelectedScreenRange()).toEqual [[4, 0], [13, 0]]
385
386 describe "the 'i[' text object", ->
387 beforeEach ->
388 editor.setText("[ something in here and in [here] ]")
389 editor.setCursorScreenPosition([0, 9])
390
391 it "applies operators inside the current word in operator-pending mode", ->
392 keydown('d')
393 keydown('i')
394 keydown('[')
395 expect(editor.getText()).toBe "[]"
396 expect(editor.getCursorScreenPosition()).toEqual [0, 1]
397 expect(editorElement.classList.contains('operator-pending-mode')).toBe(false)
398 expect(editorElement.classList.contains('normal-mode')).toBe(true)
399
400 it "applies operators inside the current word in operator-pending mode (second test)", ->
401 editor.setCursorScreenPosition([0, 29])
402 keydown('d')
403 keydown('i')
404 keydown('[')
405 expect(editor.getText()).toBe "[ something in here and in [] ]"
406 expect(editor.getCursorScreenPosition()).toEqual [0, 28]
407 expect(editorElement.classList.contains('operator-pending-mode')).toBe(false)
408 expect(editorElement.classList.contains('normal-mode')).toBe(true)
409
410 it "expands an existing selection in visual mode", ->
411 editor.setCursorScreenPosition([0, 25])
412 keydown('v')
413 keydown('l')
414 keydown('l')
415 keydown('l')
416 keydown('l')
417 keydown('i')
418 keydown('[')
419
420 expect(editor.getSelectedScreenRange()).toEqual [[0, 25], [0, 32]]
421
422 describe "the 'i\'' text object", ->
423 beforeEach ->
424 editor.setText("' something in here and in 'here' ' and over here")
425 editor.setCursorScreenPosition([0, 9])
426
427 it "applies operators inside the current string in operator-pending mode", ->
428 keydown('d')
429 keydown('i')
430 keydown('\'')
431 expect(editor.getText()).toBe "''here' ' and over here"
432 expect(editor.getCursorScreenPosition()).toEqual [0, 1]
433 expect(editorElement.classList.contains('operator-pending-mode')).toBe(false)
434 expect(editorElement.classList.contains('normal-mode')).toBe(true)
435
436 it "applies operators inside the next string in operator-pending mode (if not in a string)", ->
437 editor.setCursorScreenPosition([0, 29])
438 keydown('d')
439 keydown('i')
440 keydown('\'')
441 expect(editor.getText()).toBe "' something in here and in 'here'' and over here"
442 expect(editor.getCursorScreenPosition()).toEqual [0, 33]
443 expect(editorElement.classList.contains('operator-pending-mode')).toBe(false)
444 expect(editorElement.classList.contains('normal-mode')).toBe(true)
445
446 it "makes no change if past the last string on a line", ->
447 editor.setCursorScreenPosition([0, 39])
448 keydown('d')
449 keydown('i')
450 keydown('\'')
451 expect(editor.getText()).toBe "' something in here and in 'here' ' and over here"
452 expect(editor.getCursorScreenPosition()).toEqual [0, 39]
453 expect(editorElement.classList.contains('operator-pending-mode')).toBe(false)
454 expect(editorElement.classList.contains('normal-mode')).toBe(true)
455
456 it "expands an existing selection in visual mode", ->
457 editor.setCursorScreenPosition([0, 25])
458 keydown('v')
459 keydown('l')
460 keydown('l')
461 keydown('l')
462 keydown('l')
463 keydown('i')
464 keydown('\'')
465
466 expect(editor.getSelectedScreenRange()).toEqual [[0, 25], [0, 34]]
467
468 describe "the 'i\"' text object", ->
469 beforeEach ->
470 editor.setText("\" something in here and in \"here\" \" and over here")
471 editor.setCursorScreenPosition([0, 9])
472
473 it "applies operators inside the current string in operator-pending mode", ->
474 keydown('d')
475 keydown('i')
476 keydown('"')
477 expect(editor.getText()).toBe "\"\"here\" \" and over here"
478 expect(editor.getCursorScreenPosition()).toEqual [0, 1]
479 expect(editorElement.classList.contains('operator-pending-mode')).toBe(false)
480 expect(editorElement.classList.contains('normal-mode')).toBe(true)
481
482 it "applies operators inside the next string in operator-pending mode (if not in a string)", ->
483 editor.setCursorScreenPosition([0, 29])
484 keydown('d')
485 keydown('i')
486 keydown('"')
487 expect(editor.getText()).toBe "\" something in here and in \"here\"\" and over here"
488 expect(editor.getCursorScreenPosition()).toEqual [0, 33]
489 expect(editorElement.classList.contains('operator-pending-mode')).toBe(false)
490 expect(editorElement.classList.contains('normal-mode')).toBe(true)
491
492 it "makes no change if past the last string on a line", ->
493 editor.setCursorScreenPosition([0, 39])
494 keydown('d')
495 keydown('i')
496 keydown('"')
497 expect(editor.getText()).toBe "\" something in here and in \"here\" \" and over here"
498 expect(editor.getCursorScreenPosition()).toEqual [0, 39]
499 expect(editorElement.classList.contains('operator-pending-mode')).toBe(false)
500
501 it "expands an existing selection in visual mode", ->
502 editor.setCursorScreenPosition([0, 25])
503 keydown('v')
504 keydown('l')
505 keydown('l')
506 keydown('l')
507 keydown('l')
508 keydown('i')
509 keydown('"')
510
511 expect(editor.getSelectedScreenRange()).toEqual [[0, 25], [0, 34]]
512
513 describe "the 'aw' text object", ->
514 beforeEach ->
515 editor.setText("12345 abcde ABCDE")
516 editor.setCursorScreenPosition([0, 9])
517
518 it "applies operators from the start of the current word to the start of the next word in operator-pending mode", ->
519 keydown('d')
520 keydown('a')
521 keydown('w')
522
523 expect(editor.getText()).toBe "12345 ABCDE"
524 expect(editor.getCursorScreenPosition()).toEqual [0, 6]
525 expect(vimState.getRegister('"').text).toBe "abcde "
526 expect(editorElement.classList.contains('operator-pending-mode')).toBe(false)
527 expect(editorElement.classList.contains('normal-mode')).toBe(true)
528
529 it "selects from the start of the current word to the start of the next word in visual mode", ->
530 keydown('v')
531 keydown('a')
532 keydown('w')
533
534 expect(editor.getSelectedScreenRange()).toEqual [[0, 6], [0, 12]]
535
536 it "expands an existing selection in visual mode", ->
537 editor.setCursorScreenPosition([0, 2])
538 keydown('v')
539 keydown('l')
540 keydown('l')
541 keydown('l')
542 keydown('a')
543 keydown('w')
544
545 expect(editor.getSelectedScreenRange()).toEqual [[0, 2], [0, 12]]
546
547 it "doesn't span newlines", ->
548 editor.setText("12345\nabcde ABCDE")
549 editor.setCursorBufferPosition([0, 3])
550
551 keydown("v")
552 keydown("a")
553 keydown("w")
554
555 expect(editor.getSelectedBufferRanges()).toEqual [[[0, 0], [0, 5]]]
556
557 it "doesn't span special characters", ->
558 editor.setText("1(345\nabcde ABCDE")
559 editor.setCursorBufferPosition([0, 3])
560
561 keydown("v")
562 keydown("a")
563 keydown("w")
564
565 expect(editor.getSelectedBufferRanges()).toEqual [[[0, 2], [0, 5]]]
566
567 describe "the 'aW' text object", ->
568 beforeEach ->
569 editor.setText("12(45 ab'de ABCDE")
570 editor.setCursorScreenPosition([0, 9])
571
572 it "applies operators from the start of the current whole word to the start of the next whole word in operator-pending mode", ->
573 keydown('d')
574 keydown('a')
575 keydown('W', shift: true)
576
577 expect(editor.getText()).toBe "12(45 ABCDE"
578 expect(editor.getCursorScreenPosition()).toEqual [0, 6]
579 expect(vimState.getRegister('"').text).toBe "ab'de "
580 expect(editorElement.classList.contains('operator-pending-mode')).toBe(false)
581 expect(editorElement.classList.contains('normal-mode')).toBe(true)
582
583 it "selects from the start of the current whole word to the start of the next whole word in visual mode", ->
584 keydown('v')
585 keydown('a')
586 keydown('W', shift: true)
587
588 expect(editor.getSelectedScreenRange()).toEqual [[0, 6], [0, 12]]
589
590 it "expands an existing selection in visual mode", ->
591 editor.setCursorScreenPosition([0, 2])
592 keydown('v')
593 keydown('l')
594 keydown('l')
595 keydown('l')
596 keydown('a')
597 keydown('W', shift: true)
598
599 expect(editor.getSelectedScreenRange()).toEqual [[0, 2], [0, 12]]
600
601 it "doesn't span newlines", ->
602 editor.setText("12(45\nab'de ABCDE")
603 editor.setCursorBufferPosition([0, 4])
604
605 keydown('v')
606 keydown('a')
607 keydown('W', shift: true)
608
609 expect(editor.getSelectedBufferRanges()).toEqual [[[0, 0], [0, 5]]]
610
611 describe "the 'a(' text object", ->
612 beforeEach ->
613 editor.setText("( something in here and in (here) )")
614 editor.setCursorScreenPosition([0, 9])
615
616 it "applies operators around the current parentheses in operator-pending mode", ->
617 keydown('d')
618 keydown('a')
619 keydown('(')
620 expect(editor.getText()).toBe ""
621 expect(editor.getCursorScreenPosition()).toEqual [0, 0]
622 expect(editorElement.classList.contains('operator-pending-mode')).toBe(false)
623 expect(editorElement.classList.contains('normal-mode')).toBe(true)
624
625 it "applies operators around the current parentheses in operator-pending mode (second test)", ->
626 editor.setCursorScreenPosition([0, 29])
627 keydown('d')
628 keydown('a')
629 keydown('(')
630 expect(editor.getText()).toBe "( something in here and in )"
631 expect(editor.getCursorScreenPosition()).toEqual [0, 27]
632 expect(editorElement.classList.contains('operator-pending-mode')).toBe(false)
633 expect(editorElement.classList.contains('normal-mode')).toBe(true)
634
635 it "expands an existing selection in visual mode", ->
636 editor.setCursorScreenPosition([0, 25])
637 keydown('v')
638 keydown('l')
639 keydown('l')
640 keydown('l')
641 keydown('l')
642 keydown('a')
643 keydown('(')
644
645 expect(editor.getSelectedScreenRange()).toEqual [[0, 25], [0, 33]]
646
647 describe "the 'a{' text object", ->
648 beforeEach ->
649 editor.setText("{ something in here and in {here} }")
650 editor.setCursorScreenPosition([0, 9])
651
652 it "applies operators around the current curly brackets in operator-pending mode", ->
653 keydown('d')
654 keydown('a')
655 keydown('{')
656 expect(editor.getText()).toBe ""
657 expect(editor.getCursorScreenPosition()).toEqual [0, 0]
658 expect(editorElement.classList.contains('operator-pending-mode')).toBe(false)
659 expect(editorElement.classList.contains('normal-mode')).toBe(true)
660
661 it "applies operators around the current curly brackets in operator-pending mode (second test)", ->
662 editor.setCursorScreenPosition([0, 29])
663 keydown('d')
664 keydown('a')
665 keydown('{')
666 expect(editor.getText()).toBe "{ something in here and in }"
667 expect(editor.getCursorScreenPosition()).toEqual [0, 27]
668 expect(editorElement.classList.contains('operator-pending-mode')).toBe(false)
669 expect(editorElement.classList.contains('normal-mode')).toBe(true)
670
671 it "expands an existing selection in visual mode", ->
672 editor.setCursorScreenPosition([0, 25])
673 keydown('v')
674 keydown('l')
675 keydown('l')
676 keydown('l')
677 keydown('l')
678 keydown('a')
679 keydown('{')
680
681 expect(editor.getSelectedScreenRange()).toEqual [[0, 25], [0, 33]]
682
683 describe "the 'a<' text object", ->
684 beforeEach ->
685 editor.setText("< something in here and in <here> >")
686 editor.setCursorScreenPosition([0, 9])
687
688 it "applies operators around the current angle brackets in operator-pending mode", ->
689 keydown('d')
690 keydown('a')
691 keydown('<')
692 expect(editor.getText()).toBe ""
693 expect(editor.getCursorScreenPosition()).toEqual [0, 0]
694 expect(editorElement.classList.contains('operator-pending-mode')).toBe(false)
695 expect(editorElement.classList.contains('normal-mode')).toBe(true)
696
697 it "applies operators around the current angle brackets in operator-pending mode (second test)", ->
698 editor.setCursorScreenPosition([0, 29])
699 keydown('d')
700 keydown('a')
701 keydown('<')
702 expect(editor.getText()).toBe "< something in here and in >"
703 expect(editor.getCursorScreenPosition()).toEqual [0, 27]
704 expect(editorElement.classList.contains('operator-pending-mode')).toBe(false)
705 expect(editorElement.classList.contains('normal-mode')).toBe(true)
706
707 it "expands an existing selection in visual mode", ->
708 editor.setCursorScreenPosition([0, 25])
709 keydown('v')
710 keydown('l')
711 keydown('l')
712 keydown('l')
713 keydown('l')
714 keydown('a')
715 keydown('<')
716
717 expect(editor.getSelectedScreenRange()).toEqual [[0, 25], [0, 33]]
718
719 describe "the 'a[' text object", ->
720 beforeEach ->
721 editor.setText("[ something in here and in [here] ]")
722 editor.setCursorScreenPosition([0, 9])
723
724 it "applies operators around the current square brackets in operator-pending mode", ->
725 keydown('d')
726 keydown('a')
727 keydown('[')
728 expect(editor.getText()).toBe ""
729 expect(editor.getCursorScreenPosition()).toEqual [0, 0]
730 expect(editorElement.classList.contains('operator-pending-mode')).toBe(false)
731 expect(editorElement.classList.contains('normal-mode')).toBe(true)
732
733 it "applies operators around the current square brackets in operator-pending mode (second test)", ->
734 editor.setCursorScreenPosition([0, 29])
735 keydown('d')
736 keydown('a')
737 keydown('[')
738 expect(editor.getText()).toBe "[ something in here and in ]"
739 expect(editor.getCursorScreenPosition()).toEqual [0, 27]
740 expect(editorElement.classList.contains('operator-pending-mode')).toBe(false)
741 expect(editorElement.classList.contains('normal-mode')).toBe(true)
742
743 it "expands an existing selection in visual mode", ->
744 editor.setCursorScreenPosition([0, 25])
745 keydown('v')
746 keydown('l')
747 keydown('l')
748 keydown('l')
749 keydown('l')
750 keydown('a')
751 keydown('[')
752
753 expect(editor.getSelectedScreenRange()).toEqual [[0, 25], [0, 33]]
754
755 describe "the 'a\'' text object", ->
756 beforeEach ->
757 editor.setText("' something in here and in 'here' '")
758 editor.setCursorScreenPosition([0, 9])
759
760 it "applies operators around the current single quotes in operator-pending mode", ->
761 keydown('d')
762 keydown('a')
763 keydown('\'')
764 expect(editor.getText()).toBe "here' '"
765 expect(editor.getCursorScreenPosition()).toEqual [0, 0]
766 expect(editorElement.classList.contains('operator-pending-mode')).toBe(false)
767 expect(editorElement.classList.contains('normal-mode')).toBe(true)
768
769 it "applies operators around the current single quotes in operator-pending mode (second test)", ->
770 editor.setCursorScreenPosition([0, 29])
771 keydown('d')
772 keydown('a')
773 keydown('\'')
774 expect(editor.getText()).toBe "' something in here and in 'here"
775 expect(editor.getCursorScreenPosition()).toEqual [0, 31]
776 expect(editorElement.classList.contains('operator-pending-mode')).toBe(false)
777 expect(editorElement.classList.contains('normal-mode')).toBe(true)
778
779 it "expands an existing selection in visual mode", ->
780 editor.setCursorScreenPosition([0, 25])
781 keydown('v')
782 keydown('l')
783 keydown('l')
784 keydown('l')
785 keydown('l')
786 keydown('a')
787 keydown('\'')
788
789 expect(editor.getSelectedScreenRange()).toEqual [[0, 25], [0, 35]]
790
791 describe "the 'a\"' text object", ->
792 beforeEach ->
793 editor.setText("\" something in here and in \"here\" \"")
794 editor.setCursorScreenPosition([0, 9])
795
796 it "applies operators around the current double quotes in operator-pending mode", ->
797 keydown('d')
798 keydown('a')
799 keydown('""')
800 expect(editor.getText()).toBe 'here" "'
801 expect(editor.getCursorScreenPosition()).toEqual [0, 0]
802 expect(editorElement.classList.contains('operator-pending-mode')).toBe(false)
803 expect(editorElement.classList.contains('normal-mode')).toBe(true)
804
805 it "applies operators around the current double quotes in operator-pending mode (second test)", ->
806 editor.setCursorScreenPosition([0, 29])
807 keydown('d')
808 keydown('a')
809 keydown('"')
810 expect(editor.getText()).toBe "\" something in here and in \"here"
811 expect(editor.getCursorScreenPosition()).toEqual [0, 31]
812 expect(editorElement.classList.contains('operator-pending-mode')).toBe(false)
813 expect(editorElement.classList.contains('normal-mode')).toBe(true)
814
815 it "expands an existing selection in visual mode", ->
816 editor.setCursorScreenPosition([0, 25])
817 keydown('v')
818 keydown('l')
819 keydown('l')
820 keydown('l')
821 keydown('l')
822 keydown('a')
823 keydown('"')
824
825 expect(editor.getSelectedScreenRange()).toEqual [[0, 25], [0, 35]]