bond 0.4.2-java

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.
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,66 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ describe "operator method mission" do
4
+ before_all { MethodMission.reset }
5
+ before { Bond.agent.reset; Bond.complete(:all_operator_methods=>true) }
6
+
7
+ describe "operator" do
8
+ before { complete(:method=>"Hash#[]") { %w{ab cd ae} } }
9
+
10
+ it "completes" do
11
+ tab('{}[a').should == ["}[ab", "}[ae"]
12
+ end
13
+
14
+ it "completes quoted argument" do
15
+ tab('{:a=>1}["a').should == %w{ab ae}
16
+ end
17
+
18
+ it "completes symbolic argument" do
19
+ tab('{}[:a').should == ["}[:ab", "}[:ae"]
20
+ end
21
+
22
+ it "completes with no space between method and argument" do
23
+ tab('{}[a').should == ["}[ab", "}[ae"]
24
+ end
25
+
26
+ it "completes with space between method and argument" do
27
+ tab('{}[ a').should == ["ab", "ae"]
28
+ end
29
+
30
+ it "completes with operator characters in object" do
31
+ tab('{:a=> 1}[').should == ["1}[ab", "1}[cd", "1}[ae"]
32
+ end
33
+
34
+ it "completes all arguments with only space as argument" do
35
+ tab('{}[ ').should == ["ab", "cd", "ae"]
36
+ end
37
+
38
+ it "completes with a chain of objects" do
39
+ tab('Hash.new[a').should == %w{Hash.new[ab Hash.new[ae}
40
+ end
41
+
42
+ it "completes in middle of line" do
43
+ tab('nil; {}[a').should == ["}[ab", "}[ae"]
44
+ end
45
+
46
+ it "doesn't complete for multiple arguments" do
47
+ tab('{}[a,').should == []
48
+ end
49
+ end
50
+
51
+ it "operator with space between object and method completes" do
52
+ complete(:method=>"Array#*") { %w{ab cd ae} }
53
+ tab('[1,2] * a').should == %w{ab ae}
54
+ tab('[1,2] *a').should == %w{*ab *ae}
55
+ end
56
+
57
+ it "class operator completes" do
58
+ complete(:method=>"Hash.*") { %w{ab cd ae} }
59
+ tab('Hash * a').should == %w{ab ae}
60
+ end
61
+
62
+ it "with :search completes" do
63
+ complete(:method=>"Array#*", :search=>:anywhere) { %w{abc bcd cde} }
64
+ tab('[1, 2] * b').should == ['abc', 'bcd']
65
+ end
66
+ end
@@ -0,0 +1,140 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ describe "Search" do
4
+ before { Bond.agent.reset }
5
+
6
+ describe "mission with search" do
7
+ it "false completes" do
8
+ complete(:on=>/cool '(.*)/, :search=>false) {|e| %w{coco for puffs}.grep(/#{e.matched[1]}/) }
9
+ tab("cool 'ff").should == ['puffs']
10
+ end
11
+
12
+ it "defined in Rc completes" do
13
+ Rc.module_eval %q{def coco_search(input, list); list.grep(/#{input}/); end }
14
+ complete(:on=>/blah/, :search=>:coco) {|e| %w{coco for puffs} }
15
+ tab("blah ff").should == ['puffs']
16
+ end
17
+
18
+ it ":anywhere completes" do
19
+ complete(:on=>/blah/, :search=>:anywhere) {|e| %w{coco for puffs} }
20
+ tab("blah ff").should == ['puffs']
21
+ end
22
+
23
+ it ":ignore_case completes" do
24
+ complete(:on=>/blah/, :search=>:ignore_case) {|e| %w{Coco For PufFs} }
25
+ tab("blah pu").should == ['PufFs']
26
+ end
27
+
28
+ it ":underscore completes" do
29
+ complete(:on=>/blah/, :search=>:underscore) {|e| %w{and_one big_two can_three} }
30
+ tab("blah and").should == ['and_one']
31
+ tab("blah b_t").should == ['big_two']
32
+ end
33
+ end
34
+
35
+ it "underscore search doesn't pick up strings starting with __" do
36
+ completions = ["include?", "instance_variable_defined?", "__id__", "include_and_exclude?"]
37
+ complete(:on=>/blah/, :search=>:underscore) { completions }
38
+ tab("blah i").should == ["include?", "instance_variable_defined?", "include_and_exclude?"]
39
+ end
40
+
41
+ it "underscore search autocompletes strings starting with __" do
42
+ completions = ["include?", "__id__", "__send__"]
43
+ complete(:on=>/blah/, :search=>:underscore) { completions }
44
+ tab('blah _').should == ["__id__", "__send__"]
45
+ tab('blah __').should == ["__id__", "__send__"]
46
+ tab('blah __i').should == ["__id__"]
47
+ end
48
+
49
+ it "underscore search can match first unique strings of each underscored word" do
50
+ completions = %w{so_long so_larger so_louder}
51
+ complete(:on=>/blah/, :search=>:underscore) { completions }
52
+ tab("blah s_lo").should == %w{so_long so_louder}
53
+ tab("blah s_lou").should == %w{so_louder}
54
+ end
55
+
56
+ it "underscore search acts normal if ending in underscore" do
57
+ complete(:on=>/blah/, :search=>:underscore) {|e| %w{and_one big_two can_three ander_one} }
58
+ tab("blah and_").should == %w{and_one}
59
+ end
60
+
61
+ it "search handles completions with regex characters" do
62
+ completions = ['[doh]', '.*a', '?ok']
63
+ complete(:on=>/blah/) { completions }
64
+ tab('blah .').should == ['.*a']
65
+ tab('blah [').should == ['[doh]']
66
+ tab('blah ?').should == ['?ok']
67
+ end
68
+
69
+ it "default search uses default search" do
70
+ Search.default_search.should == :underscore
71
+ Rc.expects(:underscore_search).with('a', %w{ab cd})
72
+ Rc.send(:default_search, 'a', %w{ab cd})
73
+ end
74
+
75
+ describe "modules search" do
76
+ before {
77
+ complete(:on=>/blah/, :search=>:modules) { %w{A1 M1::Z M1::Y::X M2::X} }
78
+ }
79
+ it "completes all modules" do
80
+ tab('blah ').should == ["A1", "M1::", "M2::"]
81
+ end
82
+
83
+ it "completes single first level module" do
84
+ tab('blah A').should == %w{A1}
85
+ end
86
+
87
+ it "completes single first level module parent" do
88
+ tab('blah M2').should == %w{M2::}
89
+ end
90
+
91
+ it "completes all second level modules" do
92
+ tab('blah M1::').should == %w{M1::Z M1::Y::}
93
+ end
94
+
95
+ it "completes second level module parent" do
96
+ tab('blah M1::Y').should == %w{M1::Y::}
97
+ end
98
+
99
+ it "completes third level module" do
100
+ tab('blah M1::Y::').should == %w{M1::Y::X}
101
+ end
102
+ end
103
+
104
+ describe "files search" do
105
+ before {
106
+ complete(:on=>/rm/, :search=>:files) { %w{a1 d1/f2 d1/d2/f1 d2/f1 d2/f1/ /f1} }
107
+ }
108
+ it "completes all paths" do
109
+ tab('rm ').should == %w{a1 d1/ d2/ /}
110
+ end
111
+
112
+ it "completes single first level file" do
113
+ tab('rm a').should == %w{a1}
114
+ end
115
+
116
+ it "completes single first level directory" do
117
+ tab('rm d2').should == %w{d2/}
118
+ end
119
+
120
+ it "completes all second level paths" do
121
+ tab('rm d1/').should == %w{d1/f2 d1/d2/}
122
+ end
123
+
124
+ it "completes single second level directory" do
125
+ tab('rm d1/d2').should == %w{d1/d2/}
126
+ end
127
+
128
+ it "completes single third level file" do
129
+ tab('rm d1/d2/').should == %w{d1/d2/f1}
130
+ end
131
+
132
+ it "completes file and directory with same name" do
133
+ tab('rm d2/f').should == %w{d2/f1 d2/f1/}
134
+ end
135
+
136
+ it "completes file with full path" do
137
+ tab('rm /f').should == %w{/f1}
138
+ end
139
+ end
140
+ end
@@ -0,0 +1,69 @@
1
+ require 'bacon'
2
+ require 'bacon/bits'
3
+ require 'mocha'
4
+ require 'mocha-on-bacon'
5
+ require 'bond'
6
+ require 'rbconfig'
7
+
8
+ module TestHelpers
9
+ extend self
10
+ def mock_irb
11
+ unless Object.const_defined?(:IRB)
12
+ eval %[
13
+ module ::IRB
14
+ class<<self; attr_accessor :CurrentContext; end
15
+ module InputCompletor; CompletionProc = lambda {|e| [] }; end
16
+ end
17
+ ]
18
+ ::IRB.CurrentContext = stub(:workspace => stub(:binding => binding))
19
+ end
20
+ end
21
+
22
+ def capture_stderr(&block)
23
+ original_stderr = $stderr
24
+ $stderr = fake = StringIO.new
25
+ begin
26
+ yield
27
+ ensure
28
+ $stderr = original_stderr
29
+ end
30
+ fake.string
31
+ end
32
+
33
+ def capture_stdout(&block)
34
+ original_stdout = $stdout
35
+ $stdout = fake = StringIO.new
36
+ begin
37
+ yield
38
+ ensure
39
+ $stdout = original_stdout
40
+ end
41
+ fake.string
42
+ end
43
+
44
+ def tab(full_line, last_word=full_line)
45
+ Bond.agent.weapon.stubs(:line_buffer).returns(full_line)
46
+ Bond.agent.call(last_word)
47
+ end
48
+
49
+ def complete(*args, &block)
50
+ Bond.complete(*args, &block)
51
+ end
52
+
53
+ def valid_readline
54
+ Class.new { def self.setup(arg); end; def self.line_buffer; end }
55
+ end
56
+
57
+ def reset
58
+ M.reset
59
+ M.debrief :readline => TestHelpers.valid_readline
60
+ end
61
+ end
62
+
63
+ class Bacon::Context
64
+ include TestHelpers
65
+ end
66
+
67
+ # Default settings
68
+ Bond::M.debrief(:readline => TestHelpers.valid_readline, :debug => true)
69
+ include Bond
metadata ADDED
@@ -0,0 +1,167 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bond
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.2
5
+ prerelease:
6
+ platform: java
7
+ authors:
8
+ - Gabriel Horner
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bacon
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.1.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.1.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: mocha
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 0.9.8
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 0.9.8
46
+ - !ruby/object:Gem::Dependency
47
+ name: mocha-on-bacon
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: bacon-bits
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: Bond is on a mission to improve autocompletion in ruby, especially for
79
+ irb/ripl. Aside from doing everything irb's can do and fixing its quirks, Bond can
80
+ autocomplete argument(s) to methods, uniquely completing per module, per method
81
+ and per argument. Bond brings ruby autocompletion closer to bash/zsh as it provides
82
+ a configuration system and a DSL for creating custom completions and completion
83
+ rules. With this configuration system, users can customize their autocompletions
84
+ and share it with others. Bond can also load completions that ship with gems. Bond
85
+ is able to offer more than irb's completion since it uses the full line of input
86
+ when completing as opposed to irb's last-word approach.
87
+ email: gabriel.horner@gmail.com
88
+ executables: []
89
+ extensions: []
90
+ extra_rdoc_files:
91
+ - README.rdoc
92
+ - LICENSE.txt
93
+ files:
94
+ - lib/bond/agent.rb
95
+ - lib/bond/completion.rb
96
+ - lib/bond/completions/activerecord.rb
97
+ - lib/bond/completions/array.rb
98
+ - lib/bond/completions/bond.rb
99
+ - lib/bond/completions/hash.rb
100
+ - lib/bond/completions/kernel.rb
101
+ - lib/bond/completions/module.rb
102
+ - lib/bond/completions/object.rb
103
+ - lib/bond/completions/struct.rb
104
+ - lib/bond/input.rb
105
+ - lib/bond/m.rb
106
+ - lib/bond/mission.rb
107
+ - lib/bond/missions/anywhere_mission.rb
108
+ - lib/bond/missions/default_mission.rb
109
+ - lib/bond/missions/method_mission.rb
110
+ - lib/bond/missions/object_mission.rb
111
+ - lib/bond/missions/operator_method_mission.rb
112
+ - lib/bond/rc.rb
113
+ - lib/bond/readline.rb
114
+ - lib/bond/readlines/jruby.rb
115
+ - lib/bond/readlines/rawline.rb
116
+ - lib/bond/readlines/ruby.rb
117
+ - lib/bond/search.rb
118
+ - lib/bond/version.rb
119
+ - lib/bond.rb
120
+ - test/agent_test.rb
121
+ - test/anywhere_mission_test.rb
122
+ - test/bond_test.rb
123
+ - test/completion_test.rb
124
+ - test/completions_test.rb
125
+ - test/m_test.rb
126
+ - test/method_mission_test.rb
127
+ - test/mission_test.rb
128
+ - test/object_mission_test.rb
129
+ - test/operator_method_mission_test.rb
130
+ - test/search_test.rb
131
+ - test/test_helper.rb
132
+ - LICENSE.txt
133
+ - CHANGELOG.rdoc
134
+ - README.rdoc
135
+ - test/deps.rip
136
+ - Rakefile
137
+ - .gemspec
138
+ - .travis.yml
139
+ homepage: http://tagaholic.me/bond/
140
+ licenses:
141
+ - MIT
142
+ post_install_message:
143
+ rdoc_options:
144
+ - --title
145
+ - Bond 0.4.2 Documentation
146
+ require_paths:
147
+ - lib
148
+ required_ruby_version: !ruby/object:Gem::Requirement
149
+ none: false
150
+ requirements:
151
+ - - ! '>='
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ required_rubygems_version: !ruby/object:Gem::Requirement
155
+ none: false
156
+ requirements:
157
+ - - ! '>='
158
+ - !ruby/object:Gem::Version
159
+ version: 1.3.6
160
+ requirements: []
161
+ rubyforge_project:
162
+ rubygems_version: 1.8.24
163
+ signing_key:
164
+ specification_version: 3
165
+ summary: ! 'Mission: Easy custom autocompletion for arguments, methods and beyond.
166
+ Accomplished for irb and any other readline-like console environments.'
167
+ test_files: []