]> git.madduck.net Git - etc/vim.git/blobdiff - spec/indent/indent_spec.rb

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

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.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Travis: remove vint for now
[etc/vim.git] / spec / indent / indent_spec.rb
index 23c16293e953532190ff1273a01029a5b6ed5f7c..79d7f8474ec307a616eda8e6053297642170b15f 100644 (file)
@@ -52,7 +52,7 @@ shared_examples_for "vim" do
 
     it "puts the closing parenthesis at the same level" do
       vim.feedkeys ')'
-      indent.should == 0
+      indent.should == (hang_closing ? shiftwidth : 0)
     end
   end
 
@@ -87,7 +87,7 @@ shared_examples_for "vim" do
 
     it "lines up the closing parenthesis" do
       vim.feedkeys '}'
-      indent.should == 0
+      indent.should == (hang_closing ? shiftwidth : 0)
     end
   end
 
@@ -514,18 +514,31 @@ shared_examples_for "multiline strings" do
   end
 end
 
-describe "vim when using width of 4" do
-  before {
-    vim.command("set sw=4 ts=4 sts=4 et")
-  }
-  it_behaves_like "vim"
-end
+SUITE_SHIFTWIDTHS = [4, 3]
+SUITE_HANG_CLOSINGS = [nil, false, true]
 
-describe "vim when using width of 3" do
-  before {
-    vim.command("set sw=3 ts=3 sts=3 et")
-  }
-  it_behaves_like "vim"
+SUITE_SHIFTWIDTHS.each do |sw|
+  describe "vim when using width of #{sw}" do
+    before {
+      vim.command("set sw=#{sw} ts=#{sw} sts=#{sw} et")
+    }
+    it "sets shiftwidth to #{sw}" do
+      shiftwidth.should == sw
+    end
+
+    SUITE_HANG_CLOSINGS.each do |hc|
+      describe "vim when hang_closing is set to #{hc}" do
+        before {
+          set_hang_closing hc
+        }
+        it "sets hang_closing to #{hc}" do
+          hang_closing.should == !!hc
+        end
+
+        it_behaves_like "vim"
+      end
+    end
+  end
 end
 
 describe "vim when not using python_pep8_indent_multiline_string" do
@@ -587,3 +600,82 @@ describe "vim for cython" do
       end
   end
 end
+
+describe "Handles far away opening parens" do
+  before { vim.feedkeys '\<ESC>ggdGifrom foo import (' }
+
+  it "indents by one level" do
+    vim.feedkeys '\<CR>'
+    proposed_indent.should == shiftwidth
+  end
+
+  it "indents by one level for 10 lines" do
+    vim.command('set paste | exe "norm 9o" | set nopaste')
+    vim.feedkeys '\<Esc>o'
+    indent.should == shiftwidth
+  end
+
+  it "indents by one level for 50 lines" do
+    vim.command('set paste | exe "norm 49o" | set nopaste')
+    vim.feedkeys '\<Esc>o'
+    indent.should == shiftwidth
+  end
+end
+
+describe "Handles far away opening square brackets" do
+  before { vim.feedkeys '\<ESC>ggdGibar = [' }
+
+  it "indents by one level" do
+    vim.feedkeys '\<CR>'
+    proposed_indent.should == shiftwidth
+  end
+
+  it "indents by one level for 10 lines" do
+    vim.command('set paste | exe "norm 9o" | set nopaste')
+    vim.feedkeys '\<Esc>o'
+    indent.should == shiftwidth
+  end
+
+  it "indents by one level for 100 lines" do
+    vim.command('set paste | exe "norm 99o" | set nopaste')
+    vim.feedkeys '\<Esc>o'
+    indent.should == shiftwidth
+  end
+end
+
+describe "Handles far away opening curly brackets" do
+  before { vim.feedkeys '\<ESC>ggdGijson = {' }
+
+  it "indents by one level" do
+    vim.feedkeys '\<CR>'
+    vim.feedkeys '\<Esc>o'
+    proposed_indent.should == shiftwidth
+  end
+
+  it "indents by one level for 10 lines" do
+    vim.command('set paste | exe "norm 9o" | set nopaste')
+    vim.feedkeys '\<Esc>o'
+    indent.should == shiftwidth
+  end
+
+  it "indents by one level for 1000 lines" do
+    vim.command('set paste | exe "norm 999o" | set nopaste')
+    vim.feedkeys '\<Esc>o'
+    indent.should == shiftwidth
+  end
+end
+
+describe "Compact multiline dict" do
+  before { vim.feedkeys '\<ESC>ggdGid = {"one": 1,' }
+
+  it "gets indented correctly" do
+    vim.feedkeys '\<CR>'
+    proposed_indent.should == 5
+
+    vim.feedkeys '"two": 2}'
+    proposed_indent.should == 5
+
+    vim.feedkeys '\<CR>'
+    proposed_indent.should == 0
+  end
+end