1 helpers = require './spec-helper'
3 describe "Prefixes", ->
4 [editor, editorElement, vimState] = []
7 vimMode = atom.packages.loadPackage('vim-mode')
8 vimMode.activateResources()
10 helpers.getEditorElement (element) ->
11 editorElement = element
12 editor = editorElement.getModel()
13 vimState = editorElement.vimState
14 vimState.activateCommandMode()
15 vimState.resetCommandMode()
17 keydown = (key, options={}) ->
18 options.element ?= editorElement
19 helpers.keydown(key, options)
22 describe "with operations", ->
24 editor.setText("123456789abc")
25 editor.setCursorScreenPosition([0, 0])
27 it "repeats N times", ->
31 expect(editor.getText()).toBe '456789abc'
33 it "repeats NN times", ->
38 expect(editor.getText()).toBe 'bc'
40 describe "with motions", ->
42 editor.setText('one two three')
43 editor.setCursorScreenPosition([0, 0])
45 it "repeats N times", ->
50 expect(editor.getText()).toBe 'three'
52 describe "in visual mode", ->
54 editor.setText('one two three')
55 editor.setCursorScreenPosition([0, 0])
57 it "repeats movements in visual mode", ->
62 expect(editor.getCursorScreenPosition()).toEqual [0, 9]
64 describe "Register", ->
65 describe "the a register", ->
66 it "saves a value for future reading", ->
67 vimState.setRegister('a', text: 'new content')
68 expect(vimState.getRegister("a").text).toEqual 'new content'
70 it "overwrites a value previously in the register", ->
71 vimState.setRegister('a', text: 'content')
72 vimState.setRegister('a', text: 'new content')
73 expect(vimState.getRegister("a").text).toEqual 'new content'
75 describe "the B register", ->
76 it "saves a value for future reading", ->
77 vimState.setRegister('B', text: 'new content')
78 expect(vimState.getRegister("b").text).toEqual 'new content'
79 expect(vimState.getRegister("B").text).toEqual 'new content'
81 it "appends to a value previously in the register", ->
82 vimState.setRegister('b', text: 'content')
83 vimState.setRegister('B', text: 'new content')
84 expect(vimState.getRegister("b").text).toEqual 'contentnew content'
86 it "appends linewise to a linewise value previously in the register", ->
87 vimState.setRegister('b', {type: 'linewise', text: 'content\n'})
88 vimState.setRegister('B', text: 'new content')
89 expect(vimState.getRegister("b").text).toEqual 'content\nnew content\n'
91 it "appends linewise to a character value previously in the register", ->
92 vimState.setRegister('b', text: 'content')
93 vimState.setRegister('B', {type: 'linewise', text: 'new content\n'})
94 expect(vimState.getRegister("b").text).toEqual 'content\nnew content\n'
97 describe "the * register", ->
98 describe "reading", ->
99 it "is the same the system clipboard", ->
100 expect(vimState.getRegister('*').text).toEqual 'initial clipboard content'
101 expect(vimState.getRegister('*').type).toEqual 'character'
103 describe "writing", ->
105 vimState.setRegister('*', text: 'new content')
107 it "overwrites the contents of the system clipboard", ->
108 expect(atom.clipboard.read()).toEqual 'new content'
110 # FIXME: once linux support comes out, this needs to read from
111 # the correct clipboard. For now it behaves just like the * register
112 # See :help x11-cut-buffer and :help registers for more details on how these
113 # registers work on an X11 based system.
114 describe "the + register", ->
115 describe "reading", ->
116 it "is the same the system clipboard", ->
117 expect(vimState.getRegister('*').text).toEqual 'initial clipboard content'
118 expect(vimState.getRegister('*').type).toEqual 'character'
120 describe "writing", ->
122 vimState.setRegister('*', text: 'new content')
124 it "overwrites the contents of the system clipboard", ->
125 expect(atom.clipboard.read()).toEqual 'new content'
127 describe "the _ register", ->
128 describe "reading", ->
129 it "is always the empty string", ->
130 expect(vimState.getRegister("_").text).toEqual ''
132 describe "writing", ->
133 it "throws away anything written to it", ->
134 vimState.setRegister('_', text: 'new content')
135 expect(vimState.getRegister("_").text).toEqual ''
137 describe "the % register", ->
139 spyOn(editor, 'getURI').andReturn('/Users/atom/known_value.txt')
141 describe "reading", ->
142 it "returns the filename of the current editor", ->
143 expect(vimState.getRegister('%').text).toEqual '/Users/atom/known_value.txt'
145 describe "writing", ->
146 it "throws away anything written to it", ->
147 vimState.setRegister('%', "new content")
148 expect(vimState.getRegister('%').text).toEqual '/Users/atom/known_value.txt'