lightning 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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
@@ -0,0 +1,62 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ class Lightning::ConfigTest < Test::Unit::TestCase
4
+ context "A config" do
5
+ before(:all) {
6
+ @config = Lightning::Config.create
7
+ }
8
+
9
+ should "be a hash" do
10
+ assert @config.is_a?(Hash)
11
+ end
12
+
13
+ should "have keys that are symbols" do
14
+ assert @config.keys.all? {|e| e.is_a?(Symbol)}
15
+ end
16
+
17
+ should "have read supported keys" do
18
+ supported_keys = [:generated_file, :commands, :ignore_paths, :paths, :shell, :complete_regex]
19
+ assert_arrays_equal supported_keys, @config.keys
20
+ end
21
+
22
+ should "have a generated_file key which is a string" do
23
+ assert @config[:generated_file].is_a?(String)
24
+ end
25
+
26
+ should "have a commands key which is an array" do
27
+ assert @config[:commands].is_a?(Array)
28
+ end
29
+
30
+ should "have a command with valid keys" do
31
+ assert @config[:commands][0].slice('name', 'map_to', 'description').values.all? {|e| e.is_a?(String)}
32
+ assert @config[:commands][0]['paths'].is_a?(Array)
33
+ end
34
+
35
+ should "have a paths key which is a hash" do
36
+ assert @config[:paths].is_a?(Hash)
37
+ end
38
+
39
+ should "have an ignore_paths key which is an array" do
40
+ assert @config[:ignore_paths].is_a?(Array)
41
+ end
42
+ end
43
+
44
+ context ":configure_commands_and_paths" do
45
+ test "generates bolt key if none exists" do
46
+ config = {:commands=>[{'name'=>'c1', 'map_to'=>'s1'}]}
47
+ assert ! Lightning::Config.configure_commands_and_paths(config)[:commands][0]['bolt_key'].nil?
48
+ end
49
+
50
+ test "adds generated bolt key to config.paths if it didn't exist" do
51
+ config = {:commands=>[{'name'=>'c1', 'map_to'=>'s1', 'paths'=>['*']}]}
52
+ new_config = Lightning::Config.configure_commands_and_paths(config)
53
+ bolt_key = new_config[:commands][0]['bolt_key']
54
+ assert new_config[:paths].has_key?(bolt_key)
55
+ end
56
+
57
+ test "adds reference to bolt key if command.paths is a string" do
58
+ config = {:commands=>[{'name'=>'c1', 'map_to'=>'s1', 'paths'=>'blah'}]}
59
+ assert_equal 'blah', Lightning::Config.configure_commands_and_paths(config)[:commands][0]['bolt_key']
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,39 @@
1
+ ---
2
+ generated_file: lightning_completions
3
+
4
+ ignore_paths:
5
+ - .DS_Store
6
+ - .git
7
+
8
+ #only oa command is currently used
9
+ commands:
10
+ - name : oa
11
+ map_to : open -a
12
+ description : open mac applications
13
+ paths:
14
+ - /Applications/*.app
15
+ - /Applications/Utilities/*.app
16
+
17
+ - name : gcd
18
+ map_to : cd
19
+ paths: gem
20
+
21
+ - name : rcd
22
+ map_to : cd
23
+ description : ruby core directories
24
+ paths:
25
+ - /Library/Ruby/Site/1.8/**/
26
+ - /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/**/
27
+
28
+ paths:
29
+ # to obtain your own paths to your ruby gems:
30
+ # `gem environment path`.split(":").map {|e| e +"/gems/*" }
31
+ gem:
32
+ - /Users/bozo/.gem/ruby/1.8/gems/*
33
+ - /Library/Ruby/Gems/1.8/gems/*
34
+ - /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/*
35
+
36
+ gem_rdoc:
37
+ - /Users/bozo/.gem/ruby/1.8/doc/*
38
+ - /Library/Ruby/Gems/1.8/doc/*
39
+ - /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/doc/*
@@ -0,0 +1,58 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ class LightningTest < Test::Unit::TestCase
4
+ context "Generator" do
5
+ before(:all) do
6
+ @config_file = File.dirname(__FILE__) + '/lightning_completions'
7
+ Lightning.config[:generated_file] = @config_file
8
+ Lightning::Generator.generate_completions
9
+ end
10
+ after(:all) { FileUtils.rm_f(Lightning.config[:generated_file]) }
11
+
12
+ test "generates file in expected location" do
13
+ assert File.exists?(@config_file)
14
+ end
15
+
16
+ #this depends on oa
17
+ test "generates expected output for a command" do
18
+ generated_command = <<-EOS.gsub(/^\s{6}/,'')
19
+ #open mac applications
20
+ oa () {
21
+ if [ -z "$1" ]; then
22
+ echo "No arguments given"
23
+ return
24
+ fi
25
+ FULL_PATH="`${LBIN_PATH}lightning-full_path oa $@`"
26
+ if [ $1 == '-test' ]; then
27
+ CMD="open -a '$FULL_PATH'"
28
+ echo $CMD
29
+ else
30
+ open -a "$FULL_PATH"
31
+ fi
32
+ }
33
+ complete -o default -C "${LBIN_PATH}lightning-complete oa" oa
34
+ EOS
35
+ output = File.read(@config_file)
36
+ assert output.include?(generated_command)
37
+ end
38
+ end
39
+
40
+ context "Lightning" do
41
+ test "complete() returns correctly for valid command" do
42
+ Lightning::Completion.stub!(:complete, :return=>'blah')
43
+ assert_equal 'blah', Lightning.complete('oa', 'blah')
44
+ end
45
+
46
+ test "complete() reports error for invalid command" do
47
+ assert ! Lightning.complete('invalid','invalid').grep(/Error/).empty?
48
+ end
49
+
50
+ test "translate() returns errorless for valid command" do
51
+ assert Lightning.translate('oa', 'blah').grep(/Error/).empty?
52
+ end
53
+
54
+ test "translate() reports error for invalid command" do
55
+ assert ! Lightning.translate('invalid', 'blah').grep(/Error/).empty?
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,24 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'context' #gem install jeremymcanally-context -s http://gems.github.com
4
+ require 'stump' #gem install jeremymcanally-stump -s http://gems.github.com
5
+ #require 'pending' #gem install jeremymcanally-pending -s http://gems.github.com
6
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
+ require 'lightning'
8
+ #set up valid global config file
9
+ Lightning::Config.config_file = File.join(File.dirname(__FILE__), 'lightning.yml')
10
+
11
+
12
+ class Test::Unit::TestCase
13
+ def assert_arrays_equal(a1, a2)
14
+ assert_equal a1.map {|e| e.to_s}.sort, a2.map{|e| e.to_s}.sort
15
+ end
16
+
17
+ end
18
+
19
+ #from ActiveSupport
20
+ class Hash
21
+ def slice(*keys)
22
+ reject { |key,| !keys.include?(key) }
23
+ end
24
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lightning
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Gabriel Horner
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-23 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Lightning creates shell commands that each autocomplete to a configured group of files and directories. Autocompleting is quick since you only need to type the basename and can even use regex completion.
17
+ email: gabriel.horner@gmail.com
18
+ executables:
19
+ - lightning-complete
20
+ - lightning-full_path
21
+ - lightning-install
22
+ extensions: []
23
+
24
+ extra_rdoc_files:
25
+ - LICENSE.txt
26
+ - README.rdoc
27
+ files:
28
+ - CHANGELOG.rdoc
29
+ - LICENSE.txt
30
+ - README.rdoc
31
+ - Rakefile
32
+ - VERSION.yml
33
+ - bin/lightning-complete
34
+ - bin/lightning-full_path
35
+ - bin/lightning-install
36
+ - lib/lightning.rb
37
+ - lib/lightning/bolt.rb
38
+ - lib/lightning/bolts.rb
39
+ - lib/lightning/commands.rb
40
+ - lib/lightning/completion.rb
41
+ - lib/lightning/completion_map.rb
42
+ - lib/lightning/config.rb
43
+ - lib/lightning/generator.rb
44
+ - lightning.yml.example
45
+ - lightning_completions.example
46
+ - test/bolt_test.rb
47
+ - test/completion_map_test.rb
48
+ - test/completion_test.rb
49
+ - test/config_test.rb
50
+ - test/lightning.yml
51
+ - test/lightning_test.rb
52
+ - test/test_helper.rb
53
+ has_rdoc: true
54
+ homepage: http://github.com/cldwalker/lightning
55
+ licenses: []
56
+
57
+ post_install_message:
58
+ rdoc_options:
59
+ - --charset=UTF-8
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ version:
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: "0"
73
+ version:
74
+ requirements: []
75
+
76
+ rubyforge_project: tagaholic
77
+ rubygems_version: 1.3.5
78
+ signing_key:
79
+ specification_version: 3
80
+ summary: Path completions for your shell that will let you navigate like lightning.
81
+ test_files:
82
+ - test/bolt_test.rb
83
+ - test/completion_map_test.rb
84
+ - test/completion_test.rb
85
+ - test/config_test.rb
86
+ - test/lightning_test.rb
87
+ - test/test_helper.rb