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 using gq to reindent a '(' that is" do
80 before { vim.feedkeys 'itest(' }
81 it "something and has a string without spaces at the end" do
82 vim.feedkeys 'something_very_long_blaaaaaaaaa, "some_very_long_string_blaaaaaaaaaaaaaaaaaaaa"\<esc>gqq'
87 describe "when after multiple parens of different types" do
88 it "indents by one level" do
89 vim.feedkeys 'if({\<CR>'
90 indent.should == shiftwidth
93 it "lines up with the last paren" do
94 vim.feedkeys 'ifff({123: 456,\<CR>'
99 describe "when '#' is contained in a string that is followed by a colon" do
100 it "indents by one level" do
101 vim.feedkeys 'iif "some#thing" == "test":#test\<CR>pass'
102 indent.should == shiftwidth
106 describe "when '#' is not contained in a string and is followed by a colon" do
107 it "does not indent" do
108 vim.feedkeys 'iif "some#thing" == "test"#:test\<CR>'
113 describe "when inside an unfinished string" do
114 it "does not indent" do
115 vim.feedkeys 'i"test:\<ESC>'
116 vim.echo('synIDattr(synID(line("."), col("."), 0), "name")'
117 ).downcase.should include 'string'
118 vim.feedkeys 'a\<CR>'
119 proposed_indent.should == 0
123 it "does not dedent" do
124 vim.feedkeys 'iif True:\<CR>"test:\<ESC>'
125 vim.echo('synIDattr(synID(line("."), col("."), 0), "name")'
126 ).downcase.should include 'string'
127 proposed_indent.should == shiftwidth
128 indent.should == shiftwidth
132 describe "when after an '(' that is followed by an unfinished string" do
133 before { vim.feedkeys 'itest("""' }
135 it "it does not indent the next line" do
137 proposed_indent.should == 0
141 it "with contents it does not indent the next line" do
142 vim.feedkeys 'string_contents\<CR>'
143 proposed_indent.should == 0
148 describe "when after assigning an unfinished string" do
149 before { vim.feedkeys 'itest = """' }
151 it "it does not indent the next line" do
153 proposed_indent.should == 0
158 describe "when after assigning an unfinished string" do
159 before { vim.feedkeys 'i test = """' }
161 it "it does not indent the next line" do
163 proposed_indent.should == 0
168 describe "when after assigning a finished string" do
169 before { vim.feedkeys 'i test = ""' }
171 it "it does indent the next line" do
173 proposed_indent.should == 4
177 it "and writing a new string, it does indent the next line" do
178 vim.feedkeys '\<CR>""'
179 proposed_indent.should == 4
184 describe "when after a docstring" do
185 before { vim.feedkeys 'i """' }
187 it "it does indent the next line" do
189 proposed_indent.should == 4
194 describe "when using simple control structures" do
195 it "indents shiftwidth spaces" do
196 vim.feedkeys 'iwhile True:\<CR>pass'
197 indent.should == shiftwidth
201 describe "when writing an 'else' block" do
202 it "aligns to the preceeding 'for' block" do
203 vim.feedkeys 'ifor x in "abc":\<CR>pass\<CR>else:'
207 it "aligns to the preceeding 'if' block" do
208 vim.feedkeys 'ifor x in "abc":\<CR>if True:\<CR>pass\<CR>else:'
209 indent.should == shiftwidth
213 describe "when using parens and control statements" do
214 it "avoids ambiguity by using extra indentation" do
215 vim.feedkeys 'iif (111 and\<CR>'
217 indent.should == shiftwidth * 2
221 vim.feedkeys '222):\<CR>'
222 indent.should == shiftwidth
223 vim.feedkeys 'pass\<CR>'
227 it "still aligns parens properly if not ambiguous" do
228 vim.feedkeys 'iwhile (111 and\<CR>'
230 vim.feedkeys '222):\<CR>'
231 indent.should == shiftwidth
232 vim.feedkeys 'pass\<CR>'
236 it "still handles multiple parens correctly" do
237 vim.feedkeys 'iif (111 and (222 and 333\<CR>'
239 vim.feedkeys 'and 444\<CR>'
241 vim.feedkeys ')\<CR>'
243 indent.should == shiftwidth * 2
247 vim.feedkeys 'and 555):\<CR>'
248 indent.should == shiftwidth
249 vim.feedkeys 'pass\<CR>'
254 describe "when a line breaks with a manual '\\'" do
255 it "indents shiftwidth spaces on normal line" do
256 vim.feedkeys 'ivalue = test + \\\\\<CR>'
257 indent.should == shiftwidth
260 it "indents 2x shiftwidth spaces for control structures" do
261 vim.feedkeys 'iif somevalue == xyz and \\\\\<CR>'
262 indent.should == shiftwidth * 2
265 it "indents relative to line above" do
266 vim.feedkeys 'i\<TAB>value = test + \\\\\<CR>'
267 indent.should == shiftwidth * 2
271 describe "when current line is dedented compared to previous line" do
272 before { vim.feedkeys 'i\<TAB>\<TAB>if x:\<CR>y = True\<CR>\<ESC>' }
273 it "and current line has a valid indentation (Part 1)" do
274 vim.feedkeys '0i\<TAB>if y:'
275 proposed_indent.should == -1
278 it "and current line has a valid indentation (Part 2)" do
279 vim.feedkeys '0i\<TAB>\<TAB>if y:'
280 proposed_indent.should == -1
283 it "and current line has an invalid indentation" do
284 vim.feedkeys 'i while True:\<CR>'
285 indent.should == previous_indent + shiftwidth
289 describe "when current line is dedented compared to the last non-empty line" do
290 before { vim.feedkeys 'i\<TAB>\<TAB>if x:\<CR>y = True\<CR>\<CR>\<ESC>' }
291 it "and current line has a valid indentation" do
292 vim.feedkeys '0i\<TAB>if y:'
293 proposed_indent.should == -1
297 describe "when an 'if' is followed by" do
298 before { vim.feedkeys 'i\<TAB>\<TAB>if x:\<CR>' }
299 it "an elif, it lines up with the 'if'" do
300 vim.feedkeys 'elif y:'
301 indent.should == shiftwidth * 2
304 it "an 'else', it lines up with the 'if'" do
306 indent.should == shiftwidth * 2
310 describe "when a 'for' is followed by" do
311 before { vim.feedkeys 'i\<TAB>\<TAB>for x in y:\<CR>' }
312 it "an 'else', it lines up with the 'for'" do
314 indent.should == shiftwidth * 2
318 describe "when an 'else' is followed by" do
319 before { vim.feedkeys 'i\<TAB>\<TAB>else:\<CR>XXX\<CR>' }
320 it "a 'finally', it lines up with the 'else'" do
321 vim.feedkeys 'finally:'
322 indent.should == shiftwidth * 2
327 describe "when a 'try' is followed by" do
328 before { vim.feedkeys 'i\<TAB>\<TAB>try:\<CR>' }
329 it "an 'except', it lines up with the 'try'" do
330 vim.feedkeys 'except:'
331 indent.should == shiftwidth * 2
334 it "an 'else', it lines up with the 'try'" do
336 indent.should == shiftwidth * 2
339 it "a 'finally', it lines up with the 'try'" do
340 vim.feedkeys 'finally:'
341 indent.should == shiftwidth * 2
345 describe "when an 'except' is followed by" do
346 before { vim.feedkeys 'i\<TAB>\<TAB>except:\<CR>' }
347 it "an 'else', it lines up with the 'except'" do
349 indent.should == shiftwidth * 2
352 it "another 'except', it lines up with the previous 'except'" do
353 vim.feedkeys 'except:'
354 indent.should == shiftwidth * 2
357 it "a 'finally', it lines up with the 'except'" do
358 vim.feedkeys 'finally:'
359 indent.should == shiftwidth * 2
364 @shiftwidth ||= vim.echo("exists('*shiftwidth') ? shiftwidth() : &sw").to_i
367 @tabstop ||= vim.echo("&tabstop").to_i
370 vim.echo("indent('.')").to_i
373 pline = vim.echo("line('.')").to_i - 1
374 vim.echo("indent('#{pline}')").to_i
377 line = vim.echo("line('.')")
378 col = vim.echo("col('.')")
379 indent_value = vim.echo("GetPythonPEPIndent(line('.'))").to_i
380 vim.command("call cursor(#{line}, #{col})")
385 describe "vim when using width of 4" do
387 vim.command("set sw=4 ts=4 sts=4 et")
390 it_behaves_like "vim"
393 describe "vim when using width of 8" do
395 vim.command("set sw=8 ts=8 sts=8 et")
398 it_behaves_like "vim"