X-Git-Url: https://git.madduck.net/etc/vim.git/blobdiff_plain/105f8eccc98313a6c848ebf28651d77af14a1a76..31a2fd4cf80abba74dc3ef9fb0ceed8b540d2a1c:/spec/indent/indent_spec.rb?ds=inline diff --git a/spec/indent/indent_spec.rb b/spec/indent/indent_spec.rb index 932a091..21d14b7 100644 --- a/spec/indent/indent_spec.rb +++ b/spec/indent/indent_spec.rb @@ -67,6 +67,20 @@ describe "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' @@ -91,6 +105,24 @@ describe "vim" do end end + describe "when current line is dedented compared to previous line" do + before { vim.feedkeys 'i\\if x:\return True\\' } + it "and current line has a valid indentation (Part 1)" do + vim.feedkeys '0i\if y:' + proposed_indent.should == -1 + end + + it "and current line has a valid indentation (Part 2)" do + vim.feedkeys '0i\\if y:' + proposed_indent.should == -1 + end + + it "and current line has an invalid indentation" do + vim.feedkeys 'i while True:\' + indent.should == previous_indent + shiftwidth + end + end + def shiftwidth @shiftwidth ||= vim.echo("exists('*shiftwidth') ? shiftwidth() : &sw").to_i end @@ -100,6 +132,10 @@ describe "vim" do def indent vim.echo("indent('.')").to_i end + def previous_indent + pline = vim.echo("line('.')").to_i - 1 + vim.echo("indent('#{pline}')").to_i + end def proposed_indent line = vim.echo("line('.')") col = vim.echo("col('.')")