X-Git-Url: https://git.madduck.net/etc/vim.git/blobdiff_plain/502aea33111e33371315b4b5e93f4ba3452dbf80..eed8e99ce344d773997c4683aef9de3e2ed7ec62:/spec/indent/indent_spec.rb diff --git a/spec/indent/indent_spec.rb b/spec/indent/indent_spec.rb index bd0d0d9..a622cf8 100644 --- a/spec/indent/indent_spec.rb +++ b/spec/indent/indent_spec.rb @@ -67,6 +67,20 @@ shared_examples_for "vim" do 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\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\' + indent.should == 0 + end + end + describe "when using simple control structures" do it "indents shiftwidth spaces" do vim.feedkeys 'iwhile True:\pass' @@ -109,6 +123,72 @@ shared_examples_for "vim" do end end + describe "when an 'if' is followed by" do + before { vim.feedkeys 'i\\if x:\' } + it "an elif, it lines up with the 'if'" do + vim.feedkeys 'elif y:' + indent.should == shiftwidth * 2 + end + + it "an 'else', it lines up with the 'if'" do + vim.feedkeys 'else:' + indent.should == shiftwidth * 2 + end + end + + describe "when a 'for' is followed by" do + before { vim.feedkeys 'i\\for x in y:\' } + it "an 'else', it lines up with the 'for'" do + vim.feedkeys 'else:' + indent.should == shiftwidth * 2 + end + end + + describe "when an 'else' is followed by" do + before { vim.feedkeys 'i\\else:\XXX\' } + it "a 'finally', it lines up with the 'else'" do + vim.feedkeys 'finally:' + indent.should == shiftwidth * 2 + end + end + + + describe "when a 'try' is followed by" do + before { vim.feedkeys 'i\\try:\' } + it "an 'except', it lines up with the 'try'" do + vim.feedkeys 'except:' + indent.should == shiftwidth * 2 + end + + it "an 'else', it lines up with the 'try'" do + vim.feedkeys 'else:' + indent.should == shiftwidth * 2 + end + + it "a 'finally', it lines up with the 'try'" do + vim.feedkeys 'finally:' + indent.should == shiftwidth * 2 + end + end + + describe "when an 'except' is followed by" do + before { vim.feedkeys 'i\\except:\' } + it "an 'else', it lines up with the 'except'" do + vim.feedkeys 'else:' + indent.should == shiftwidth * 2 + end + + it "another 'except', it lines up with the previous 'except'" do + vim.feedkeys 'except:' + indent.should == shiftwidth * 2 + end + + it "a 'finally', it lines up with the 'except'" do + vim.feedkeys 'finally:' + indent.should == shiftwidth * 2 + end + end + def shiftwidth @shiftwidth ||= vim.echo("exists('*shiftwidth') ? shiftwidth() : &sw").to_i end