Skip to content

Commit

Permalink
renamed Bond.complete to complete in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cldwalker committed Jul 21, 2009
1 parent 8f7eb9d commit 1f9b63d
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 42 deletions.
8 changes: 4 additions & 4 deletions test/agent_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ class Bond::AgentTest < Test::Unit::TestCase
before(:each) {|e| Bond.agent.reset }

test "chooses default mission if no missions match" do
Bond.complete(:on=>/bling/) {|e| [] }
complete(:on=>/bling/) {|e| [] }
Bond.agent.default_mission.expects(:execute)
tabtab 'blah'
end

test "chooses default mission if internal processing fails" do
Bond.complete(:on=>/bling/) {|e| [] }
complete(:on=>/bling/) {|e| [] }
Bond.agent.expects(:find_mission).raises
Bond.agent.default_mission.expects(:execute)
tabtab('bling')
Expand All @@ -22,8 +22,8 @@ class Bond::AgentTest < Test::Unit::TestCase

context "spy" do
before(:all) {
Bond.reset; Bond.complete(:on=>/end$/) { [] }; Bond.complete(:method=>'the') { %w{spy who loved me} }
Bond.complete(:object=>"Symbol")
Bond.reset; complete(:on=>/end$/) { [] }; complete(:method=>'the') { %w{spy who loved me} }
complete(:object=>"Symbol")
}

test "detects basic mission" do
Expand Down
12 changes: 6 additions & 6 deletions test/bond_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,29 @@ class BondTest < Test::Unit::TestCase

context "complete" do
test "prints error if no action given" do
capture_stderr { Bond.complete :on=>/blah/ }.should =~ /Invalid mission/
capture_stderr { complete :on=>/blah/ }.should =~ /Invalid mission/
end

test "prints error if no condition given" do
capture_stderr { Bond.complete {|e| []} }.should =~ /Invalid mission/
capture_stderr { complete {|e| []} }.should =~ /Invalid mission/
end

test "prints error if invalid condition given" do
capture_stderr { Bond.complete(:on=>'blah') {|e| []} }.should =~ /Invalid mission/
capture_stderr { complete(:on=>'blah') {|e| []} }.should =~ /Invalid mission/
end

test "prints error if invalid symbol action given" do
capture_stderr { Bond.complete(:on=>/blah/, :action=>:bling) }.should =~ /Invalid mission action/
capture_stderr { complete(:on=>/blah/, :action=>:bling) }.should =~ /Invalid mission action/
end

test "prints error if setting mission fails unpredictably" do
Bond.agent.expects(:complete).raises(ArgumentError)
capture_stderr { Bond.complete(:on=>/blah/) {|e| [] } }.should =~ /Mission setup failed/
capture_stderr { complete(:on=>/blah/) {|e| [] } }.should =~ /Mission setup failed/
end
end

test "reset clears existing missions" do
Bond.complete(:on=>/blah/) {[]}
complete(:on=>/blah/) {[]}
Bond.agent.missions.size.should_not == 0
Bond.reset
Bond.agent.missions.size.should == 0
Expand Down
26 changes: 13 additions & 13 deletions test/mission_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,53 +6,53 @@ class Bond::MissionTest < Test::Unit::TestCase
context "mission" do
before(:each) {|e| Bond.agent.reset }
test "completes" do
Bond.complete(:on=>/bling/) {|e| %w{ab cd fg hi}}
Bond.complete(:method=>'cool') {|e| [] }
complete(:on=>/bling/) {|e| %w{ab cd fg hi}}
complete(:method=>'cool') {|e| [] }
tabtab('some bling f').should == %w{fg}
end

test "with method completes" do
Bond.complete(:on=>/bling/) {|e| [] }
Bond.complete(:method=>'cool') {|e| %w{ab cd ef gd} }
complete(:on=>/bling/) {|e| [] }
complete(:method=>'cool') {|e| %w{ab cd ef gd} }
tabtab('cool c').should == %w{cd}
end

test "with method and quoted argument completes" do
Bond.complete(:on=>/bling/) {|e| [] }
Bond.complete(:method=>'cool') {|e| %w{ab cd ef ad} }
complete(:on=>/bling/) {|e| [] }
complete(:method=>'cool') {|e| %w{ab cd ef ad} }
tabtab('cool "a').should == %w{ab ad}
end

test "with string method completes exact matches" do
Bond.complete(:method=>'cool?') {|e| [] }
Bond.complete(:method=>'cool') {|e| %w{ab cd ef gd} }
complete(:method=>'cool?') {|e| [] }
complete(:method=>'cool') {|e| %w{ab cd ef gd} }
tabtab('cool c').should == %w{cd}
end

test "with regex method completes multiple methods" do
Bond.complete(:method=>/cool|ls/) {|e| %w{ab cd ef ad}}
complete(:method=>/cool|ls/) {|e| %w{ab cd ef ad}}
tabtab("cool a").should == %w{ab ad}
tabtab("ls c").should == %w{cd}
end

test "with regexp condition completes" do
Bond.complete(:on=>/\s*'([^']+)$/, :search=>false) {|e| %w{coco for puffs}.grep(/#{e.matched[1]}/) }
complete(:on=>/\s*'([^']+)$/, :search=>false) {|e| %w{coco for puffs}.grep(/#{e.matched[1]}/) }
tabtab("require 'ff").should == ['puffs']
end

test "with non-string completions completes" do
Bond.complete(:on=>/.*/) { [:one,:two,:three] }
complete(:on=>/.*/) { [:one,:two,:three] }
tabtab('ok ').should == %w{one two three}
end

test "with symbol action completes" do
eval %[module ::Bond::Actions; def blah(input); %w{one two three}; end; end]
Bond.complete(:method=>'blah', :action=>:blah)
complete(:method=>'blah', :action=>:blah)
tabtab('blah ').should == %w{one two three}
end

test "with invalid action prints error" do
Bond.complete(:on=>/bling/) {|e| raise "whoops" }
complete(:on=>/bling/) {|e| raise "whoops" }
capture_stderr { tabtab('bling') }.should =~ /bling.*whoops/m
end
end
Expand Down
22 changes: 11 additions & 11 deletions test/object_mission_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,52 @@ class Bond::ObjectMissionTest < Test::Unit::TestCase
before(:each) {|e| Bond.agent.reset }
context "object mission" do
test "with default action completes" do
Bond.complete(:object=>"String")
Bond.complete(:on=>/man/) { %w{upper upster upful}}
complete(:object=>"String")
complete(:on=>/man/) { %w{upper upster upful}}
tabtab("'man'.u").should == [".upcase!", ".unpack", ".untaint", ".upcase", ".upto"]
end

test "with regex condition completes" do
Bond.complete(:object=>/Str/) {|e| e.object.class.superclass.instance_methods(true) }
Bond.complete(:on=>/man/) { %w{upper upster upful}}
complete(:object=>/Str/) {|e| e.object.class.superclass.instance_methods(true) }
complete(:on=>/man/) { %w{upper upster upful}}
tabtab("'man'.u").should == [".untaint"]
end

test "with explicit action completes" do
Bond.complete(:object=>"String") {|e| e.object.class.superclass.instance_methods(true) }
Bond.complete(:on=>/man/) { %w{upper upster upful}}
complete(:object=>"String") {|e| e.object.class.superclass.instance_methods(true) }
complete(:on=>/man/) { %w{upper upster upful}}
tabtab("'man'.u").should == [".untaint"]
end

test "completes without including word break characters" do
Bond.complete(:object=>"Hash")
complete(:object=>"Hash")
matches = tabtab("{}.f")
assert matches.size > 0
matches.all? {|e| !e.include?('{')}.should == true
end

test "completes nil, false and range objects" do
Bond.complete(:object=>"Object")
complete(:object=>"Object")
assert tabtab("nil.f").size > 0
assert tabtab("false.f").size > 0
assert tabtab("(1..10).f").size > 0
end

test "completes hashes and arrays with spaces" do
Bond.complete(:object=>"Object")
complete(:object=>"Object")
assert tabtab("[1, 2].f").size > 0
assert tabtab("{:a =>1}.f").size > 0
end

test "ignores invalid invalid ruby" do
Bond.complete(:object=>"String")
complete(:object=>"String")
tabtab("blah.upt").should == []
end

# needed to ensure Bond works in irbrc
test "doesn't evaluate irb binding on definition" do
Object.expects(:const_defined?).never
Bond.complete(:object=>"String")
complete(:object=>"String")
end

test "sets binding to toplevel binding when not in irb" do
Expand Down
16 changes: 8 additions & 8 deletions test/search_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,48 @@ class Bond::SearchTest < Test::Unit::TestCase

context "mission with search" do
test "false completes" do
Bond.complete(:on=>/cool '(.*)/, :search=>false) {|e| %w{coco for puffs}.grep(/#{e.matched[1]}/) }
complete(:on=>/cool '(.*)/, :search=>false) {|e| %w{coco for puffs}.grep(/#{e.matched[1]}/) }
tabtab("cool 'ff").should == ['puffs']
end

test "proc completes" do
Bond.complete(:method=>'blah', :search=>proc {|input, list| list.grep(/#{input}/)}) {|e| %w{coco for puffs} }
complete(:method=>'blah', :search=>proc {|input, list| list.grep(/#{input}/)}) {|e| %w{coco for puffs} }
tabtab("blah 'ff").should == ['puffs']
end

test ":anywhere completes" do
Bond.complete(:method=>'blah', :search=>:anywhere) {|e| %w{coco for puffs} }
complete(:method=>'blah', :search=>:anywhere) {|e| %w{coco for puffs} }
tabtab("blah 'ff").should == ['puffs']
end

test ":ignore_case completes" do
Bond.complete(:method=>'blah', :search=>:ignore_case) {|e| %w{Coco For PufFs} }
complete(:method=>'blah', :search=>:ignore_case) {|e| %w{Coco For PufFs} }
tabtab("blah 'pu").should == ['PufFs']
end

test ":underscore completes" do
Bond.complete(:on=>/blah/, :search=>:underscore) {|e| %w{and_one big_two can_three} }
complete(:on=>/blah/, :search=>:underscore) {|e| %w{and_one big_two can_three} }
tabtab("blah and").should == ['and_one']
tabtab("blah b-t").should == ['big_two']
end
end

test "underscore search doesn't pick up strings starting with __" do
completions = ["include?", "instance_variable_defined?", "__id__", "include_and_exclude?"]
Bond.complete(:method=>'blah', :search=>:underscore) { completions }
complete(:method=>'blah', :search=>:underscore) { completions }
tabtab("blah i").should == ["include?", "instance_variable_defined?", "include_and_exclude?"]
end

test "underscore search can match first unique strings of each underscored word" do
completions = %w{so_long so_larger so_louder}
Bond.complete(:method=>'blah', :search=>:underscore) { completions }
complete(:method=>'blah', :search=>:underscore) { completions }
tabtab("blah s-lo").should == %w{so_long so_louder}
tabtab("blah s-lou").should == %w{so_louder}
end

test "search handles completions with regex characters" do
completions = ['[doh]', '.*a', '?ok']
Bond.complete(:on=>/blah/) { completions }
complete(:on=>/blah/) { completions }
tabtab('blah .').should == ['.*a']
tabtab('blah [').should == ['[doh]']
tabtab('blah ?').should == ['?ok']
Expand Down
4 changes: 4 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def tabtab(full_line, last_word=full_line)
Bond.agent.call(last_word)
end

def complete(*args, &block)
Bond.complete(*args, &block)
end

def valid_readline_plugin
Module.new{ def setup; end; def line_buffer; end }
end
Expand Down

0 comments on commit 1f9b63d

Please sign in to comment.