Pathogen and new bundles

git-svn-id: http://photonzero.com/dotfiles/trunk@65 23f722f6-122a-0410-8cef-c75bd312dd78
This commit is contained in:
michener 2010-09-21 23:59:55 +00:00
parent 9b767aed56
commit 96a93bce9e
78 changed files with 10717 additions and 0 deletions

View file

@ -0,0 +1,80 @@
# Copyright 2010 Wincent Colaiuta. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
require File.expand_path('../spec_helper', File.dirname(__FILE__))
require 'command-t/finder'
module VIM; end
describe CommandT::Finder do
before :all do
@finder = CommandT::Finder.new File.join(File.dirname(__FILE__), '..',
'..', 'fixtures')
@all_fixtures = %w(
bar/abc
bar/xyz
baz
bing
foo/alpha/t1
foo/alpha/t2
foo/beta
)
end
before do
# scanner will call VIM's expand() function for exclusion filtering
stub(::VIM).evaluate(/expand\(.+\)/) { '0' }
end
describe 'sorted_matches_for method' do
it 'should return an empty array when no matches' do
@finder.sorted_matches_for('kung foo fighting').should == []
end
it 'should return all files when query string is empty' do
@finder.sorted_matches_for('').should == @all_fixtures
end
it 'should return files in alphabetical order when query string is empty' do
results = @finder.sorted_matches_for('')
results.should == results.sort
end
it 'should return matching files in score order' do
@finder.sorted_matches_for('ba').
should == %w(baz bar/abc bar/xyz foo/beta)
@finder.sorted_matches_for('a').
should == %w(baz bar/abc bar/xyz foo/alpha/t1 foo/alpha/t2 foo/beta)
end
it 'should obey the :limit option for empty search strings' do
@finder.sorted_matches_for('', :limit => 2).
should == %w(bar/abc bar/xyz)
end
it 'should obey the :limit option for non-empty search strings' do
@finder.sorted_matches_for('a', :limit => 3).
should == %w(baz bar/abc bar/xyz)
end
end
end

View file

@ -0,0 +1,236 @@
# Copyright 2010 Wincent Colaiuta. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
require File.expand_path('../spec_helper', File.dirname(__FILE__))
require 'command-t/ext'
describe CommandT::Match do
def match_for path, pattern
CommandT::Match.new path, pattern
end
it 'requires pattern to be lowercase' do
# this is an optimization: we ask our caller (the Matcher class) to
# downcase once before calling us, rather than downcase repeatedly
# during looping, recursion, and initialization of thousands of Match
# instances
match_for('foo', 'Foo').matches?.should == false
end
describe '#matches?' do
it 'returns false for non-matches' do
match_for('foo', 'bar').matches?.should == false
end
it 'returns true for matches' do
match_for('foo', 'foo').matches?.should == true
end
it 'returns true for empty search strings' do
match_for('foo', '').matches?.should == true
end
it 'returns false for overlength matches' do
match_for('foo', 'foo...').matches?.should == false
end
end
describe 'score method' do
it 'assigns a score of 1.0 for empty search string' do
match_for('foo', '').score.should == 1.0
end
it 'assigns a score of zero for a non-match' do
match_for('foo', 'bar').score.should == 0.0
end
it 'assigns a score of zero for an overlength match' do
match_for('foo', 'foo...').score.should == 0.0
end
it 'assigns perfect matches a score of one' do
match_for('foo', 'foo').score.should == 1.0
end
it 'assigns perfect but incomplete matches a score of less than one' do
match_for('foo', 'f').score.should < 1.0
end
it 'prioritizes matches with more matching characters' do
few_matches = match_for('foobar', 'fb')
many_matches = match_for('foobar', 'fbar')
many_matches.score.should > few_matches.score
end
it 'prioritizes shorter paths over longer ones' do
short_path = match_for('article.rb', 'art')
long_path = match_for('articles_controller_spec.rb', 'art')
short_path.score.should > long_path.score
end
it 'prioritizes matches after "/"' do
normal_match = match_for('fooobar', 'b')
special_match = match_for('foo/bar', 'b')
special_match.score.should > normal_match.score
# note that / beats _
normal_match = match_for('foo_bar', 'b')
special_match = match_for('foo/bar', 'b')
special_match.score.should > normal_match.score
# / also beats -
normal_match = match_for('foo-bar', 'b')
special_match = match_for('foo/bar', 'b')
special_match.score.should > normal_match.score
# and numbers
normal_match = match_for('foo9bar', 'b')
special_match = match_for('foo/bar', 'b')
special_match.score.should > normal_match.score
# and periods
normal_match = match_for('foo.bar', 'b')
special_match = match_for('foo/bar', 'b')
special_match.score.should > normal_match.score
# and spaces
normal_match = match_for('foo bar', 'b')
special_match = match_for('foo/bar', 'b')
special_match.score.should > normal_match.score
end
it 'prioritizes matches after "-"' do
normal_match = match_for('fooobar', 'b')
special_match = match_for('foo-bar', 'b')
special_match.score.should > normal_match.score
# - also beats .
normal_match = match_for('foo.bar', 'b')
special_match = match_for('foo-bar', 'b')
special_match.score.should > normal_match.score
end
it 'prioritizes matches after "_"' do
normal_match = match_for('fooobar', 'b')
special_match = match_for('foo_bar', 'b')
special_match.score.should > normal_match.score
# _ also beats .
normal_match = match_for('foo.bar', 'b')
special_match = match_for('foo_bar', 'b')
special_match.score.should > normal_match.score
end
it 'prioritizes matches after " "' do
normal_match = match_for('fooobar', 'b')
special_match = match_for('foo bar', 'b')
special_match.score.should > normal_match.score
# " " also beats .
normal_match = match_for('foo.bar', 'b')
special_match = match_for('foo bar', 'b')
special_match.score.should > normal_match.score
end
it 'prioritizes matches after numbers' do
normal_match = match_for('fooobar', 'b')
special_match = match_for('foo9bar', 'b')
special_match.score.should > normal_match.score
# numbers also beat .
normal_match = match_for('foo.bar', 'b')
special_match = match_for('foo9bar', 'b')
special_match.score.should > normal_match.score
end
it 'prioritizes matches after periods' do
normal_match = match_for('fooobar', 'b')
special_match = match_for('foo.bar', 'b')
special_match.score.should > normal_match.score
end
it 'prioritizes matching capitals following lowercase' do
normal_match = match_for('foobar', 'b')
special_match = match_for('fooBar', 'b')
special_match.score.should > normal_match.score
end
it 'prioritizes matches earlier in the string' do
early_match = match_for('**b*****', 'b')
late_match = match_for('******b*', 'b')
early_match.score.should > late_match.score
end
it 'prioritizes matches closer to previous matches' do
early_match = match_for('**bc****', 'bc')
late_match = match_for('**b***c*', 'bc')
early_match.score.should > late_match.score
end
it 'scores alternative matches of same path differently' do
# given path: app/controllers/articles_controller.rb
left_to_right_match = match_for('a**/****r******/**t*c***_*on*******.**', 'artcon')
best_match = match_for('***/***********/art*****_con*******.**', 'artcon')
best_match.score.should > left_to_right_match.score
end
it 'returns the best possible score among alternatives' do
# given path: app/controllers/articles_controller.rb
best_match = match_for('***/***********/art*****_con*******.**', 'artcon')
chosen_match = match_for('app/controllers/articles_controller.rb', 'artcon')
chosen_match.score.should == best_match.score
end
it 'provides intuitive results for "artcon" and "articles_controller"' do
low = match_for('app/controllers/heartbeat_controller.rb', 'artcon')
high = match_for('app/controllers/articles_controller.rb', 'artcon')
high.score.should > low.score
end
it 'provides intuitive results for "aca" and "a/c/articles_controller"' do
low = match_for 'app/controllers/heartbeat_controller.rb', 'aca'
high = match_for 'app/controllers/articles_controller.rb', 'aca'
best_match = match_for 'a**/c**********/a******************.**', 'aca'
high.score.should > low.score
high.score.should == best_match.score
end
it 'provides intuitive results for "d" and "doc/command-t.txt"' do
low = match_for 'TODO', 'd'
high = match_for 'doc/command-t.txt', 'd'
high.score.should > low.score
end
it 'provides intuitive results for "do" and "doc/command-t.txt"' do
low = match_for 'TODO', 'do'
high = match_for 'doc/command-t.txt', 'do'
high.score.should > low.score
end
end
describe 'to_s method' do
it 'returns the entire matched string' do
match_for('abc', 'abc').to_s.should == 'abc'
end
end
end

View file

@ -0,0 +1,76 @@
# Copyright 2010 Wincent Colaiuta. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
require File.expand_path('../spec_helper', File.dirname(__FILE__))
require 'command-t/scanner'
require 'command-t/ext'
describe CommandT::Matcher do
describe 'initialization' do
it 'should raise an ArgumentError if passed nil' do
lambda { CommandT::Matcher.new nil }.
should raise_error(ArgumentError)
end
end
describe '#matches_for' do
before do
@scanner = Object.new
end
it 'raises an ArgumentError if passed nil' do
@matcher = CommandT::Matcher.new @scanner
lambda { @matcher.matches_for(nil) }.
should raise_error(ArgumentError)
end
it 'returns empty array when source array empty' do
stub(@scanner).paths { [] }
@no_paths = CommandT::Matcher.new @scanner
@no_paths.matches_for('foo').should == []
@no_paths.matches_for('').should == []
end
it 'returns empty array when no matches' do
stub(@scanner).paths { ['foo/bar', 'foo/baz', 'bing'] }
@no_matches = CommandT::Matcher.new @scanner
@no_matches.matches_for('xyz').should == []
end
it 'returns matching paths' do
stub(@scanner).paths { ['foo/bar', 'foo/baz', 'bing'] }
@foo_paths = CommandT::Matcher.new @scanner
matches = @foo_paths.matches_for('z')
matches.map { |m| m.to_s }.should == ['foo/baz']
matches = @foo_paths.matches_for('bg')
matches.map { |m| m.to_s }.should == ['bing']
end
it 'performs case-insensitive matching' do
stub(@scanner).paths { ['Foo'] }
@path = CommandT::Matcher.new @scanner
matches = @path.matches_for('f')
matches.map { |m| m.to_s }.should == ['Foo']
end
end
end

View file

@ -0,0 +1,82 @@
# Copyright 2010 Wincent Colaiuta. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
require File.expand_path('../spec_helper', File.dirname(__FILE__))
require 'command-t/scanner'
module VIM; end
describe CommandT::Scanner do
before do
@dir = File.join(File.dirname(__FILE__), '..', '..', 'fixtures')
@all_fixtures = \
%w(bar/abc bar/xyz baz bing foo/alpha/t1 foo/alpha/t2 foo/beta)
@scanner = CommandT::Scanner.new @dir
# scanner will call VIM's expand() function for exclusion filtering
stub(::VIM).evaluate(/expand\(.+\)/) { '0' }
end
describe 'paths method' do
it 'should return a list of regular files' do
@scanner.paths.should =~ @all_fixtures
end
end
describe 'flush method' do
it 'should force a rescan on next call to paths method' do
first = @scanner.paths
@scanner.flush
@scanner.paths.object_id.should_not == first.object_id
end
end
describe 'path= method' do
it 'should allow repeated applications of scanner at different paths' do
@scanner.paths.should =~ @all_fixtures
# drill down 1 level
@scanner.path = File.join(@dir, 'foo')
@scanner.paths.should =~ %w(alpha/t1 alpha/t2 beta)
# and another
@scanner.path = File.join(@dir, 'foo', 'alpha')
@scanner.paths.should =~ %w(t1 t2)
end
end
describe "'wildignore' exclusion" do
it "should call on VIM's expand() function for pattern filtering" do
@scanner = CommandT::Scanner.new @dir
mock(::VIM).evaluate(/expand\(.+\)/).times(10)
@scanner.paths
end
end
describe ':max_depth option' do
it 'should not descend below "max_depth" levels' do
@scanner = CommandT::Scanner.new @dir, :max_depth => 1
@scanner.paths.should =~ %w(bar/abc bar/xyz baz bing foo/beta)
end
end
end

View file

@ -0,0 +1,38 @@
# Copyright 2010 Wincent Colaiuta. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
if !Object.const_defined?('Bundler')
require 'rubygems'
require 'bundler'
Bundler.setup
end
require 'rspec'
lib = File.expand_path('../ruby', File.dirname(__FILE__))
unless $LOAD_PATH.include? lib
$LOAD_PATH.unshift lib
end
RSpec.configure do |config|
config.mock_framework = :rr
end

View file

@ -0,0 +1,41 @@
require 'spec/runner/formatter/base_text_formatter'
require 'pathname'
# Format spec results for display in the Vim quickfix window
# Use this custom formatter like this:
# spec -r spec/vim_formatter.rb -f Spec::Runner::Formatter::VimFormatter spec
module Spec
module Runner
module Formatter
class VimFormatter < BaseTextFormatter
# TODO: handle pending issues
# TODO: vim-side function for printing progress
def dump_failure counter, failure
path = failure.exception.backtrace.find do |frame|
frame =~ %r{\bspec/.*_spec\.rb:\d+\z}
end
message = failure.exception.message.gsub("\n", ' ')
@output.puts "#{relativize_path(path)}: #{message}" if path
end
def dump_pending; end
def dump_summary duration, example_count, failure_count, pending_count
end
private
def relativize_path path
@wd ||= Pathname.new Dir.getwd
begin
return Pathname.new(path).relative_path_from(@wd)
rescue ArgumentError
# raised unless both paths relative, or both absolute
return path
end
end
end # class VimFormatter
end # module Formatter
end # module Runner
end # module Spec