cldwalker-lightning 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT LICENSE
2
2
 
3
- Copyright (c) 2008 Gabriel Horner
3
+ Copyright (c) 2009 Gabriel Horner
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
data/README.markdown CHANGED
@@ -13,14 +13,31 @@ you type or complete
13
13
 
14
14
  bash> rvim irb.rb
15
15
 
16
- Uneasy about what lightning will execute? Test it out with a -test flag
16
+ Uneasy about what lightning will execute? Test/print it out with a -test flag
17
17
 
18
18
  bash> rvim -test irb.rb
19
19
  rvim '/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb.rb'
20
20
 
21
+ Want to autocomplete but don't remember how the basename starts? Just use a ruby regular expression:
22
+
23
+ # *'s are converted to .*'s for convience sakes
24
+ bash> rvim *dialog [TAB TAB]
25
+ canvasprintdialog.rb
26
+ extfileselectiondialog.rb
27
+ dialog.rb//System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/tk
28
+ fileselectiondialog.rb
29
+ dialog.rb//System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/tkextlib/bwidget
30
+ finddialog.rb
31
+
32
+ #re-edit your line to narrow down your completion to one entry
33
+ bash> rvim ca*dialog [TAB TAB]
34
+
35
+ #once the basename completes, you can execute your command
36
+ bash> rvim canvasprintdialog.rb
37
+
21
38
  As you can see, you only need to autocomplete the basenames of paths and lightning will resolve their
22
- full paths. rvim is a lightning command configured to autocomplete a certain group of paths for vim.
23
- In this case, rvim is configured to complete my ruby core and standard library files.
39
+ full paths. In these examples, rvim is a lightning command configured to autocomplete a certain group of paths for vim.
40
+ In my case, rvim is configured to complete my ruby core and standard library files.
24
41
 
25
42
 
26
43
  Install
@@ -60,6 +77,12 @@ Since the globbable paths are interpreted by ruby's Dir.glob(), you can:
60
77
 
61
78
  `ri Dir.glob` for more examples.
62
79
 
80
+ Aliases
81
+ =======
82
+
83
+ Lightning supports custom aliases for any path, globally and per command. So if there is some
84
+ path that you access often but that's still too slow with completion, alias it away!
85
+
63
86
  Configuration
64
87
  =====================
65
88
 
@@ -70,7 +93,15 @@ Configuration options are:
70
93
  * generated\_file: Location of shell script file generated from config. Defaults to
71
94
  ~/.lightning\_completions.
72
95
  * ignore\_paths: List of paths to globally ignore when listing completions.
96
+ * complete\_regex: true or false (default is true)
97
+ Turns on/off Ruby regular expression matching when completing. One convience
98
+ is that a '*' is converted to '.*' ie glob-like behavior.
99
+
100
+ Note: Realize your regular expression normally just match the basename. However, since duplicates
101
+ list their full paths, their full paths are subject to regex matching.
73
102
  * shell: Specifies shell script generator used for generating completions. Defaults to bash.
103
+ * aliases: A hash (pairs) of custom aliases pointing to full paths. These aliases will be globally
104
+ recognized by any lightning command.
74
105
  * commands: A list of lightning commands. A lightning command is just a shell function
75
106
  which executes a specified shell function with a defined set of paths to autocomplete on.
76
107
  A command consists of the following options/keys:
@@ -80,6 +111,7 @@ Configuration options are:
80
111
  * description: Description which is placed as a comment in the generated shell script.
81
112
  * paths (required): A list of globbable paths, whose basenames are autocompleted. You can also
82
113
  pass this a path name that has been defined in the paths option.
114
+ * aliases: A hash (pairs) of custom aliases and full paths only for this command.
83
115
 
84
116
  * paths: This takes a hash (pairs) of path names and globbable paths. This should be used when
85
117
  you have a group of paths that are used in multiple commands. When doing that, you would specify
@@ -124,6 +156,5 @@ I had to do something.
124
156
  Todo/Ideas
125
157
  ==========
126
158
 
127
- * Aliases for common autocompletions.
128
159
  * Allow lightning commands to only path-resolve one of multiple arguments given.
129
160
  * Command interface to easily add/remove current directory or globs from a command
data/Rakefile ADDED
@@ -0,0 +1,68 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+ begin
5
+ require 'rcov/rcovtask'
6
+
7
+ Rcov::RcovTask.new do |t|
8
+ t.libs << 'test'
9
+ t.test_files = FileList['test/**/*_test.rb']
10
+ t.rcov_opts = ["-T -x '/Library/Ruby/*'"]
11
+ t.verbose = true
12
+ end
13
+ rescue LoadError
14
+ puts "Rcov not available. Install it for rcov-related tasks with: sudo gem install rcov"
15
+ end
16
+
17
+ begin
18
+ require 'jeweler'
19
+ Jeweler::Tasks.new do |s|
20
+ s.name = "lightning"
21
+ s.executables = ["lightning-complete", "lightning-full_path", "lightning-install"]
22
+ s.summary = "Path completions for your shell that will let you navigate like lightning."
23
+ s.email = "gabriel.horner@gmail.com"
24
+ s.homepage = "http://github.com/cldwalker/lightning"
25
+ s.description = "Path completions for your shell that will let you navigate like lightning."
26
+ s.authors = ["Gabriel Horner"]
27
+ s.files = FileList["Rakefile", "VERSION.yml", "lightning_completions.example", "lightning.yml.example","README.markdown", "LICENSE.txt", "{bin,lib,test}/**/*"]
28
+ s.has_rdoc = true
29
+ s.extra_rdoc_files = ["README.markdown", "LICENSE.txt"]
30
+ end
31
+
32
+ rescue LoadError
33
+ puts "Jeweler not available. Install it for jeweler-related tasks with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
34
+ end
35
+
36
+ Rake::TestTask.new do |t|
37
+ t.libs << 'lib'
38
+ t.pattern = 'test/**/*_test.rb'
39
+ t.verbose = false
40
+ end
41
+
42
+ Rake::RDocTask.new do |rdoc|
43
+ rdoc.rdoc_dir = 'rdoc'
44
+ rdoc.title = 'test'
45
+ rdoc.options << '--line-numbers' << '--inline-source'
46
+ rdoc.rdoc_files.include('README*')
47
+ rdoc.rdoc_files.include('lib/**/*.rb')
48
+ end
49
+
50
+ namespace :dev do
51
+ desc "Generates completion, modifies it for local development"
52
+ task :reload=>:generate_completions do
53
+ file = 'lightning_completions'
54
+ string = File.read(file)
55
+ string.sub!(/^LBIN_PATH/,'#LBIN_PATH')
56
+ string.sub!(/^#LBIN_PATH/,'LBIN_PATH')
57
+ File.open(file,'w') {|f| f.write(string) }
58
+ end
59
+
60
+ desc "Generates local completion file to be sourced by your shell"
61
+ task :generate_completions do
62
+ $:.unshift 'lib'
63
+ require 'lightning'
64
+ Lightning::Generator.generate_completions 'lightning_completions'
65
+ end
66
+ end
67
+
68
+ task :default => :test
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :minor: 2
3
+ :patch: 0
4
+ :major: 0
data/lib/lightning.rb CHANGED
@@ -4,7 +4,7 @@ require 'lightning/bolt'
4
4
  require 'lightning/bolts'
5
5
  require 'lightning/completion'
6
6
  require 'lightning/config'
7
- require 'lightning/path_map'
7
+ require 'lightning/completion_map'
8
8
  require 'lightning/core_extensions'
9
9
  require 'lightning/generator'
10
10
 
@@ -7,11 +7,13 @@ class Lightning
7
7
  end
8
8
 
9
9
  def completions
10
- path_map.keys
10
+ completion_map.keys
11
11
  end
12
12
 
13
- def path_map
14
- @path_map ||= Lightning::PathMap.new(self.paths)
13
+ def completion_map
14
+ @completion_map ||= Lightning::CompletionMap.new(self.paths,
15
+ :global_aliases=>Lightning.config[:aliases],
16
+ :aliases=>Lightning.config_command(Lightning.current_command)['aliases'])
15
17
  end
16
18
 
17
19
  def resolve_completion(basename)
@@ -21,11 +23,11 @@ class Lightning
21
23
  # if (regex = Lightning.config_command(Lightning.current_command)['completion_regex'])
22
24
  # basename = basename[/#{regex}/]
23
25
  # end
24
- path_map[basename] || ''
26
+ completion_map[basename] || ''
25
27
  end
26
28
 
27
29
  def paths
28
30
  @paths ||= Lightning.config[:paths][key] || []
29
31
  end
30
32
  end
31
- end
33
+ end
@@ -12,10 +12,23 @@ class Lightning
12
12
  end
13
13
 
14
14
  def matches
15
- possible_completions.select do |e|
16
- e[0, typed.length] == typed
15
+ if Lightning.config[:complete_regex]
16
+ begin
17
+ possible_completions.grep(/#{blob_to_regex(typed)}/)
18
+ rescue RegexpError
19
+ ['Error: Invalid regular expression']
20
+ end
21
+ else
22
+ possible_completions.select do |e|
23
+ e[0, typed.length] == typed
24
+ end
17
25
  end
18
26
  end
27
+
28
+ #just converts * to .* to make a glob-like regex
29
+ def blob_to_regex(string)
30
+ string.gsub(/^\*|([^\.])\*/) {|e| $1 ? $1 + ".*" : ".*" }
31
+ end
19
32
 
20
33
  def typed
21
34
  # @text_typed[/\s(.+?)$/, 1] || ''
@@ -1,20 +1,22 @@
1
1
  #This class maps completions to their full paths for the given blobs
2
2
  class Lightning
3
- class PathMap
3
+ class CompletionMap
4
4
  attr_accessor :map
5
+ attr_reader :alias_map
5
6
 
6
7
  def initialize(*globs)
7
- #globs need to be an array
8
+ options = globs[-1].is_a?(Hash) ? globs.pop : {}
8
9
  globs.flatten!
9
10
  @map = create_map_for_globs(globs)
11
+ @alias_map = (options[:global_aliases] || {}).merge(options[:aliases] || {})
10
12
  end
11
13
 
12
14
  def [](completion)
13
- @map[completion]
15
+ @map[completion] || @alias_map[completion]
14
16
  end
15
17
 
16
18
  def keys
17
- @map.keys
19
+ (@map.keys + @alias_map.keys).uniq
18
20
  end
19
21
 
20
22
  #should return hash
@@ -1,4 +1,5 @@
1
1
  module Lightning::Config
2
+ attr_accessor :config_file
2
3
  def load_config
3
4
  @config = setup_config
4
5
  end
@@ -7,16 +8,21 @@ module Lightning::Config
7
8
  @config ||= setup_config
8
9
  end
9
10
 
11
+ def config=(value)
12
+ @config = value
13
+ end
14
+
10
15
  def setup_config
11
16
  hash = read_config_file
12
17
  configure_commands_and_paths(hash)
13
18
  hash
14
19
  end
15
20
 
16
- def read_config_file(config_file=nil)
17
- default_config = {:shell=>'bash', :generated_file=>File.expand_path(File.join('~', '.lightning_completions'))}
18
- config_file ||= File.exists?('lightning.yml') ? 'lightning.yml' : File.expand_path(File.join("~",".lightning.yml"))
19
- hash = YAML::load(File.new(config_file))
21
+ def read_config_file(file=nil)
22
+ default_config = {:shell=>'bash', :generated_file=>File.expand_path(File.join('~', '.lightning_completions')),
23
+ :complete_regex=>true}
24
+ @config_file = file || @config_file || (File.exists?('lightning.yml') ? 'lightning.yml' : File.expand_path(File.join("~",".lightning.yml")))
25
+ hash = YAML::load(File.new(@config_file))
20
26
  default_config.merge(hash.symbolize_keys)
21
27
  end
22
28
 
@@ -44,6 +44,8 @@ commands:
44
44
  paths:
45
45
  - /Library/Ruby/Site/1.8/**/
46
46
  - /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/**/
47
+ aliases:
48
+ r1: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8
47
49
 
48
50
  - name : oa
49
51
  map_to : open -a
data/test/bolt_test.rb ADDED
@@ -0,0 +1,36 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ class Lightning::BoltTest < Test::Unit::TestCase
4
+ context "Bolt" do
5
+ before(:each) do
6
+ @completion_map = {'path1'=>'/dir/path1','path2'=>'/dir/path2'}
7
+ @bolt = Lightning::Bolt.new('blah')
8
+ @bolt.completion_map.map = @completion_map
9
+ end
10
+
11
+ test "fetches correct completions" do
12
+ assert_equal @bolt.completions, @completion_map.keys
13
+ end
14
+
15
+ test "resolves completion" do
16
+ assert_equal @completion_map['path1'], @bolt.resolve_completion('path1')
17
+ end
18
+
19
+ test "resolves completion with test flag" do
20
+ assert_equal @completion_map['path1'], @bolt.resolve_completion('-test path1')
21
+ end
22
+
23
+ test "creates completion_map only once" do
24
+ assert_equal @bolt.completion_map.object_id, @bolt.completion_map.object_id
25
+ end
26
+ end
27
+
28
+ test "Bolt's completion_map sets up alias map with options" do
29
+ old_config = Lightning.config
30
+ Lightning.stub!(:current_command, :return=>'blah')
31
+ Lightning.config = {:aliases=>{'path1'=>'/dir1/path1'}, :commands=>[{'name'=>'blah'}], :paths=>{}}
32
+ @bolt = Lightning::Bolt.new('blah')
33
+ assert_equal({'path1'=>'/dir1/path1'}, @bolt.completion_map.alias_map)
34
+ Lightning.config = old_config
35
+ end
36
+ end
@@ -0,0 +1,58 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ class Lightning::CompletionMapTest < Test::Unit::TestCase
4
+
5
+ context "CompletionMap" do
6
+ def create_map(path_hash, new_options={})
7
+ Dir.stub!(:glob) { path_hash.values }
8
+ @completion_map = Lightning::CompletionMap.new('blah', new_options)
9
+ end
10
+
11
+ test "creates basic map" do
12
+ expected_map = {"path1"=>"/dir1/path1", "path2"=>"/dir1/path2"}
13
+ create_map(expected_map)
14
+ assert_equal expected_map, @completion_map.map
15
+ end
16
+
17
+ test "ignores paths from Lightning.ignore_paths" do
18
+ Lightning.stub!(:ignore_paths, :return=>['path1'])
19
+ expected_map = {"path1"=>"/dir1/path1", "path2"=>"/dir1/path2"}
20
+ create_map(expected_map)
21
+ assert_equal expected_map.slice('path2'), @completion_map.map
22
+ end
23
+
24
+ test "creates map with duplicates" do
25
+ expected_map = {"path1//dir3"=>"/dir3/path1", "path2"=>"/dir1/path2", "path1//dir1"=>"/dir1/path1", "path1//dir2"=>"/dir2/path1"}
26
+ create_map(expected_map)
27
+ assert_equal expected_map, @completion_map.map
28
+ end
29
+
30
+ test "fetches correct path completion" do
31
+ map = {"path1"=>"/dir1/path1", "path2"=>"/dir1/path2"}
32
+ create_map(map)
33
+ assert_equal '/dir1/path1', @completion_map['path1']
34
+ end
35
+
36
+ test "creates alias map" do
37
+ create_map({}, :aliases=>{'path3'=>'/dir1/path3'}, :global_aliases=>{'path2'=>'/dir1/path2'})
38
+ assert_equal({"path2"=>"/dir1/path2", "path3"=>"/dir1/path3"}, @completion_map.alias_map)
39
+ end
40
+
41
+ test "fetches correct alias completion" do
42
+ create_map({}, :aliases=>{'path3'=>'/dir1/path3'})
43
+ assert_equal '/dir1/path3', @completion_map['path3']
44
+ end
45
+
46
+ test "fetches correct global alias completion" do
47
+ map = {"path1"=>"/dir1/path1", "path2"=>"/dir1/path2"}
48
+ create_map(map, :global_aliases=>{'path3'=>'/dir1/path3'})
49
+ assert_equal '/dir1/path3', @completion_map['path3']
50
+ end
51
+
52
+ test "keys include aliases" do
53
+ map = {"path2"=>"/dir1/path2"}
54
+ create_map(map, :global_aliases=>{'path3'=>'/dir1/path3'})
55
+ assert_arrays_equal ['path2','path3'], @completion_map.keys
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,49 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ class Lightning::CompletionTest < Test::Unit::TestCase
4
+ context "Completion" do
5
+ before(:each) {
6
+ @key = 'blah';
7
+ Lightning.bolts[@key].stub!(:completions, :return=>%w{at ap blah})
8
+ Lightning.config[:complete_regex] = true
9
+ }
10
+ test "from script matches" do
11
+ Lightning.config[:complete_regex] = false
12
+ assert_arrays_equal %w{at ap}, Lightning::Completion.complete('cd-test a', @key)
13
+ end
14
+
15
+ test "for basic case matches" do
16
+ Lightning.config[:complete_regex] = false
17
+ @completion = Lightning::Completion.new('cd-test a', @key)
18
+ assert_arrays_equal %w{at ap}, @completion.matches
19
+ end
20
+
21
+ test "with test flag matches" do
22
+ Lightning.config[:complete_regex] = false
23
+ @completion = Lightning::Completion.new('cd-test -test a', @key)
24
+ assert_arrays_equal %w{at ap}, @completion.matches
25
+ end
26
+
27
+ test "with complete_regex on matches" do
28
+ Lightning.config[:complete_regex] = true
29
+ @completion = Lightning::Completion.new('cd-test *', @key)
30
+ assert_arrays_equal %w{at ap blah}, @completion.matches
31
+ end
32
+
33
+ test "with invalid regex is rescued" do
34
+ Lightning.config[:complete_regex] = true
35
+ @completion = Lightning::Completion.new('cd-test []', @key)
36
+ assert !@completion.matches.grep(/Error/).empty?
37
+ end
38
+ end
39
+
40
+ test "blob_to_regex converts * to .*" do
41
+ @lc = Lightning::Completion.new('blah', @key)
42
+ assert_equal '.*a.*blah', @lc.blob_to_regex('*a*blah')
43
+ end
44
+
45
+ test "blob_to_regex doesn't modify .*" do
46
+ @lc = Lightning::Completion.new('blah', @key)
47
+ assert_equal '.*blah.*', @lc.blob_to_regex('.*blah.*')
48
+ end
49
+ end
@@ -1,6 +1,6 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
2
 
3
- class LightningConfigTest < Test::Unit::TestCase
3
+ class Lightning::ConfigTest < Test::Unit::TestCase
4
4
  context "A config" do
5
5
  before(:all) {
6
6
  @config = Lightning.read_config_file(File.dirname(__FILE__) + '/lightning.yml')
@@ -15,7 +15,7 @@ class LightningConfigTest < Test::Unit::TestCase
15
15
  end
16
16
 
17
17
  should "have read supported keys" do
18
- supported_keys = [:generated_file, :commands, :ignore_paths, :paths, :shell]
18
+ supported_keys = [:generated_file, :commands, :ignore_paths, :paths, :shell, :complete_regex]
19
19
  assert_arrays_equal supported_keys, @config.keys
20
20
  end
21
21
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
2
 
3
3
  class LightningTest < Test::Unit::TestCase
4
4
  context "Generator" do
data/test/test_helper.rb CHANGED
@@ -3,8 +3,11 @@ require 'test/unit'
3
3
  require 'context' #gem install jeremymcanally-context -s http://gems.github.com
4
4
  require 'stump' #gem install jeremymcanally-stump -s http://gems.github.com
5
5
  require 'pending' #gem install jeremymcanally-pending -s http://gems.github.com
6
- $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
6
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
7
  require 'lightning'
8
+ #set up valid global config file
9
+ Lightning.config_file = File.join(File.dirname(__FILE__), 'lightning.yml')
10
+
8
11
 
9
12
  class Test::Unit::TestCase
10
13
  def assert_arrays_equal(a1, a2)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cldwalker-lightning
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriel Horner
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-16 00:00:00 -08:00
12
+ date: 2009-01-28 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -25,6 +25,8 @@ extra_rdoc_files:
25
25
  - README.markdown
26
26
  - LICENSE.txt
27
27
  files:
28
+ - Rakefile
29
+ - VERSION.yml
28
30
  - lightning_completions.example
29
31
  - lightning.yml.example
30
32
  - README.markdown
@@ -36,16 +38,16 @@ files:
36
38
  - lib/lightning/bolt.rb
37
39
  - lib/lightning/bolts.rb
38
40
  - lib/lightning/completion.rb
41
+ - lib/lightning/completion_map.rb
39
42
  - lib/lightning/config.rb
40
43
  - lib/lightning/core_extensions.rb
41
44
  - lib/lightning/generator.rb
42
- - lib/lightning/path_map.rb
43
45
  - lib/lightning.rb
46
+ - test/bolt_test.rb
47
+ - test/completion_map_test.rb
48
+ - test/completion_test.rb
49
+ - test/config_test.rb
44
50
  - test/lightning.yml
45
- - test/lightning_bolt_test.rb
46
- - test/lightning_completion_test.rb
47
- - test/lightning_config_test.rb
48
- - test/lightning_path_map_test.rb
49
51
  - test/lightning_test.rb
50
52
  - test/test_helper.rb
51
53
  has_rdoc: true
@@ -1,27 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper'
2
-
3
- class LightningBoltTest < Test::Unit::TestCase
4
- context "Bolt" do
5
- before(:each) do
6
- @path_map = {'path1'=>'/dir/path1','path2'=>'/dir/path2'}
7
- @bolt = Lightning::Bolt.new('blah')
8
- @bolt.path_map.map = @path_map
9
- end
10
-
11
- test "fetches correct completions" do
12
- assert_equal @bolt.completions, @path_map.keys
13
- end
14
-
15
- test "resolves completion" do
16
- assert_equal @path_map['path1'], @bolt.resolve_completion('path1')
17
- end
18
-
19
- test "resolves completion with test flag" do
20
- assert_equal @path_map['path1'], @bolt.resolve_completion('-test path1')
21
- end
22
-
23
- test "creates path_map only once" do
24
- assert_equal @bolt.path_map.object_id, @bolt.path_map.object_id
25
- end
26
- end
27
- end
@@ -1,23 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper'
2
-
3
- class LightningCompletionTest < Test::Unit::TestCase
4
- context "Completion" do
5
- before(:each) {
6
- @key = 'blah';
7
- Lightning.bolts[@key].stub!(:completions, :return=>%w{at ap blah})
8
- }
9
- test "from script matches correctly" do
10
- assert_arrays_equal Lightning::Completion.complete('cd-test a', @key), %w{at ap}
11
- end
12
-
13
- test "for basic case matches correctly" do
14
- @completion = Lightning::Completion.new('cd-test a', @key)
15
- assert_arrays_equal @completion.matches, %w{at ap}
16
- end
17
-
18
- test "with test flag matches correctly" do
19
- @completion = Lightning::Completion.new('cd-test -test a', @key)
20
- assert_arrays_equal @completion.matches, %w{at ap}
21
- end
22
- end
23
- end
@@ -1,30 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper'
2
-
3
- class LightningPathMapTest < Test::Unit::TestCase
4
-
5
- context "PathMap" do
6
- def create_map(path_hash)
7
- Dir.stub!(:glob) { path_hash.values }
8
- @path_map = Lightning::PathMap.new('blah')
9
- end
10
-
11
- test "creates basic map" do
12
- expected_map = {"path1"=>"/dir1/path1", "path2"=>"/dir1/path2"}
13
- create_map(expected_map)
14
- assert_equal expected_map, @path_map.map
15
- end
16
-
17
- test "ignores paths from Lightning.ignore_paths" do
18
- Lightning.stub!(:ignore_paths, :return=>['path1'])
19
- expected_map = {"path1"=>"/dir1/path1", "path2"=>"/dir1/path2"}
20
- create_map(expected_map)
21
- assert_equal expected_map.slice('path2'), @path_map.map
22
- end
23
-
24
- test "creates map with duplicates" do
25
- expected_map = {"path1//dir3"=>"/dir3/path1", "path2"=>"/dir1/path2", "path1//dir1"=>"/dir1/path1", "path1//dir2"=>"/dir2/path1"}
26
- create_map(expected_map)
27
- assert_equal expected_map, @path_map.map
28
- end
29
- end
30
- end