Skip to content
This repository was archived by the owner on Apr 6, 2018. It is now read-only.

Commit 616f45e

Browse files
committed
add tests for yank scrolling
1 parent c18ea28 commit 616f45e

File tree

2 files changed

+89
-1
lines changed

2 files changed

+89
-1
lines changed

spec/operators-spec.coffee

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,8 +745,9 @@ describe "Operators", ->
745745

746746
describe "the y keybinding", ->
747747
beforeEach ->
748-
editor.getBuffer().setText("012 345\nabc\n")
748+
editor.getBuffer().setText("012 345\nabc\ndefg\n")
749749
editor.setCursorScreenPosition([0, 4])
750+
vimState.setRegister('"', text: '345')
750751

751752
describe "when selected lines in visual linewise mode", ->
752753
beforeEach ->
@@ -857,6 +858,18 @@ describe "Operators", ->
857858
it "leaves the cursor at the starting position", ->
858859
expect(editor.getCursorScreenPosition()).toEqual [0, 4]
859860

861+
describe "with an up motion", ->
862+
beforeEach ->
863+
editor.setCursorScreenPosition([2, 2])
864+
keydown 'y'
865+
keydown 'k'
866+
867+
it "saves both full lines to the default register", ->
868+
expect(vimState.getRegister('"').text).toBe "abc\ndefg\n"
869+
870+
it "puts the cursor on the first line and the original column", ->
871+
expect(editor.getCursorScreenPosition()).toEqual [1, 2]
872+
860873
describe "when followed by a G", ->
861874
beforeEach ->
862875
originalText = "12345\nabcde\nABCDE"
@@ -913,6 +926,48 @@ describe "Operators", ->
913926
expect(vimState.getRegister('"').text).toBe '123'
914927
expect(editor.getCursorBufferPositions()).toEqual [[0, 0], [1, 2]]
915928

929+
describe "in a long file", ->
930+
beforeEach ->
931+
editor.setHeight(400)
932+
editor.setLineHeightInPixels(10)
933+
editor.setDefaultCharWidth(10)
934+
text = ""
935+
for i in [1..200]
936+
text += "#{i}\n"
937+
editor.setText(text)
938+
939+
describe "yanking many lines forward", ->
940+
it "does not scroll the window", ->
941+
editor.setCursorBufferPosition [40, 1]
942+
top40 = editor.getScrollTop()
943+
944+
# yank many lines
945+
keydown('y')
946+
keydown('1')
947+
keydown('6')
948+
keydown('0')
949+
keydown('G', shift: true)
950+
951+
expect(editor.getScrollTop()).toEqual(top40)
952+
expect(editor.getCursorBufferPosition()).toEqual [40, 1]
953+
expect(vimState.getRegister('"').text.split('\n').length).toBe 121
954+
955+
describe "yanking many lines backwards", ->
956+
it "scrolls the window", ->
957+
editor.setCursorBufferPosition [140, 1]
958+
top140 = editor.getScrollTop()
959+
960+
# yank many lines
961+
keydown('y')
962+
keydown('6')
963+
keydown('0')
964+
keydown('G', shift: true)
965+
966+
expect(editor.getScrollTop()).toNotEqual top140
967+
expect(editor.getCursorBufferPosition()).toEqual [59, 1]
968+
expect(vimState.getRegister('"').text.split('\n').length).toBe 83
969+
970+
916971
describe "the yy keybinding", ->
917972
describe "on a single line file", ->
918973
beforeEach ->

spec/scroll-spec.coffee

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,39 @@ describe "Scrolling", ->
1818
options.element ?= editorElement
1919
helpers.keydown(key, options)
2020

21+
describe "normal movements (sanity check for scrolling)", ->
22+
beforeEach ->
23+
editor.setHeight(400)
24+
editor.setLineHeightInPixels(10)
25+
editor.setDefaultCharWidth(10)
26+
text = ""
27+
for i in [1..200]
28+
text += "#{i}\n"
29+
editor.setText(text)
30+
31+
describe "the G keybinding", ->
32+
it "scrolls the window", ->
33+
editor.setCursorBufferPosition [0, 0]
34+
top0 = editor.getScrollTop()
35+
36+
editor.setCursorBufferPosition [100, 0]
37+
top100 = editor.getScrollTop()
38+
expect(top100).toBeGreaterThan(top0)
39+
40+
editor.setCursorBufferPosition [101, 0]
41+
top101 = editor.getScrollTop()
42+
expect(top101-top100).toEqual(10)
43+
44+
editor.setCursorBufferPosition [161, 0]
45+
top161 = editor.getScrollTop()
46+
expect(top161-top100).toEqual(610)
47+
48+
editor.setCursorBufferPosition [0, 0]
49+
expect(editor.getScrollTop()).toNotBe top101
50+
editor.setCursorBufferPosition [101, 0]
51+
expect(editor.getScrollTop()).toBe top101
52+
53+
2154
describe "scrolling keybindings", ->
2255
beforeEach ->
2356
editor.setText("1\n2\n3\n4\n5\n6\n7\n8\n9\n10")

0 commit comments

Comments
 (0)