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 a line breaks with a manual '\\'" do
92 it "indents shiftwidth spaces on normal line" do
93 vim.feedkeys 'ivalue = test + \\\\\<CR>'
94 indent.should == shiftwidth
97 it "indents 2x shiftwidth spaces for control structures" do
98 vim.feedkeys 'iif somevalue == xyz and \\\\\<CR>'
99 indent.should == shiftwidth * 2
102 it "indents relative to line above" do
103 vim.feedkeys 'i\<TAB>value = test + \\\\\<CR>'
104 indent.should == shiftwidth * 2
108 describe "when current line is dedented compared to previous line" do
109 before { vim.feedkeys 'i\<TAB>\<TAB>if x:\<CR>return True\<CR>\<ESC>' }
110 it "and current line has a valid indentation (Part 1)" do
111 vim.feedkeys '0i\<TAB>if y:'
112 proposed_indent.should == -1
115 it "and current line has a valid indentation (Part 2)" do
116 vim.feedkeys '0i\<TAB>\<TAB>if y:'
117 proposed_indent.should == -1
120 it "and current line has an invalid indentation" do
121 vim.feedkeys 'i while True:\<CR>'
122 indent.should == previous_indent + shiftwidth
126 describe "when an 'if' is followed by" do
127 before { vim.feedkeys 'i\<TAB>\<TAB>if x:\<CR>' }
128 it "an elif, it lines up with the 'if'" do
129 vim.feedkeys 'elif y:'
130 indent.should == shiftwidth * 2
133 it "an 'else', it lines up with the 'if'" do
135 indent.should == shiftwidth * 2
139 describe "when a 'for' is followed by" do
140 before { vim.feedkeys 'i\<TAB>\<TAB>for x in y:\<CR>' }
141 it "an 'else', it lines up with the 'for'" do
143 indent.should == shiftwidth * 2
147 describe "when an 'else' is followed by" do
148 before { vim.feedkeys 'i\<TAB>\<TAB>else:\<CR>XXX\<CR>' }
149 it "a 'finally', it lines up with the 'else'" do
150 vim.feedkeys 'finally:'
151 indent.should == shiftwidth * 2
156 describe "when a 'try' is followed by" do
157 before { vim.feedkeys 'i\<TAB>\<TAB>try:\<CR>' }
158 it "an 'except', it lines up with the 'try'" do
159 vim.feedkeys 'except:'
160 indent.should == shiftwidth * 2
163 it "an 'else', it lines up with the 'try'" do
165 indent.should == shiftwidth * 2
168 it "a 'finally', it lines up with the 'try'" do
169 vim.feedkeys 'finally:'
170 indent.should == shiftwidth * 2
174 describe "when an 'except' is followed by" do
175 before { vim.feedkeys 'i\<TAB>\<TAB>except:\<CR>' }
176 it "an 'else', it lines up with the 'except'" do
178 indent.should == shiftwidth * 2
181 it "another 'except', it lines up with the previous 'except'" do
182 vim.feedkeys 'except:'
183 indent.should == shiftwidth * 2
186 it "a 'finally', it lines up with the 'except'" do
187 vim.feedkeys 'finally:'
188 indent.should == shiftwidth * 2
193 @shiftwidth ||= vim.echo("exists('*shiftwidth') ? shiftwidth() : &sw").to_i
196 @tabstop ||= vim.echo("&tabstop").to_i
199 vim.echo("indent('.')").to_i
202 pline = vim.echo("line('.')").to_i - 1
203 vim.echo("indent('#{pline}')").to_i
206 line = vim.echo("line('.')")
207 col = vim.echo("col('.')")
208 indent_value = vim.echo("GetPythonPEPIndent(line('.'))").to_i
209 vim.command("call cursor(#{line}, #{col})")
214 describe "vim when using width of 4" do
216 vim.command("set sw=4 ts=4 sts=4 et")
219 it_behaves_like "vim"
222 describe "vim when using width of 8" do
224 vim.command("set sw=8 ts=8 sts=8 et")
227 it_behaves_like "vim"