All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
3 shared_examples_for "vim" do
9 # Insert two blank lines.
10 # The first line is a corner case in this plugin that would shadow the
11 # correct behaviour of other tests. Thus we explicitly jump to the first
12 # line when we require so.
13 vim.feedkeys 'i\<CR>\<CR>\<ESC>'
16 describe "when using the indent plugin" do
17 it "sets the indentexpr and indentkeys options" do
18 vim.command("set indentexpr?").should include "GetPythonPEPIndent("
19 vim.command("set indentkeys?").should include "=elif"
22 it "sets autoindent and expandtab" do
23 vim.command("set autoindent?").should match(/\s*autoindent/)
24 vim.command("set expandtab?").should match(/\s*expandtab/)
28 describe "when entering the first line" do
29 before { vim.feedkeys '0ggipass' }
31 it "does not indent" do
32 proposed_indent.should == 0
36 it "does not indent when using '=='" do
42 describe "when after a '(' that is at the end of its line" do
43 before { vim.feedkeys 'itest(\<CR>' }
45 it "indents by one level" do
46 proposed_indent.should == shiftwidth
47 vim.feedkeys 'something'
48 indent.should == shiftwidth
50 indent.should == shiftwidth
53 it "puts the closing parenthesis at the same level" do
59 describe "when after an '(' that is followed by something" do
60 before { vim.feedkeys 'itest(something,\<CR>' }
62 it "lines up on following lines" do
64 vim.feedkeys 'more,\<CR>'
68 it "lines up the closing parenthesis" do
73 it "does not touch the closing parenthesis if it is already indented further" do
79 describe "when after multiple parens of different types" do
80 it "indents by one level" do
81 vim.feedkeys 'if({\<CR>'
82 indent.should == shiftwidth
85 it "lines up with the last paren" do
86 vim.feedkeys 'ifff({123: 456,\<CR>'
91 describe "when '#' is contained in a string that is followed by a colon" do
92 it "indents by one level" do
93 vim.feedkeys 'iif "some#thing" == "test":#test\<CR>pass'
94 indent.should == shiftwidth
98 describe "when '#' is not contained in a string and is followed by a colon" do
99 it "does not indent" do
100 vim.feedkeys 'iif "some#thing" == "test"#:test\<CR>'
105 describe "when inside an unfinished string" do
106 it "does not indent" do
107 vim.feedkeys 'i"test:\<ESC>'
108 vim.echo('synIDattr(synID(line("."), col("."), 0), "name")'
109 ).downcase.should include 'string'
110 vim.feedkeys 'a\<CR>'
111 proposed_indent.should == 0
115 it "does not dedent" do
116 vim.feedkeys 'iif True:\<CR>"test:\<ESC>'
117 vim.echo('synIDattr(synID(line("."), col("."), 0), "name")'
118 ).downcase.should include 'string'
119 proposed_indent.should == shiftwidth
120 indent.should == shiftwidth
124 describe "when using simple control structures" do
125 it "indents shiftwidth spaces" do
126 vim.feedkeys 'iwhile True:\<CR>pass'
127 indent.should == shiftwidth
131 describe "when writing an 'else' block" do
132 it "aligns to the preceeding 'for' block" do
133 vim.feedkeys 'ifor x in "abc":\<CR>pass\<CR>else:'
137 it "aligns to the preceeding 'if' block" do
138 vim.feedkeys 'ifor x in "abc":\<CR>if True:\<CR>pass\<CR>else:'
139 indent.should == shiftwidth
143 describe "when using parens and control statements" do
144 it "avoids ambiguity by using extra indentation" do
145 vim.feedkeys 'iif (111 and\<CR>'
147 indent.should == shiftwidth * 2
151 vim.feedkeys '222):\<CR>'
152 indent.should == shiftwidth
153 vim.feedkeys 'pass\<CR>'
157 it "still aligns parens properly if not ambiguous" do
158 vim.feedkeys 'iwhile (111 and\<CR>'
160 vim.feedkeys '222):\<CR>'
161 indent.should == shiftwidth
162 vim.feedkeys 'pass\<CR>'
166 it "still handles multiple parens correctly" do
167 vim.feedkeys 'iif (111 and (222 and 333\<CR>'
169 vim.feedkeys 'and 444\<CR>'
171 vim.feedkeys ')\<CR>'
173 indent.should == shiftwidth * 2
177 vim.feedkeys 'and 555):\<CR>'
178 indent.should == shiftwidth
179 vim.feedkeys 'pass\<CR>'
184 describe "when a line breaks with a manual '\\'" do
185 it "indents shiftwidth spaces on normal line" do
186 vim.feedkeys 'ivalue = test + \\\\\<CR>'
187 indent.should == shiftwidth
190 it "indents 2x shiftwidth spaces for control structures" do
191 vim.feedkeys 'iif somevalue == xyz and \\\\\<CR>'
192 indent.should == shiftwidth * 2
195 it "indents relative to line above" do
196 vim.feedkeys 'i\<TAB>value = test + \\\\\<CR>'
197 indent.should == shiftwidth * 2
201 describe "when current line is dedented compared to previous line" do
202 before { vim.feedkeys 'i\<TAB>\<TAB>if x:\<CR>y = True\<CR>\<ESC>' }
203 it "and current line has a valid indentation (Part 1)" do
204 vim.feedkeys '0i\<TAB>if y:'
205 proposed_indent.should == -1
208 it "and current line has a valid indentation (Part 2)" do
209 vim.feedkeys '0i\<TAB>\<TAB>if y:'
210 proposed_indent.should == -1
213 it "and current line has an invalid indentation" do
214 vim.feedkeys 'i while True:\<CR>'
215 indent.should == previous_indent + shiftwidth
219 describe "when an 'if' is followed by" do
220 before { vim.feedkeys 'i\<TAB>\<TAB>if x:\<CR>' }
221 it "an elif, it lines up with the 'if'" do
222 vim.feedkeys 'elif y:'
223 indent.should == shiftwidth * 2
226 it "an 'else', it lines up with the 'if'" do
228 indent.should == shiftwidth * 2
232 describe "when a 'for' is followed by" do
233 before { vim.feedkeys 'i\<TAB>\<TAB>for x in y:\<CR>' }
234 it "an 'else', it lines up with the 'for'" do
236 indent.should == shiftwidth * 2
240 describe "when an 'else' is followed by" do
241 before { vim.feedkeys 'i\<TAB>\<TAB>else:\<CR>XXX\<CR>' }
242 it "a 'finally', it lines up with the 'else'" do
243 vim.feedkeys 'finally:'
244 indent.should == shiftwidth * 2
249 describe "when a 'try' is followed by" do
250 before { vim.feedkeys 'i\<TAB>\<TAB>try:\<CR>' }
251 it "an 'except', it lines up with the 'try'" do
252 vim.feedkeys 'except:'
253 indent.should == shiftwidth * 2
256 it "an 'else', it lines up with the 'try'" do
258 indent.should == shiftwidth * 2
261 it "a 'finally', it lines up with the 'try'" do
262 vim.feedkeys 'finally:'
263 indent.should == shiftwidth * 2
267 describe "when an 'except' is followed by" do
268 before { vim.feedkeys 'i\<TAB>\<TAB>except:\<CR>' }
269 it "an 'else', it lines up with the 'except'" do
271 indent.should == shiftwidth * 2
274 it "another 'except', it lines up with the previous 'except'" do
275 vim.feedkeys 'except:'
276 indent.should == shiftwidth * 2
279 it "a 'finally', it lines up with the 'except'" do
280 vim.feedkeys 'finally:'
281 indent.should == shiftwidth * 2
286 @shiftwidth ||= vim.echo("exists('*shiftwidth') ? shiftwidth() : &sw").to_i
289 @tabstop ||= vim.echo("&tabstop").to_i
292 vim.echo("indent('.')").to_i
295 pline = vim.echo("line('.')").to_i - 1
296 vim.echo("indent('#{pline}')").to_i
299 line = vim.echo("line('.')")
300 col = vim.echo("col('.')")
301 indent_value = vim.echo("GetPythonPEPIndent(line('.'))").to_i
302 vim.command("call cursor(#{line}, #{col})")
307 describe "vim when using width of 4" do
309 vim.command("set sw=4 ts=4 sts=4 et")
312 it_behaves_like "vim"
315 describe "vim when using width of 8" do
317 vim.command("set sw=8 ts=8 sts=8 et")
320 it_behaves_like "vim"