+ describe "when after an '{' that is followed by a comment" do
+ before { vim.feedkeys 'imydict = { # comment\<CR>' }
+
+ it "indent by one level" do
+ indent.should == shiftwidth
+ vim.feedkeys '1: 1,\<CR>'
+ indent.should == shiftwidth
+ end
+
+ it "lines up the closing parenthesis" do
+ vim.feedkeys '}'
+ indent.should == (hang_closing ? shiftwidth : 0)
+ end
+ end
+
+ describe "when using gq to reindent a '(' that is" do
+ before { vim.feedkeys 'itest(' }
+ it "something and has a string without spaces at the end" do
+ vim.feedkeys 'something_very_long_blaaaaaaaaa, "some_very_long_string_blaaaaaaaaaaaaaaaaaaaa"\<esc>gqq'
+ indent.should == 5
+ end
+ end
+
+ describe "when after multiple parens of different types" do
+ it "indents by one level" do
+ vim.feedkeys 'if({\<CR>'
+ indent.should == shiftwidth
+ end
+
+ it "lines up with the last paren" do
+ vim.feedkeys 'ifff({123: 456,\<CR>'
+ indent.should == 5
+ end
+ end
+
+ describe "when '#' is contained in a string that is followed by a colon" do
+ it "indents by one level" do
+ vim.feedkeys 'iif "some#thing" == "test":#test\<CR>pass'
+ indent.should == shiftwidth
+ end
+ end
+
+ describe "when '#' is not contained in a string and is followed by a colon" do
+ it "does not indent" do
+ vim.feedkeys 'iif "some#thing" == "test"#:test\<CR>'
+ indent.should == 0
+ end
+ end
+
+ describe "when inside an unfinished string" do
+ it "does not indent" do
+ vim.feedkeys 'i"test:\<ESC>'
+ vim.echo('synIDattr(synID(line("."), col("."), 0), "name")'
+ ).downcase.should include 'string'
+ vim.feedkeys 'a\<CR>'
+ proposed_indent.should == -1
+ indent.should == 0
+ end
+
+ it "does not dedent" do
+ vim.feedkeys 'iif True:\<CR>"test:\<ESC>'
+ vim.echo('synIDattr(synID(line("."), col("."), 0), "name")'
+ ).downcase.should include 'string'
+ proposed_indent.should == shiftwidth
+ indent.should == shiftwidth
+ end
+ end
+
+ describe "when the previous line has a colon in a string" do
+ before { vim.feedkeys 'itest(":".join(["1","2"]))\<CR>' }
+ it "does not indent" do
+ vim.feedkeys 'if True:'
+ indent.should == 0
+ proposed_indent.should == 0
+ end
+ end
+
+ describe "when the previous line has a list slice" do
+ it "does not indent" do
+ vim.feedkeys 'ib = a[2:]\<CR>'
+ indent.should == 0
+ proposed_indent.should == 0
+ end
+ end
+
+ describe "when line is empty inside a block" do
+ it "is indented like the previous line" do
+ vim.feedkeys 'idef a():\<CR>1\<CR>\<CR>2\<ESC>kcc'
+ indent.should == shiftwidth
+ end
+ end
+
+ describe "when an empty line is after empty line / before non-empty" do
+ it "is indented like the next line" do
+ vim.feedkeys 'idef a():\<CR>1\<CR>\<CR>\<CR>2\<ESC><<kcc'
+ indent.should == 0
+ end
+ end
+
+ describe "when an empty line is after empty line / before non-empty (nested)" do
+ it "is indented like the next line" do
+ vim.feedkeys 'idef a():\<CR>1\<CR>\<CR>\<CR>\<ESC>0i\<TAB>2\<ESC>kcc'
+ indent.should == shiftwidth
+ end
+ end
+
+ describe "when line is empty inside a block following multi-line statement" do
+ it "is indented like the previous line" do
+ vim.feedkeys 'idef a():\<CR>x = (1 +\<CR>2)\<CR>\<CR>y\<ESC>kcc'
+ indent.should == shiftwidth
+ end
+ end
+
+ describe "when line is empty inside a block following stop statement" do
+ it "is indented like the previous line minus shiftwidth" do
+ vim.feedkeys 'iif x:\<CR>if y:\<CR>pass\<CR>\<CR>z\<ESC>kcc'
+ indent.should == shiftwidth
+ end
+ end
+