]>
Commit | Line | Data |
---|---|---|
24c7594d BB |
1 | helpers = require './spec-helper' |
2 | ||
3 | describe "Prefixes", -> | |
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.activateCommandMode() | |
15 | vimState.resetCommandMode() | |
16 | ||
17 | keydown = (key, options={}) -> | |
18 | options.element ?= editorElement | |
19 | helpers.keydown(key, options) | |
20 | ||
21 | describe "Repeat", -> | |
22 | describe "with operations", -> | |
23 | beforeEach -> | |
24 | editor.setText("123456789abc") | |
25 | editor.setCursorScreenPosition([0, 0]) | |
26 | ||
27 | it "repeats N times", -> | |
28 | keydown('3') | |
29 | keydown('x') | |
30 | ||
31 | expect(editor.getText()).toBe '456789abc' | |
32 | ||
33 | it "repeats NN times", -> | |
34 | keydown('1') | |
35 | keydown('0') | |
36 | keydown('x') | |
37 | ||
38 | expect(editor.getText()).toBe 'bc' | |
39 | ||
40 | describe "with motions", -> | |
41 | beforeEach -> | |
42 | editor.setText('one two three') | |
43 | editor.setCursorScreenPosition([0, 0]) | |
44 | ||
45 | it "repeats N times", -> | |
46 | keydown('d') | |
47 | keydown('2') | |
48 | keydown('w') | |
49 | ||
50 | expect(editor.getText()).toBe 'three' | |
51 | ||
52 | describe "in visual mode", -> | |
53 | beforeEach -> | |
54 | editor.setText('one two three') | |
55 | editor.setCursorScreenPosition([0, 0]) | |
56 | ||
57 | it "repeats movements in visual mode", -> | |
58 | keydown("v") | |
59 | keydown("2") | |
60 | keydown("w") | |
61 | ||
62 | expect(editor.getCursorScreenPosition()).toEqual [0, 9] | |
63 | ||
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' | |
69 | ||
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' | |
74 | ||
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' | |
80 | ||
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' | |
85 | ||
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' | |
90 | ||
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' | |
95 | ||
96 | ||
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' | |
102 | ||
103 | describe "writing", -> | |
104 | beforeEach -> | |
105 | vimState.setRegister('*', text: 'new content') | |
106 | ||
107 | it "overwrites the contents of the system clipboard", -> | |
108 | expect(atom.clipboard.read()).toEqual 'new content' | |
109 | ||
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' | |
119 | ||
120 | describe "writing", -> | |
121 | beforeEach -> | |
122 | vimState.setRegister('*', text: 'new content') | |
123 | ||
124 | it "overwrites the contents of the system clipboard", -> | |
125 | expect(atom.clipboard.read()).toEqual 'new content' | |
126 | ||
127 | describe "the _ register", -> | |
128 | describe "reading", -> | |
129 | it "is always the empty string", -> | |
130 | expect(vimState.getRegister("_").text).toEqual '' | |
131 | ||
132 | describe "writing", -> | |
133 | it "throws away anything written to it", -> | |
134 | vimState.setRegister('_', text: 'new content') | |
135 | expect(vimState.getRegister("_").text).toEqual '' | |
136 | ||
137 | describe "the % register", -> | |
138 | beforeEach -> | |
139 | spyOn(editor, 'getURI').andReturn('/Users/atom/known_value.txt') | |
140 | ||
141 | describe "reading", -> | |
142 | it "returns the filename of the current editor", -> | |
143 | expect(vimState.getRegister('%').text).toEqual '/Users/atom/known_value.txt' | |
144 | ||
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' |