bond 0.4.2-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/.gemspec +28 -0
  2. data/.travis.yml +8 -0
  3. data/CHANGELOG.rdoc +91 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.rdoc +242 -0
  6. data/Rakefile +47 -0
  7. data/lib/bond.rb +127 -0
  8. data/lib/bond/agent.rb +108 -0
  9. data/lib/bond/completion.rb +16 -0
  10. data/lib/bond/completions/activerecord.rb +12 -0
  11. data/lib/bond/completions/array.rb +1 -0
  12. data/lib/bond/completions/bond.rb +6 -0
  13. data/lib/bond/completions/hash.rb +3 -0
  14. data/lib/bond/completions/kernel.rb +15 -0
  15. data/lib/bond/completions/module.rb +10 -0
  16. data/lib/bond/completions/object.rb +21 -0
  17. data/lib/bond/completions/struct.rb +1 -0
  18. data/lib/bond/input.rb +28 -0
  19. data/lib/bond/m.rb +146 -0
  20. data/lib/bond/mission.rb +151 -0
  21. data/lib/bond/missions/anywhere_mission.rb +15 -0
  22. data/lib/bond/missions/default_mission.rb +21 -0
  23. data/lib/bond/missions/method_mission.rb +197 -0
  24. data/lib/bond/missions/object_mission.rb +44 -0
  25. data/lib/bond/missions/operator_method_mission.rb +27 -0
  26. data/lib/bond/rc.rb +48 -0
  27. data/lib/bond/readline.rb +38 -0
  28. data/lib/bond/readlines/jruby.rb +13 -0
  29. data/lib/bond/readlines/rawline.rb +15 -0
  30. data/lib/bond/readlines/ruby.rb +9 -0
  31. data/lib/bond/search.rb +74 -0
  32. data/lib/bond/version.rb +3 -0
  33. data/test/agent_test.rb +235 -0
  34. data/test/anywhere_mission_test.rb +34 -0
  35. data/test/bond_test.rb +141 -0
  36. data/test/completion_test.rb +148 -0
  37. data/test/completions_test.rb +98 -0
  38. data/test/deps.rip +4 -0
  39. data/test/m_test.rb +34 -0
  40. data/test/method_mission_test.rb +246 -0
  41. data/test/mission_test.rb +51 -0
  42. data/test/object_mission_test.rb +59 -0
  43. data/test/operator_method_mission_test.rb +66 -0
  44. data/test/search_test.rb +140 -0
  45. data/test/test_helper.rb +69 -0
  46. metadata +167 -0
@@ -0,0 +1,98 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ describe "completions for" do
4
+ before_all {
5
+ reset
6
+ complete(:all_methods=>true)
7
+ complete(:all_operator_methods=>true)
8
+ M.load_file File.dirname(__FILE__) + '/../lib/bond/completion.rb'
9
+ M.load_dir File.dirname(__FILE__) + '/../lib/bond'
10
+ }
11
+
12
+ it "Array#delete" do
13
+ tab("[12,23,34,15].delete 1").should == %w{12 15}
14
+ end
15
+
16
+ describe "Hash" do
17
+ before { @hash = %q{{:ab=>1,:bc=>1,:cd=>3,:ae=>2}} }
18
+
19
+ it "#delete" do
20
+ tab("#{@hash}.delete :a").sort.should == %w{:ab :ae}
21
+ end
22
+
23
+ it "#index" do
24
+ tab("#{@hash}.index 2").should == %w{2}
25
+ end
26
+
27
+ it "#[]" do
28
+ tab("#{@hash}['a").sort.should == %w{ab ae}
29
+ end
30
+ end
31
+
32
+ describe "Kernel" do
33
+ it "#raise" do
34
+ tab("raise Errno::ETIME").sort.should == %w{Errno::ETIME Errno::ETIMEDOUT}
35
+ end
36
+
37
+ it "#require" do
38
+ mock_libs = ['net/http.rb', 'net/http/get.rb', 'abbrev.rb'].map {|e| $:[0] + "/#{e}" }
39
+ Dir.stubs(:[]).returns(mock_libs)
40
+ tab("require 'net/htt").should == %w{net/http.rb net/http/}
41
+ end
42
+ end
43
+
44
+ describe "Object" do
45
+ it "#instance_of?" do
46
+ expectations = ['Hash']
47
+ expectations = ["Hash", "Hash::"] if RbConfig::CONFIG["RUBY_SO_NAME"].to_s[/rubinius/i]
48
+ tab("[].instance_of? Has").should == expectations
49
+ end
50
+
51
+ it "#is_a?" do
52
+ tab("Module.is_a? Mod").should == ['Module']
53
+ end
54
+
55
+ it "#send" do
56
+ tab("Object.send :ne").should == [':new']
57
+ end
58
+
59
+ it "#send and additional arguments" do
60
+ tab('Bond.send :const_get, Ag').should == ['Agent']
61
+ end
62
+
63
+ it "#send and invalid first argument" do
64
+ tab('Bond.send :blah, ').should == []
65
+ end
66
+
67
+ it "#instance_variable_get" do
68
+ tab("Bond::M.instance_variable_get '@a").should == ['@agent']
69
+ end
70
+
71
+ it "#method" do
72
+ tab("Bond::M.method :ho").should == [':home']
73
+ end
74
+
75
+ it "#[]" do
76
+ ::ENV['ZZZ'] = ::ENV['ZZY'] = 'blah'
77
+ tab("ENV['ZZ").should == %w{ZZY ZZZ}
78
+ end
79
+ end
80
+
81
+ describe "Module" do
82
+ it "#const_get" do
83
+ tab("Bond.const_get M").sort.should == ['M', 'MethodMission', 'Mission']
84
+ end
85
+
86
+ it "#instance_methods" do
87
+ tab("Bond::Agent.instance_method :ca").should == [':call']
88
+ end
89
+
90
+ it "#>" do
91
+ tab("Object > Mod").should == %w{Module}
92
+ end
93
+
94
+ it "#> and :files search" do
95
+ tab("Object > Bon").should == %w{Bond Bond::}
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,4 @@
1
+ bacon >=1.1.0
2
+ mocha >=0.9.8
3
+ mocha-on-bacon >=0
4
+ bacon-bits >=0
@@ -0,0 +1,34 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ describe "M" do
4
+ describe "#load_gems" do
5
+ before { $: << '/dir' }
6
+ after { $:.pop }
7
+
8
+ def mock_file_exists(file)
9
+ File.expects(:exists?).at_least(1).returns(false).with {|e| e != file }
10
+ File.expects(:exists?).times(1).returns(true).with {|e| e == file }
11
+ end
12
+
13
+ it "loads gem" do
14
+ M.expects(:gem)
15
+ mock_file_exists '/dir/boom/../bond'
16
+ M.expects(:load_dir).with('/dir/boom/../bond').returns(true)
17
+ Bond.load_gems('boom').should == ['boom']
18
+ end
19
+
20
+ it "loads plugin gem in gem format" do
21
+ M.expects(:find_gem_file).returns(false)
22
+ mock_file_exists '/dir/boom/completions/what.rb'
23
+ M.expects(:load_file).with('/dir/boom/completions/what.rb')
24
+ Bond.load_gems('boom-what').should == ['boom-what']
25
+ end
26
+
27
+ it "loads plugin gem in file format" do
28
+ M.expects(:find_gem_file).returns(false)
29
+ mock_file_exists '/dir/boom/completions/what.rb'
30
+ M.expects(:load_file).with('/dir/boom/completions/what.rb')
31
+ Bond.load_gems('boom/what.rb').should == ['boom/what.rb']
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,246 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ describe "method mission" do
4
+ before_all { MethodMission.reset }
5
+ before { Bond.agent.reset; Bond.complete(:all_methods=>true) }
6
+
7
+ describe "method" do
8
+ before { complete(:method=>'Array#index') {|e| %w{ab cd ef ad} } }
9
+
10
+ it "completes" do
11
+ tab('[].index c').should == %w{cd}
12
+ end
13
+
14
+ it "completes quoted argument" do
15
+ tab('[].index "a').should == %w{ab ad}
16
+ end
17
+
18
+ it "completes parenthetical argument" do
19
+ tab('[].index("a').should == %w{ab ad}
20
+ end
21
+
22
+ it "completes symbolic argument" do
23
+ tab('[].index :a').should == %w{:ab :ad}
24
+ end
25
+
26
+ it "needs space to complete argument" do
27
+ tab('[].indexa').should == []
28
+ tab('[].index a').should == %w{ab ad}
29
+ end
30
+
31
+ it "completes all arguments with only space as argument" do
32
+ tab('[].index ').should == %w{ab cd ef ad}
33
+ end
34
+
35
+ it "completes with a chain of objects" do
36
+ tab('{}.to_a.index a').should == %w{ab ad}
37
+ end
38
+
39
+ it "completes after valid ruby" do
40
+ tab('nil; [].index a').should == %w{ab ad}
41
+ end
42
+
43
+ it "completes after invalid ruby" do
44
+ tab('blah [].index a').should == %w{ab ad}
45
+ end
46
+
47
+ describe "completes for whitespaced object that is" do
48
+ def complete_and_tab(klass, example)
49
+ complete(:method=>"#{klass}#to_s") { %w{ab cd ef ad} }
50
+ tab(example + '.to_s a').should == %w{ab ad}
51
+ end
52
+
53
+ it "a string" do
54
+ complete_and_tab(String, "'man oh'")
55
+ end
56
+
57
+ it "an array" do
58
+ complete_and_tab(Array, "[1, 2, 3]")
59
+ end
60
+
61
+ it "a hash" do
62
+ complete_and_tab(Hash, "{:a => 1}")
63
+ end
64
+
65
+ it "a regexp" do
66
+ complete_and_tab(Regexp, "/man oh/")
67
+ end
68
+
69
+ it "a proc" do
70
+ complete_and_tab(Proc, "lambda { }")
71
+ complete_and_tab(Proc, "proc { }")
72
+ end
73
+
74
+ it "a range" do
75
+ complete_and_tab(Range, "(1.. 10)")
76
+ end
77
+
78
+ it "wrapped ()" do
79
+ complete_and_tab(Fixnum, "(2 * 2)")
80
+ end
81
+
82
+ it "quoted by {}" do
83
+ complete_and_tab(String, "%q{man oh}")
84
+ end
85
+
86
+ it "quoted by []" do
87
+ complete_and_tab(String, "%q[man oh]")
88
+ end
89
+ end
90
+ end
91
+
92
+ describe "any instance method" do
93
+ before { complete(:method=>'Array#index', :search=>:anywhere) {|e| %w{ab cd ef ad} } }
94
+
95
+ it "completes for objects of a subclass" do
96
+ class ::MyArray < Array; end
97
+ tab('MyArray.new.index a').should == %w{ab ad}
98
+ end
99
+
100
+ it "completes for objects of a subclass using its own definition" do
101
+ class ::MyArray < Array; end
102
+ complete(:method=>'MyArray#index') {|e| %w{aa ab bc} }
103
+ tab('MyArray.new.index a').should == %w{aa ab}
104
+ end
105
+
106
+ it "ignores invalid ruby" do
107
+ tab("[{].index a").should == []
108
+ end
109
+
110
+ it "with string :action copies its action" do
111
+ complete(:method=>"Array#fetch", :action=>"Array#index")
112
+ tab('[].fetch a').should == %w{ab ad}
113
+ end
114
+
115
+ it "with string :action copies its search" do
116
+ complete(:method=>"Array#fetch", :action=>"Array#index")
117
+ tab('[].fetch d').should == %w{cd ad}
118
+ end
119
+
120
+ it "with string :action and :search doesn't copy its search" do
121
+ complete(:method=>"Array#fetch", :action=>"Array#index", :search=>:normal)
122
+ tab('[].fetch d').should == []
123
+ end
124
+
125
+ it "with symbol :action references Rc method" do
126
+ Rc.module_eval %[def _fetch(input); %w{ab cd ef ad}; end ]
127
+ complete(:method=>"Array#fetch", :action=>:_fetch)
128
+ tab('[].fetch a').should == %w{ab ad}
129
+ end
130
+ end
131
+
132
+ describe "any class method" do
133
+ before { complete(:method=>'Date.parse') {|e| %w{12/01 03/01 01/01} } }
134
+
135
+ it "completes" do
136
+ tab('Date.parse 0').should == ["03/01", "01/01"]
137
+ end
138
+
139
+ it "completes for a subclass using inherited definition" do
140
+ class ::MyDate < Date; end
141
+ tab('MyDate.parse 0').should == ["03/01", "01/01"]
142
+ end
143
+
144
+ it "completes for a subclass using its own definition" do
145
+ class ::MyDate < Date; end
146
+ complete(:method=>'MyDate.parse') {|e| %w{12 03 01} }
147
+ tab('MyDate.parse 0').should == %w{03 01}
148
+ end
149
+
150
+ it "with string :action copies existing action" do
151
+ complete(:method=>"Date.blah", :action=>"Date.parse")
152
+ tab('Date.blah 0').should == ["03/01", "01/01"]
153
+ end
154
+
155
+ it "doesn't conflict with instance method completion" do
156
+ complete(:method=>'Date#parse') {|e| %w{01 02 23}}
157
+ tab('Date.today.parse 0').should == %w{01 02}
158
+ end
159
+ end
160
+
161
+ describe "multi argument method" do
162
+ before { complete(:method=>'Array#index') {|e| %w{ab cd ef ad e,e} } }
163
+
164
+ it "completes second argument" do
165
+ tab('[].index ab, a').should == %w{ab ad}
166
+ end
167
+
168
+ it "completes second argument as a symbol" do
169
+ tab('[].index ab, :a').should == %w{:ab :ad}
170
+ end
171
+
172
+ it "completes second argument as a string" do
173
+ tab('[].index \'ab\' , "a').should == %w{ab ad}
174
+ end
175
+
176
+ it "completes third argument" do
177
+ tab('[].index ab, zz, c').should == %w{cd}
178
+ end
179
+
180
+ it "completes all arguments after comma" do
181
+ tab('[].index ab,').should == %w{ab cd ef ad e,e}
182
+ tab('[].index ab, ').should == %w{ab cd ef ad e,e}
183
+ end
184
+
185
+ it "completes based on argument number" do
186
+ complete(:method=>'blah') {|e| e.argument == 2 ? %w{ab ad} : %w{ab ae} }
187
+ tab('blah a').should == %w{ab ae}
188
+ tab('blah zz, a').should == %w{ab ad}
189
+ end
190
+
191
+ it "can't handle a completion with a comma as a completion" do
192
+ tab('[].index e,').should == %w{ab cd ef ad e,e}
193
+ end
194
+ end
195
+
196
+ describe "top-level method" do
197
+ before { complete(:method=>'cool') {|e| %w{ab cd ef ad} } }
198
+
199
+ it "completes" do
200
+ complete(:method=>'cool?') {|e| [] }
201
+ tab('cool c').should == %w{cd}
202
+ end
203
+
204
+ it "completes after valid ruby" do
205
+ tab('nil; cool a').should == %w{ab ad}
206
+ end
207
+ end
208
+
209
+ it "with :methods completes for multiple instance methods" do
210
+ complete(:methods=>%w{cool ls}) {|e| %w{ab cd ef ad}}
211
+ tab("cool a").should == %w{ab ad}
212
+ tab("ls c").should == %w{cd}
213
+ end
214
+
215
+ it "with :methods completes for instance and class methods" do
216
+ complete(:methods=>%w{String#include? String.new}) {|e| %w{ab cd ef ad}}
217
+ tab("'blah'.include? a").should == %w{ab ad}
218
+ tab("String.new a").should == %w{ab ad}
219
+ end
220
+
221
+ it "with :search completes" do
222
+ complete(:method=>"blah", :search=>:anywhere) { %w{abc bcd cde} }
223
+ tab('blah bc').should == ['abc', 'bcd']
224
+ end
225
+
226
+ describe "with :class" do
227
+ it "completes for instance methods" do
228
+ complete(:method=>"blong", :class=>"Array#") { %w{ab cd ef ad} }
229
+ tab('[].blong a').should == %w{ab ad}
230
+ complete(:methods=>["bling"], :class=>"Array#") { %w{ab cd ef ad} }
231
+ tab('[].bling a').should == %w{ab ad}
232
+ end
233
+
234
+ it "that is ambiguous defaults to instance methods" do
235
+ complete(:method=>"blong", :class=>"Array") { %w{ab cd ef ad} }
236
+ tab('[].blong a').should == %w{ab ad}
237
+ end
238
+
239
+ it "completes for class methods" do
240
+ complete(:method=>"blong", :class=>"Array.") { %w{ab cd ef ad} }
241
+ tab('Array.blong a').should == %w{ab ad}
242
+ complete(:methods=>["bling"], :class=>"Array.") { %w{ab cd ef ad} }
243
+ tab('Array.bling a').should == %w{ab ad}
244
+ end
245
+ end
246
+ end
@@ -0,0 +1,51 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ describe "Mission" do
4
+ describe "mission" do
5
+ before { Bond.agent.reset }
6
+ it "completes" do
7
+ complete(:on=>/bling/) {|e| %w{ab cd fg hi}}
8
+ complete(:method=>'cool') {|e| [] }
9
+ tab('some bling f').should == %w{fg}
10
+ end
11
+
12
+ it "with regexp condition completes" do
13
+ complete(:on=>/\s*'([^']+)$/, :search=>false) {|e| %w{coco for puffs}.grep(/#{e.matched[1]}/) }
14
+ tab("require 'ff").should == ['puffs']
15
+ end
16
+
17
+ it "with non-string completions completes" do
18
+ complete(:on=>/.*/) { [:one,:two,:three] }
19
+ tab('ok ').should == %w{one two three}
20
+ end
21
+
22
+ it "with non-array completions completes" do
23
+ complete(:on=>/blah/) { 'blah' }
24
+ tab('blah ').should == ['blah']
25
+ end
26
+
27
+ it "with symbol action completes" do
28
+ Rc.module_eval %[def blah(input); %w{one two three}; end]
29
+ complete(:on=>/blah/, :action=>:blah)
30
+ tab('blah ').should == %w{one two three}
31
+ end
32
+
33
+ it "with string action completes" do
34
+ Rc.module_eval %[def blah(input); %w{one two three}; end]
35
+ complete(:on=>/blah/, :action=>'blah')
36
+ tab('blah ').should == %w{one two three}
37
+ end
38
+
39
+ it "always passes Input to action block" do
40
+ complete(:on=>/man/) {|e| e.should.be.is_a(Input); [] }
41
+ tab('man ')
42
+ end
43
+ end
44
+
45
+ it "sets binding to toplevel binding when not in irb" do
46
+ Mission.eval_binding = nil
47
+ mock_irb
48
+ ::IRB.CurrentContext.expects(:workspace).raises
49
+ Mission.eval_binding.should == ::TOPLEVEL_BINDING
50
+ end
51
+ end
@@ -0,0 +1,59 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ describe "ObjectMission" do
4
+ before { Bond.agent.reset }
5
+ describe "object mission" do
6
+ it "with default action completes" do
7
+ complete(:object=>"String")
8
+ complete(:on=>/man/) { %w{upper upster upful}}
9
+ tab("'man'.up").sort.should == [".upcase", ".upcase!", ".upto"]
10
+ end
11
+
12
+ it "with regex condition completes" do
13
+ complete(:object=>'Str.*') {|e| e.object.class.superclass.instance_methods(true) }
14
+ complete(:on=>/man/) { %w{upper upster upful}}
15
+ tab("'man'.unta").should == [".untaint"]
16
+ end
17
+
18
+ it "with explicit action completes" do
19
+ complete(:object=>"String") {|e| e.object.class.superclass.instance_methods(true) }
20
+ complete(:on=>/man/) { %w{upper upster upful}}
21
+ tab("'man'.unta").should == [".untaint"]
22
+ end
23
+
24
+ it "completes without including word break characters" do
25
+ complete(:object=>"Hash")
26
+ matches = tab("{}.f")
27
+ matches.size.should.be > 0
28
+ matches.all? {|e| !e.include?('{')}.should == true
29
+ end
30
+
31
+ it "completes with additional text after completion point" do
32
+ complete(:object=>"Object")
33
+ tab(':man.f blah', ':man.f').include?(':man.freeze').should == true
34
+ end
35
+
36
+ it "doesn't evaluate anything before the completion object" do
37
+ complete(:object=>'Object')
38
+ tab('raise :man.i').size.should > 0
39
+ end
40
+
41
+ it "ignores invalid ruby" do
42
+ complete(:object=>"String")
43
+ tab("blah.upt").should == []
44
+ end
45
+
46
+ it "ignores object that doesn't have a valid class" do
47
+ complete :on=>/(.*)./, :object=>'Object'
48
+ capture_stdout {
49
+ tab("obj = Object.new; def obj.class; end; obj.").should == []
50
+ }.should == ''
51
+ end
52
+
53
+ # needed to ensure Bond works in irbrc
54
+ it "doesn't evaluate irb binding on definition" do
55
+ Object.expects(:const_defined?).never
56
+ complete(:object=>"String")
57
+ end
58
+ end
59
+ end