From: Johann Klähn Date: Sun, 16 Jun 2013 21:47:13 +0000 (+0200) Subject: add basic test suite using vimrunner X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/659ef8fe6e0fdaa4672bccf54f30f2a4b51f5917 add basic test suite using vimrunner --- diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..7d08815 --- /dev/null +++ b/Gemfile @@ -0,0 +1,3 @@ +source 'https://rubygems.org' +gem "vimrunner", "0.3.0" +gem "rspec" diff --git a/indent/python.vim b/indent/python.vim index 1dabb47..9c3aa0c 100644 --- a/indent/python.vim +++ b/indent/python.vim @@ -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 index 0000000..3a4d3a2 --- /dev/null +++ b/spec/indent/indent_spec.rb @@ -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(\' } + + 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,\' } + + it "lines up on following lines" do + indent.should == 5 + vim.feedkeys 'more,\' + 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 index 0000000..3a07436 --- /dev/null +++ b/spec/spec_helper.rb @@ -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