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 the previous line has a list slice" do
157 it "does not indent" do
158 vim.feedkeys 'ib = a[2:]\<CR>'
160 proposed_indent.should == 0
164 describe "when after an '(' that is followed by an unfinished string" do
165 before { vim.feedkeys 'itest("""' }
167 it "it does not indent the next line" do
169 proposed_indent.should == 0
173 it "with contents it does not indent the next line" do
174 vim.feedkeys 'string_contents\<CR>'
175 proposed_indent.should == 0
180 describe "when after assigning an unfinished string" do
181 before { vim.feedkeys 'itest = """' }
183 it "it does not indent the next line" do
185 proposed_indent.should == 0
190 describe "when after assigning an unfinished string" do
191 before { vim.feedkeys 'i test = """' }
193 it "it does not indent the next line" do
195 proposed_indent.should == 0
200 describe "when after assigning a finished string" do
201 before { vim.feedkeys 'i test = ""' }
203 it "it does indent the next line" do
205 proposed_indent.should == 4
209 it "and writing a new string, it does indent the next line" do
210 vim.feedkeys '\<CR>""'
211 proposed_indent.should == 4
216 describe "when after a docstring" do
217 before { vim.feedkeys 'i """' }
219 it "it does indent the next line" do
221 proposed_indent.should == 4
226 describe "when using simple control structures" do
227 it "indents shiftwidth spaces" do
228 vim.feedkeys 'iwhile True:\<CR>pass'
229 indent.should == shiftwidth
233 describe "when using a function definition" do
234 it "indents shiftwidth spaces" do
235 vim.feedkeys 'idef long_function_name(\<CR>arg'
236 indent.should == shiftwidth * 2
240 describe "when using a class definition" do
241 it "indents shiftwidth spaces" do
242 vim.feedkeys 'iclass Foo(\<CR>'
243 indent.should == shiftwidth * 2
247 describe "when writing an 'else' block" do
248 it "aligns to the preceeding 'for' block" do
249 vim.feedkeys 'ifor x in "abc":\<CR>pass\<CR>else:'
253 it "aligns to the preceeding 'if' block" do
254 vim.feedkeys 'ifor x in "abc":\<CR>if True:\<CR>pass\<CR>else:'
255 indent.should == shiftwidth
259 describe "when using parens and control statements" do
260 it "avoids ambiguity by using extra indentation" do
261 vim.feedkeys 'iif (111 and\<CR>'
263 indent.should == shiftwidth * 2
267 vim.feedkeys '222):\<CR>'
268 indent.should == shiftwidth
269 vim.feedkeys 'pass\<CR>'
273 it "still aligns parens properly if not ambiguous" do
274 vim.feedkeys 'iwhile (111 and\<CR>'
276 vim.feedkeys '222):\<CR>'
277 indent.should == shiftwidth
278 vim.feedkeys 'pass\<CR>'
282 it "still handles multiple parens correctly" do
283 vim.feedkeys 'iif (111 and (222 and 333\<CR>'
285 vim.feedkeys 'and 444\<CR>'
287 vim.feedkeys ')\<CR>'
289 indent.should == shiftwidth * 2
293 vim.feedkeys 'and 555):\<CR>'
294 indent.should == shiftwidth
295 vim.feedkeys 'pass\<CR>'
300 describe "when a line breaks with a manual '\\'" do
301 it "indents shiftwidth spaces on normal line" do
302 vim.feedkeys 'ivalue = test + \\\\\<CR>'
303 indent.should == shiftwidth
306 it "indents 2x shiftwidth spaces for control structures" do
307 vim.feedkeys 'iif somevalue == xyz and \\\\\<CR>'
308 indent.should == shiftwidth * 2
311 it "indents relative to line above" do
312 vim.feedkeys 'i\<TAB>value = test + \\\\\<CR>'
313 indent.should == shiftwidth * 2
317 describe "when current line is dedented compared to previous line" do
318 before { vim.feedkeys 'i\<TAB>\<TAB>if x:\<CR>y = True\<CR>\<ESC>' }
319 it "and current line has a valid indentation (Part 1)" do
320 vim.feedkeys '0i\<TAB>if y:'
321 proposed_indent.should == -1
324 it "and current line has a valid indentation (Part 2)" do
325 vim.feedkeys '0i\<TAB>\<TAB>if y:'
326 proposed_indent.should == -1
329 it "and current line has an invalid indentation" do
330 vim.feedkeys 'i while True:\<CR>'
331 indent.should == previous_indent + shiftwidth
335 describe "when current line is dedented compared to the last non-empty line" do
336 before { vim.feedkeys 'i\<TAB>\<TAB>if x:\<CR>y = True\<CR>\<CR>\<ESC>' }
337 it "and current line has a valid indentation" do
338 vim.feedkeys '0i\<TAB>if y:'
339 proposed_indent.should == -1
343 describe "when an 'if' is followed by" do
344 before { vim.feedkeys 'i\<TAB>\<TAB>if x:\<CR>' }
345 it "an elif, it lines up with the 'if'" do
346 vim.feedkeys 'elif y:'
347 indent.should == shiftwidth * 2
350 it "an 'else', it lines up with the 'if'" do
352 indent.should == shiftwidth * 2
356 describe "when a 'for' is followed by" do
357 before { vim.feedkeys 'i\<TAB>\<TAB>for x in y:\<CR>' }
358 it "an 'else', it lines up with the 'for'" do
360 indent.should == shiftwidth * 2
364 describe "when an 'else' is followed by" do
365 before { vim.feedkeys 'i\<TAB>\<TAB>else:\<CR>XXX\<CR>' }
366 it "a 'finally', it lines up with the 'else'" do
367 vim.feedkeys 'finally:'
368 indent.should == shiftwidth * 2
373 describe "when a 'try' is followed by" do
374 before { vim.feedkeys 'i\<TAB>\<TAB>try:\<CR>' }
375 it "an 'except', it lines up with the 'try'" do
376 vim.feedkeys 'except:'
377 indent.should == shiftwidth * 2
380 it "an 'else', it lines up with the 'try'" do
382 indent.should == shiftwidth * 2
385 it "a 'finally', it lines up with the 'try'" do
386 vim.feedkeys 'finally:'
387 indent.should == shiftwidth * 2
391 describe "when an 'except' is followed by" do
392 before { vim.feedkeys 'i\<TAB>\<TAB>except:\<CR>' }
393 it "an 'else', it lines up with the 'except'" do
395 indent.should == shiftwidth * 2
398 it "another 'except', it lines up with the previous 'except'" do
399 vim.feedkeys 'except:'
400 indent.should == shiftwidth * 2
403 it "a 'finally', it lines up with the 'except'" do
404 vim.feedkeys 'finally:'
405 indent.should == shiftwidth * 2
409 describe "when jedi-vim call signatures are used" do
410 before { vim.command 'syn match jediFunction "JEDI_CALL_SIGNATURE" keepend extend' }
412 it "ignores the call signature after a colon" do
413 vim.feedkeys 'iif True: JEDI_CALL_SIGNATURE\<CR>'
414 indent.should == shiftwidth
417 it "ignores the call signature after a function" do
418 vim.feedkeys 'idef f( JEDI_CALL_SIGNATURE\<CR>'
419 indent.should == shiftwidth * 2
424 @shiftwidth ||= vim.echo("exists('*shiftwidth') ? shiftwidth() : &sw").to_i
427 @tabstop ||= vim.echo("&tabstop").to_i
430 vim.echo("indent('.')").to_i
433 pline = vim.echo("line('.')").to_i - 1
434 vim.echo("indent('#{pline}')").to_i
437 line = vim.echo("line('.')")
438 col = vim.echo("col('.')")
439 indent_value = vim.echo("GetPythonPEPIndent(line('.'))").to_i
440 vim.command("call cursor(#{line}, #{col})")
445 describe "vim when using width of 4" do
447 vim.command("set sw=4 ts=4 sts=4 et")
450 it_behaves_like "vim"
453 describe "vim when using width of 8" do
455 vim.command("set sw=8 ts=8 sts=8 et")
458 it_behaves_like "vim"
461 describe "vim for cython" do
464 vim.command "set ft=cython"
465 vim.command "runtime indent/python.vim"
469 @shiftwidth ||= vim.echo("exists('*shiftwidth') ? shiftwidth() : &sw").to_i
472 @tabstop ||= vim.echo("&tabstop").to_i
475 vim.echo("indent('.')").to_i
478 describe "when using a cdef function definition" do
479 it "indents shiftwidth spaces" do
480 vim.feedkeys 'icdef long_function_name(\<CR>arg'
481 indent.should == shiftwidth * 2
485 describe "when using a cpdef function definition" do
486 it "indents shiftwidth spaces" do
487 vim.feedkeys 'icpdef long_function_name(\<CR>arg'
488 indent.should == shiftwidth * 2