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
5 before(:each) { vim.normal 'gg"_dG' } # clear buffer
7 describe "when using the indent plugin" do
8 it "sets the indentexpr and indentkeys options" do
9 vim.command("set indentexpr?").should include "GetPythonPEPIndent("
10 vim.command("set indentkeys?").should include "=elif"
13 it "sets autoindent and expandtab" do
14 vim.command("set autoindent?").should match(/\s*autoindent/)
15 vim.command("set expandtab?").should match(/\s*expandtab/)
19 describe "when entering the first line" do
20 before { vim.feedkeys 'ipass' }
22 it "does not indent" do
23 proposed_indent.should == 0
27 it "does not indent when using '=='" do
33 describe "when after a '(' that is at the end of its line" do
34 before { vim.feedkeys 'itest(\<CR>' }
36 it "indents by one level" do
37 proposed_indent.should == shiftwidth
38 vim.feedkeys 'something'
39 indent.should == shiftwidth
41 indent.should == shiftwidth
44 it "puts the closing parenthesis at the same level" do
50 describe "when after an '(' that is followed by something" do
51 before { vim.feedkeys 'itest(something,\<CR>' }
53 it "lines up on following lines" do
55 vim.feedkeys 'more,\<CR>'
59 it "lines up the closing parenthesis" do
64 it "does not touch the closing parenthesis if it is already indented further" do
70 describe "when '#' is contained in a string that is followed by a colon" do
71 it "indents by one level" do
72 vim.feedkeys 'iif "some#thing" == "test":#test\<CR>pass'
73 indent.should == shiftwidth
77 describe "when '#' is not contained in a string and is followed by a colon" do
78 it "does not indent" do
79 vim.feedkeys 'iif "some#thing" == "test"#:test\<CR>'
84 describe "when using simple control structures" do
85 it "indents shiftwidth spaces" do
86 vim.feedkeys 'iwhile True:\<CR>pass'
87 indent.should == shiftwidth
91 describe "when using parens and control statements" do
92 it "avoids ambiguity by using extra indentation" do
93 vim.feedkeys 'iif (111 and\<CR>'
95 indent.should == shiftwidth * 2
99 vim.feedkeys '222):\<CR>'
100 indent.should == shiftwidth
101 vim.feedkeys 'pass\<CR>'
105 it "still aligns parens properly if not ambiguous" do
106 vim.feedkeys 'iwhile (111 and\<CR>'
108 vim.feedkeys '222):\<CR>'
109 indent.should == shiftwidth
110 vim.feedkeys 'pass\<CR>'
114 it "still handles multiple parens correctly" do
115 vim.feedkeys 'iif (111 and (222 and 333\<CR>'
117 vim.feedkeys 'and 444\<CR>'
119 vim.feedkeys ')\<CR>'
121 indent.should == shiftwidth * 2
125 vim.feedkeys 'and 555):\<CR>'
126 indent.should == shiftwidth
127 vim.feedkeys 'pass\<CR>'
132 describe "when a line breaks with a manual '\\'" do
133 it "indents shiftwidth spaces on normal line" do
134 vim.feedkeys 'ivalue = test + \\\\\<CR>'
135 indent.should == shiftwidth
138 it "indents 2x shiftwidth spaces for control structures" do
139 vim.feedkeys 'iif somevalue == xyz and \\\\\<CR>'
140 indent.should == shiftwidth * 2
143 it "indents relative to line above" do
144 vim.feedkeys 'i\<TAB>value = test + \\\\\<CR>'
145 indent.should == shiftwidth * 2
149 describe "when current line is dedented compared to previous line" do
150 before { vim.feedkeys 'i\<TAB>\<TAB>if x:\<CR>return True\<CR>\<ESC>' }
151 it "and current line has a valid indentation (Part 1)" do
152 vim.feedkeys '0i\<TAB>if y:'
153 proposed_indent.should == -1
156 it "and current line has a valid indentation (Part 2)" do
157 vim.feedkeys '0i\<TAB>\<TAB>if y:'
158 proposed_indent.should == -1
161 it "and current line has an invalid indentation" do
162 vim.feedkeys 'i while True:\<CR>'
163 indent.should == previous_indent + shiftwidth
167 describe "when an 'if' is followed by" do
168 before { vim.feedkeys 'i\<TAB>\<TAB>if x:\<CR>' }
169 it "an elif, it lines up with the 'if'" do
170 vim.feedkeys 'elif y:'
171 indent.should == shiftwidth * 2
174 it "an 'else', it lines up with the 'if'" do
176 indent.should == shiftwidth * 2
180 describe "when a 'for' is followed by" do
181 before { vim.feedkeys 'i\<TAB>\<TAB>for x in y:\<CR>' }
182 it "an 'else', it lines up with the 'for'" do
184 indent.should == shiftwidth * 2
188 describe "when an 'else' is followed by" do
189 before { vim.feedkeys 'i\<TAB>\<TAB>else:\<CR>XXX\<CR>' }
190 it "a 'finally', it lines up with the 'else'" do
191 vim.feedkeys 'finally:'
192 indent.should == shiftwidth * 2
197 describe "when a 'try' is followed by" do
198 before { vim.feedkeys 'i\<TAB>\<TAB>try:\<CR>' }
199 it "an 'except', it lines up with the 'try'" do
200 vim.feedkeys 'except:'
201 indent.should == shiftwidth * 2
204 it "an 'else', it lines up with the 'try'" do
206 indent.should == shiftwidth * 2
209 it "a 'finally', it lines up with the 'try'" do
210 vim.feedkeys 'finally:'
211 indent.should == shiftwidth * 2
215 describe "when an 'except' is followed by" do
216 before { vim.feedkeys 'i\<TAB>\<TAB>except:\<CR>' }
217 it "an 'else', it lines up with the 'except'" do
219 indent.should == shiftwidth * 2
222 it "another 'except', it lines up with the previous 'except'" do
223 vim.feedkeys 'except:'
224 indent.should == shiftwidth * 2
227 it "a 'finally', it lines up with the 'except'" do
228 vim.feedkeys 'finally:'
229 indent.should == shiftwidth * 2
234 @shiftwidth ||= vim.echo("exists('*shiftwidth') ? shiftwidth() : &sw").to_i
237 @tabstop ||= vim.echo("&tabstop").to_i
240 vim.echo("indent('.')").to_i
243 pline = vim.echo("line('.')").to_i - 1
244 vim.echo("indent('#{pline}')").to_i
247 line = vim.echo("line('.')")
248 col = vim.echo("col('.')")
249 indent_value = vim.echo("GetPythonPEPIndent(line('.'))").to_i
250 vim.command("call cursor(#{line}, #{col})")
255 describe "vim when using width of 4" do
257 vim.command("set sw=4 ts=4 sts=4 et")
260 it_behaves_like "vim"
263 describe "vim when using width of 8" do
265 vim.command("set sw=8 ts=8 sts=8 et")
268 it_behaves_like "vim"