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 an '{' that is followed by a comment" do
80 before { vim.feedkeys 'imydict = { # comment\<CR>' }
82 it "indent by one level" do
83 indent.should == shiftwidth
84 vim.feedkeys '1: 1,\<CR>'
85 indent.should == shiftwidth
88 it "lines up the closing parenthesis" do
94 describe "when using gq to reindent a '(' that is" do
95 before { vim.feedkeys 'itest(' }
96 it "something and has a string without spaces at the end" do
97 vim.feedkeys 'something_very_long_blaaaaaaaaa, "some_very_long_string_blaaaaaaaaaaaaaaaaaaaa"\<esc>gqq'
102 describe "when after multiple parens of different types" do
103 it "indents by one level" do
104 vim.feedkeys 'if({\<CR>'
105 indent.should == shiftwidth
108 it "lines up with the last paren" do
109 vim.feedkeys 'ifff({123: 456,\<CR>'
114 describe "when '#' is contained in a string that is followed by a colon" do
115 it "indents by one level" do
116 vim.feedkeys 'iif "some#thing" == "test":#test\<CR>pass'
117 indent.should == shiftwidth
121 describe "when '#' is not contained in a string and is followed by a colon" do
122 it "does not indent" do
123 vim.feedkeys 'iif "some#thing" == "test"#:test\<CR>'
128 describe "when inside an unfinished string" do
129 it "does not indent" do
130 vim.feedkeys 'i"test:\<ESC>'
131 vim.echo('synIDattr(synID(line("."), col("."), 0), "name")'
132 ).downcase.should include 'string'
133 vim.feedkeys 'a\<CR>'
134 proposed_indent.should == 0
138 it "does not dedent" do
139 vim.feedkeys 'iif True:\<CR>"test:\<ESC>'
140 vim.echo('synIDattr(synID(line("."), col("."), 0), "name")'
141 ).downcase.should include 'string'
142 proposed_indent.should == shiftwidth
143 indent.should == shiftwidth
147 describe "when the previous line has a colon in a string" do
148 before { vim.feedkeys 'itest(":".join(["1","2"]))\<CR>' }
149 it "does not indent" do
150 vim.feedkeys 'if True:'
152 proposed_indent.should == 0
156 describe "when after an '(' that is followed by an unfinished string" do
157 before { vim.feedkeys 'itest("""' }
159 it "it does not indent the next line" do
161 proposed_indent.should == 0
165 it "with contents it does not indent the next line" do
166 vim.feedkeys 'string_contents\<CR>'
167 proposed_indent.should == 0
172 describe "when after assigning an unfinished string" do
173 before { vim.feedkeys 'itest = """' }
175 it "it does not indent the next line" do
177 proposed_indent.should == 0
182 describe "when after assigning an unfinished string" do
183 before { vim.feedkeys 'i test = """' }
185 it "it does not indent the next line" do
187 proposed_indent.should == 0
192 describe "when after assigning a finished string" do
193 before { vim.feedkeys 'i test = ""' }
195 it "it does indent the next line" do
197 proposed_indent.should == 4
201 it "and writing a new string, it does indent the next line" do
202 vim.feedkeys '\<CR>""'
203 proposed_indent.should == 4
208 describe "when after a docstring" do
209 before { vim.feedkeys 'i """' }
211 it "it does indent the next line" do
213 proposed_indent.should == 4
218 describe "when using simple control structures" do
219 it "indents shiftwidth spaces" do
220 vim.feedkeys 'iwhile True:\<CR>pass'
221 indent.should == shiftwidth
225 describe "when using a function definition" do
226 it "indents shiftwidth spaces" do
227 vim.feedkeys 'idef long_function_name(\<CR>arg'
228 indent.should == shiftwidth * 2
232 describe "when using a class definition" do
233 it "indents shiftwidth spaces" do
234 vim.feedkeys 'iclass Foo(\<CR>'
235 indent.should == shiftwidth * 2
239 describe "when writing an 'else' block" do
240 it "aligns to the preceeding 'for' block" do
241 vim.feedkeys 'ifor x in "abc":\<CR>pass\<CR>else:'
245 it "aligns to the preceeding 'if' block" do
246 vim.feedkeys 'ifor x in "abc":\<CR>if True:\<CR>pass\<CR>else:'
247 indent.should == shiftwidth
251 describe "when using parens and control statements" do
252 it "avoids ambiguity by using extra indentation" do
253 vim.feedkeys 'iif (111 and\<CR>'
255 indent.should == shiftwidth * 2
259 vim.feedkeys '222):\<CR>'
260 indent.should == shiftwidth
261 vim.feedkeys 'pass\<CR>'
265 it "still aligns parens properly if not ambiguous" do
266 vim.feedkeys 'iwhile (111 and\<CR>'
268 vim.feedkeys '222):\<CR>'
269 indent.should == shiftwidth
270 vim.feedkeys 'pass\<CR>'
274 it "still handles multiple parens correctly" do
275 vim.feedkeys 'iif (111 and (222 and 333\<CR>'
277 vim.feedkeys 'and 444\<CR>'
279 vim.feedkeys ')\<CR>'
281 indent.should == shiftwidth * 2
285 vim.feedkeys 'and 555):\<CR>'
286 indent.should == shiftwidth
287 vim.feedkeys 'pass\<CR>'
292 describe "when a line breaks with a manual '\\'" do
293 it "indents shiftwidth spaces on normal line" do
294 vim.feedkeys 'ivalue = test + \\\\\<CR>'
295 indent.should == shiftwidth
298 it "indents 2x shiftwidth spaces for control structures" do
299 vim.feedkeys 'iif somevalue == xyz and \\\\\<CR>'
300 indent.should == shiftwidth * 2
303 it "indents relative to line above" do
304 vim.feedkeys 'i\<TAB>value = test + \\\\\<CR>'
305 indent.should == shiftwidth * 2
309 describe "when current line is dedented compared to previous line" do
310 before { vim.feedkeys 'i\<TAB>\<TAB>if x:\<CR>y = True\<CR>\<ESC>' }
311 it "and current line has a valid indentation (Part 1)" do
312 vim.feedkeys '0i\<TAB>if y:'
313 proposed_indent.should == -1
316 it "and current line has a valid indentation (Part 2)" do
317 vim.feedkeys '0i\<TAB>\<TAB>if y:'
318 proposed_indent.should == -1
321 it "and current line has an invalid indentation" do
322 vim.feedkeys 'i while True:\<CR>'
323 indent.should == previous_indent + shiftwidth
327 describe "when current line is dedented compared to the last non-empty line" do
328 before { vim.feedkeys 'i\<TAB>\<TAB>if x:\<CR>y = True\<CR>\<CR>\<ESC>' }
329 it "and current line has a valid indentation" do
330 vim.feedkeys '0i\<TAB>if y:'
331 proposed_indent.should == -1
335 describe "when an 'if' is followed by" do
336 before { vim.feedkeys 'i\<TAB>\<TAB>if x:\<CR>' }
337 it "an elif, it lines up with the 'if'" do
338 vim.feedkeys 'elif y:'
339 indent.should == shiftwidth * 2
342 it "an 'else', it lines up with the 'if'" do
344 indent.should == shiftwidth * 2
348 describe "when a 'for' is followed by" do
349 before { vim.feedkeys 'i\<TAB>\<TAB>for x in y:\<CR>' }
350 it "an 'else', it lines up with the 'for'" do
352 indent.should == shiftwidth * 2
356 describe "when an 'else' is followed by" do
357 before { vim.feedkeys 'i\<TAB>\<TAB>else:\<CR>XXX\<CR>' }
358 it "a 'finally', it lines up with the 'else'" do
359 vim.feedkeys 'finally:'
360 indent.should == shiftwidth * 2
365 describe "when a 'try' is followed by" do
366 before { vim.feedkeys 'i\<TAB>\<TAB>try:\<CR>' }
367 it "an 'except', it lines up with the 'try'" do
368 vim.feedkeys 'except:'
369 indent.should == shiftwidth * 2
372 it "an 'else', it lines up with the 'try'" do
374 indent.should == shiftwidth * 2
377 it "a 'finally', it lines up with the 'try'" do
378 vim.feedkeys 'finally:'
379 indent.should == shiftwidth * 2
383 describe "when an 'except' is followed by" do
384 before { vim.feedkeys 'i\<TAB>\<TAB>except:\<CR>' }
385 it "an 'else', it lines up with the 'except'" do
387 indent.should == shiftwidth * 2
390 it "another 'except', it lines up with the previous 'except'" do
391 vim.feedkeys 'except:'
392 indent.should == shiftwidth * 2
395 it "a 'finally', it lines up with the 'except'" do
396 vim.feedkeys 'finally:'
397 indent.should == shiftwidth * 2
401 describe "when jedi-vim call signatures are used" do
402 before { vim.command 'syn match jediFunction "JEDI_CALL_SIGNATURE" keepend extend' }
404 it "ignores the call signature after a colon" do
405 vim.feedkeys 'iif True: JEDI_CALL_SIGNATURE\<CR>'
406 indent.should == shiftwidth
409 it "ignores the call signature after a function" do
410 vim.feedkeys 'idef f( JEDI_CALL_SIGNATURE\<CR>'
411 indent.should == shiftwidth * 2
416 @shiftwidth ||= vim.echo("exists('*shiftwidth') ? shiftwidth() : &sw").to_i
419 @tabstop ||= vim.echo("&tabstop").to_i
422 vim.echo("indent('.')").to_i
425 pline = vim.echo("line('.')").to_i - 1
426 vim.echo("indent('#{pline}')").to_i
429 line = vim.echo("line('.')")
430 col = vim.echo("col('.')")
431 indent_value = vim.echo("GetPythonPEPIndent(line('.'))").to_i
432 vim.command("call cursor(#{line}, #{col})")
437 describe "vim when using width of 4" do
439 vim.command("set sw=4 ts=4 sts=4 et")
442 it_behaves_like "vim"
445 describe "vim when using width of 8" do
447 vim.command("set sw=8 ts=8 sts=8 et")
450 it_behaves_like "vim"