]> git.madduck.net Git - etc/vim.git/commitdiff

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:

add basic test suite using vimrunner
authorJohann Klähn <kljohann@gmail.com>
Sun, 16 Jun 2013 21:47:13 +0000 (23:47 +0200)
committerJohann Klähn <kljohann@gmail.com>
Sun, 16 Jun 2013 21:52:38 +0000 (23:52 +0200)
Gemfile [new file with mode: 0644]
indent/python.vim
spec/indent/indent_spec.rb [new file with mode: 0644]
spec/spec_helper.rb [new file with mode: 0644]

diff --git a/Gemfile b/Gemfile
new file mode 100644 (file)
index 0000000..7d08815
--- /dev/null
+++ b/Gemfile
@@ -0,0 +1,3 @@
+source 'https://rubygems.org'
+gem "vimrunner", "0.3.0"
+gem "rspec"
index 1dabb475c043533578dc6eebcee53d4d288f753e..9c3aa0cda4293d75366cf398f7861d00ffd83cbe 100644 (file)
@@ -15,7 +15,7 @@ let b:did_indent = 1
 setlocal expandtab
 setlocal nolisp
 setlocal autoindent
-setlocal indentexpr=GetPythonIndent(v:lnum)
+setlocal indentexpr=GetPythonPEPIndent(v:lnum)
 setlocal indentkeys=!^F,o,O,<:>,0),0],0},=elif,=except
 
 let s:maxoff = 50
@@ -101,7 +101,7 @@ function! s:BlockStarter(lnum, block_start_re)
     return -1
 endfunction
 
-function! GetPythonIndent(lnum)
+function! GetPythonPEPIndent(lnum)
 
     " First line has indent 0
     if a:lnum == 1
diff --git a/spec/indent/indent_spec.rb b/spec/indent/indent_spec.rb
new file mode 100644 (file)
index 0000000..3a4d3a2
--- /dev/null
@@ -0,0 +1,83 @@
+require "spec_helper"
+
+describe "vim" do
+
+  before(:each) { vim.normal 'gg"_dG' }  # clear buffer
+
+  describe "when using the indent plugin" do
+    it "sets the indentexpr and indentkeys options" do
+      vim.command("set indentexpr?").should include "GetPythonPEPIndent("
+      vim.command("set indentkeys?").should include "=elif"
+    end
+
+    it "sets autoindent and expandtab" do
+      vim.command("set autoindent?").should match(/\s*autoindent/)
+      vim.command("set expandtab?").should match(/\s*expandtab/)
+    end
+  end
+
+  describe "when entering the first line" do
+    before { vim.feedkeys 'ipass' }
+
+    it "does not indent" do
+      proposed_indent.should == 0
+      indent.should == 0
+    end
+
+    it "does not indent when using '=='" do
+      vim.normal "=="
+      indent.should == 0
+    end
+  end
+
+  describe "when after a '(' that is at the end of its line" do
+    before { vim.feedkeys 'itest(\<CR>' }
+
+    it "indents by one level" do
+      proposed_indent.should == shiftwidth
+      vim.feedkeys 'something'
+      indent.should == shiftwidth
+      vim.normal '=='
+      indent.should == shiftwidth
+    end
+
+    it "puts the closing parenthesis at the same level" do
+      vim.feedkeys ')'
+      indent.should == 0
+    end
+  end
+
+  describe "when after an '(' that is followed by something" do
+    before { vim.feedkeys 'itest(something,\<CR>' }
+
+    it "lines up on following lines" do
+      indent.should == 5
+      vim.feedkeys 'more,\<CR>'
+      indent.should == 5
+    end
+
+    it "lines up the closing parenthesis" do
+      vim.feedkeys ')'
+      indent.should == 5
+    end
+
+    it "does not touch the closing parenthesis if it is already indented further" do
+      vim.feedkeys '  )'
+      indent.should == 7
+    end
+  end
+
+  def shiftwidth
+    @shiftwidth ||= vim.echo("exists('*shiftwidth') ? shiftwidth() : &sw").to_i
+  end
+  def tabstop
+    @tabstop ||= vim.echo("&tabstop").to_i
+  end
+  def indent
+    vim.echo("indent('.')").to_i
+  end
+  def proposed_indent
+    vim.echo("GetPythonPEPIndent(line('.'))").to_i
+  end
+end
+
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
new file mode 100644 (file)
index 0000000..3a07436
--- /dev/null
@@ -0,0 +1,20 @@
+require 'vimrunner'
+require 'vimrunner/rspec'
+
+Vimrunner::RSpec.configure do |config|
+  config.reuse_server = true
+
+  config.start_vim do
+    vim = Vimrunner.start
+
+    plugin_path = File.expand_path('../..', __FILE__)
+
+    # add_plugin appends the path to the rtp... :(
+    # vim.add_plugin(plugin_path, 'indent/python.vim')
+
+    vim.command "set rtp^=#{plugin_path}"
+    vim.command "runtime indent/python.vim"
+
+    vim
+  end
+end