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
33 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 using simple control structures" do
165 it "indents shiftwidth spaces" do
166 vim.feedkeys 'iwhile True:\<CR>pass'
167 indent.should == shiftwidth
171 describe "when using a function definition" do
172 it "indents shiftwidth spaces" do
173 vim.feedkeys 'idef long_function_name(\<CR>arg'
174 indent.should == shiftwidth * 2
178 describe "when using a class definition" do
179 it "indents shiftwidth spaces" do
180 vim.feedkeys 'iclass Foo(\<CR>'
181 indent.should == shiftwidth * 2
185 describe "when writing an 'else' block" do
186 it "aligns to the preceeding 'for' block" do
187 vim.feedkeys 'ifor x in "abc":\<CR>pass\<CR>else:'
191 it "aligns to the preceeding 'if' block" do
192 vim.feedkeys 'ifor x in "abc":\<CR>if True:\<CR>pass\<CR>else:'
193 indent.should == shiftwidth
197 describe "when using parens and control statements" do
198 it "avoids ambiguity by using extra indentation" do
199 vim.feedkeys 'iif (111 and\<CR>'
201 indent.should == shiftwidth * 2
205 vim.feedkeys '222):\<CR>'
206 indent.should == shiftwidth
207 vim.feedkeys 'pass\<CR>'
211 it "still aligns parens properly if not ambiguous" do
212 vim.feedkeys 'iwhile (111 and\<CR>'
214 vim.feedkeys '222):\<CR>'
215 indent.should == shiftwidth
216 vim.feedkeys 'pass\<CR>'
220 it "still handles multiple parens correctly" do
221 vim.feedkeys 'iif (111 and (222 and 333\<CR>'
223 vim.feedkeys 'and 444\<CR>'
225 vim.feedkeys ')\<CR>'
227 indent.should == shiftwidth * 2
231 vim.feedkeys 'and 555):\<CR>'
232 indent.should == shiftwidth
233 vim.feedkeys 'pass\<CR>'
238 describe "when a line breaks with a manual '\\'" do
239 it "indents shiftwidth spaces on normal line" do
240 vim.feedkeys 'ivalue = test + \\\\\<CR>'
241 indent.should == shiftwidth
244 it "indents 2x shiftwidth spaces for control structures" do
245 vim.feedkeys 'iif somevalue == xyz and \\\\\<CR>'
246 indent.should == shiftwidth * 2
249 it "indents relative to line above" do
250 vim.feedkeys 'i\<TAB>value = test + \\\\\<CR>'
251 indent.should == shiftwidth * 2
255 describe "when current line is dedented compared to previous line" do
256 before { vim.feedkeys 'i\<TAB>\<TAB>if x:\<CR>y = True\<CR>\<ESC>' }
257 it "and current line has a valid indentation (Part 1)" do
258 vim.feedkeys '0i\<TAB>if y:'
259 proposed_indent.should == -1
262 it "and current line has a valid indentation (Part 2)" do
263 vim.feedkeys '0i\<TAB>\<TAB>if y:'
264 proposed_indent.should == -1
267 it "and current line has an invalid indentation" do
268 vim.feedkeys 'i while True:\<CR>'
269 indent.should == previous_indent + shiftwidth
273 describe "when current line is dedented compared to the last non-empty line" do
274 before { vim.feedkeys 'i\<TAB>\<TAB>if x:\<CR>y = True\<CR>\<CR>\<ESC>' }
275 it "and current line has a valid indentation" do
276 vim.feedkeys '0i\<TAB>if y:'
277 proposed_indent.should == -1
281 describe "when an 'if' is followed by" do
282 before { vim.feedkeys 'i\<TAB>\<TAB>if x:\<CR>' }
283 it "an elif, it lines up with the 'if'" do
284 vim.feedkeys 'elif y:'
285 indent.should == shiftwidth * 2
288 it "an 'else', it lines up with the 'if'" do
290 indent.should == shiftwidth * 2
294 describe "when an 'if' contains a try-except" do
296 vim.feedkeys 'iif x:\<CR>try:\<CR>pass\<CR>except:\<CR>pass\<CR>'
297 indent.should == shiftwidth
299 it "an 'else' should be indented to the try" do
301 indent.should == shiftwidth
302 proposed_indent.should == shiftwidth
304 it "an 'else' should keep the indent of the 'if'" do
305 vim.feedkeys 'else:\<ESC><<'
307 proposed_indent.should == 0
311 describe "when a 'for' is followed by" do
312 before { vim.feedkeys 'i\<TAB>\<TAB>for x in y:\<CR>' }
313 it "an 'else', it lines up with the 'for'" do
315 indent.should == shiftwidth * 2
319 describe "when an 'else' is followed by" do
320 before { vim.feedkeys 'i\<TAB>\<TAB>else:\<CR>XXX\<CR>' }
321 it "a 'finally', it lines up with the 'else'" do
322 vim.feedkeys 'finally:'
323 indent.should == shiftwidth * 2
328 describe "when a 'try' is followed by" do
329 before { vim.feedkeys 'i\<TAB>\<TAB>try:\<CR>' }
330 it "an 'except', it lines up with the 'try'" do
331 vim.feedkeys 'except:'
332 indent.should == shiftwidth * 2
335 it "an 'else', it lines up with the 'try'" do
337 indent.should == shiftwidth * 2
340 it "a 'finally', it lines up with the 'try'" do
341 vim.feedkeys 'finally:'
342 indent.should == shiftwidth * 2
346 describe "when an 'except' is followed by" do
347 before { vim.feedkeys 'i\<TAB>\<TAB>except:\<CR>' }
348 it "an 'else', it lines up with the 'except'" do
350 indent.should == shiftwidth * 2
353 it "another 'except', it lines up with the previous 'except'" do
354 vim.feedkeys 'except:'
355 indent.should == shiftwidth * 2
358 it "a 'finally', it lines up with the 'except'" do
359 vim.feedkeys 'finally:'
360 indent.should == shiftwidth * 2
364 describe "when jedi-vim call signatures are used" do
365 before { vim.command 'syn match jediFunction "JEDI_CALL_SIGNATURE" keepend extend' }
367 it "ignores the call signature after a colon" do
368 vim.feedkeys 'iif True: JEDI_CALL_SIGNATURE\<CR>'
369 indent.should == shiftwidth
372 it "ignores the call signature after a function" do
373 vim.feedkeys 'idef f( JEDI_CALL_SIGNATURE\<CR>'
374 indent.should == shiftwidth * 2
379 shared_examples_for "multiline strings" do
380 describe "when after an '(' that is followed by an unfinished string" do
381 before { vim.feedkeys 'itest("""' }
383 it "it indents the next line" do
385 expected_proposed, expected_indent = multiline_indent(0, shiftwidth)
386 proposed_indent.should == expected_proposed
387 indent.should == expected_indent
390 it "with contents it indents the second line to the parenthesis" do
391 vim.feedkeys 'second line\<CR>'
392 expected_proposed, expected_indent = multiline_indent(0, 5)
393 proposed_indent.should == expected_proposed
394 indent.should == expected_indent
398 describe "when after assigning an unfinished string" do
399 before { vim.feedkeys 'itest = """' }
401 it "it indents the next line" do
403 expected_proposed, expected_indent = multiline_indent(0, shiftwidth)
404 proposed_indent.should == expected_proposed
405 indent.should == expected_indent
409 describe "when after assigning an unfinished string" do
410 before { vim.feedkeys 'i test = """' }
412 it "it indents the next line" do
414 expected_proposed, expected_indent = multiline_indent(4, shiftwidth + 4)
415 proposed_indent.should == expected_proposed
416 indent.should == expected_indent
420 describe "when after assigning a finished string" do
421 before { vim.feedkeys 'i test = ""' }
423 it "it does indent the next line" do
428 it "and writing a new string, it does indent the next line" do
429 vim.feedkeys '\<CR>""'
434 describe "when after a docstring" do
435 before { vim.feedkeys 'i """' }
436 it "it does indent the next line to the docstring" do
439 proposed_indent.should == 4
443 describe "when after a docstring with contents" do
444 before { vim.feedkeys 'i """First line' }
445 it "it does indent the next line to the docstring" do
448 proposed_indent.should == 4
453 describe "vim when using width of 4" do
455 vim.command("set sw=4 ts=4 sts=4 et")
457 it_behaves_like "vim"
460 describe "vim when using width of 3" do
462 vim.command("set sw=3 ts=3 sts=3 et")
464 it_behaves_like "vim"
467 describe "vim when not using python_pep8_indent_multiline_string" do
469 vim.command("set sw=4 ts=4 sts=4 et")
470 vim.command("unlet! g:python_pep8_indent_multiline_string")
472 it_behaves_like "multiline strings"
475 describe "vim when using python_pep8_indent_multiline_first=0" do
477 vim.command("set sw=4 ts=4 sts=4 et")
478 vim.command("let g:python_pep8_indent_multiline_string=0")
480 it_behaves_like "multiline strings"
483 describe "vim when using python_pep8_indent_multiline_string=-1" do
485 vim.command("set sw=4 ts=4 sts=4 et")
486 vim.command("let g:python_pep8_indent_multiline_string=-1")
488 it_behaves_like "multiline strings"
491 describe "vim when using python_pep8_indent_multiline_string=-2" do
493 vim.command("set sw=4 ts=4 sts=4 et")
494 vim.command("let g:python_pep8_indent_multiline_string=-2")
496 it_behaves_like "multiline strings"
499 describe "vim for cython" do
502 vim.command "set ft=cython"
503 vim.command "runtime indent/python.vim"
506 describe "when using a cdef function definition" do
507 it "indents shiftwidth spaces" do
508 vim.feedkeys 'icdef long_function_name(\<CR>arg'
509 indent.should == shiftwidth * 2
513 describe "when using a cpdef function definition" do
514 it "indents shiftwidth spaces" do
515 vim.feedkeys 'icpdef long_function_name(\<CR>arg'
516 indent.should == shiftwidth * 2