test/search_test.rb in bond-0.1.4 vs test/search_test.rb in bond-0.2.0
- old
+ new
@@ -1,55 +1,132 @@
require File.join(File.dirname(__FILE__), 'test_helper')
-class Bond::SearchTest < Test::Unit::TestCase
- before(:all) {|e| Bond.debrief(:readline_plugin=>valid_readline_plugin) }
- before(:each) {|e| Bond.agent.reset }
+describe "Search" do
+ before { Bond.agent.reset }
- context "mission with search" do
- test "false completes" do
+ describe "mission with search" do
+ it "false completes" do
complete(:on=>/cool '(.*)/, :search=>false) {|e| %w{coco for puffs}.grep(/#{e.matched[1]}/) }
- tabtab("cool 'ff").should == ['puffs']
+ tab("cool 'ff").should == ['puffs']
end
- test "proc completes" do
- complete(:method=>'blah', :search=>proc {|input, list| list.grep(/#{input}/)}) {|e| %w{coco for puffs} }
- tabtab("blah 'ff").should == ['puffs']
+ it "defined in Rc completes" do
+ Rc.module_eval %q{def coco_search(input, list); list.grep(/#{input}/); end }
+ complete(:on=>/blah/, :search=>:coco) {|e| %w{coco for puffs} }
+ tab("blah ff").should == ['puffs']
end
- test ":anywhere completes" do
- complete(:method=>'blah', :search=>:anywhere) {|e| %w{coco for puffs} }
- tabtab("blah 'ff").should == ['puffs']
+ it ":anywhere completes" do
+ complete(:on=>/blah/, :search=>:anywhere) {|e| %w{coco for puffs} }
+ tab("blah ff").should == ['puffs']
end
- test ":ignore_case completes" do
- complete(:method=>'blah', :search=>:ignore_case) {|e| %w{Coco For PufFs} }
- tabtab("blah 'pu").should == ['PufFs']
+ it ":ignore_case completes" do
+ complete(:on=>/blah/, :search=>:ignore_case) {|e| %w{Coco For PufFs} }
+ tab("blah pu").should == ['PufFs']
end
- test ":underscore completes" do
+ it ":underscore completes" do
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']
+ tab("blah and").should == ['and_one']
+ tab("blah b_t").should == ['big_two']
end
end
- test "underscore search doesn't pick up strings starting with __" do
+ it "underscore search doesn't pick up strings starting with __" do
completions = ["include?", "instance_variable_defined?", "__id__", "include_and_exclude?"]
- complete(:method=>'blah', :search=>:underscore) { completions }
- tabtab("blah i").should == ["include?", "instance_variable_defined?", "include_and_exclude?"]
+ complete(:on=>/blah/, :search=>:underscore) { completions }
+ tab("blah i").should == ["include?", "instance_variable_defined?", "include_and_exclude?"]
end
- test "underscore search can match first unique strings of each underscored word" do
+ it "underscore search can match first unique strings of each underscored word" do
completions = %w{so_long so_larger so_louder}
- complete(:method=>'blah', :search=>:underscore) { completions }
- tabtab("blah s-lo").should == %w{so_long so_louder}
- tabtab("blah s-lou").should == %w{so_louder}
+ complete(:on=>/blah/, :search=>:underscore) { completions }
+ tab("blah s_lo").should == %w{so_long so_louder}
+ tab("blah s_lou").should == %w{so_louder}
end
- test "search handles completions with regex characters" do
+ it "underscore search acts normal if ending in underscore" do
+ complete(:on=>/blah/, :search=>:underscore) {|e| %w{and_one big_two can_three ander_one} }
+ tab("blah and_").should == %w{and_one}
+ end
+
+ it "search handles completions with regex characters" do
completions = ['[doh]', '.*a', '?ok']
complete(:on=>/blah/) { completions }
- tabtab('blah .').should == ['.*a']
- tabtab('blah [').should == ['[doh]']
- tabtab('blah ?').should == ['?ok']
+ tab('blah .').should == ['.*a']
+ tab('blah [').should == ['[doh]']
+ tab('blah ?').should == ['?ok']
+ end
+
+ it "default search uses default search" do
+ Search.default_search.should == :underscore
+ Rc.expects(:underscore_search).with('a', %w{ab cd})
+ Rc.send(:default_search, 'a', %w{ab cd})
+ end
+
+ describe "modules search" do
+ before {
+ complete(:on=>/blah/, :search=>:modules) { %w{A1 M1::Z M1::Y::X M2::X} }
+ }
+ it "completes all modules" do
+ tab('blah ').should == ["A1", "M1::", "M2::"]
+ end
+
+ it "completes single first level module" do
+ tab('blah A').should == %w{A1}
+ end
+
+ it "completes single first level module parent" do
+ tab('blah M2').should == %w{M2::}
+ end
+
+ it "completes all second level modules" do
+ tab('blah M1::').should == %w{M1::Z M1::Y::}
+ end
+
+ it "completes second level module parent" do
+ tab('blah M1::Y').should == %w{M1::Y::}
+ end
+
+ it "completes third level module" do
+ tab('blah M1::Y::').should == %w{M1::Y::X}
+ end
+ end
+
+ describe "files search" do
+ before {
+ complete(:on=>/rm/, :search=>:files) { %w{a1 d1/f2 d1/d2/f1 d2/f1 d2/f1/ /f1} }
+ }
+ it "completes all paths" do
+ tab('rm ').should == %w{a1 d1/ d2/ /}
+ end
+
+ it "completes single first level file" do
+ tab('rm a').should == %w{a1}
+ end
+
+ it "completes single first level directory" do
+ tab('rm d2').should == %w{d2/}
+ end
+
+ it "completes all second level paths" do
+ tab('rm d1/').should == %w{d1/f2 d1/d2/}
+ end
+
+ it "completes single second level directory" do
+ tab('rm d1/d2').should == %w{d1/d2/}
+ end
+
+ it "completes single third level file" do
+ tab('rm d1/d2/').should == %w{d1/d2/f1}
+ end
+
+ it "completes file and directory with same name" do
+ tab('rm d2/f').should == %w{d2/f1 d2/f1/}
+ end
+
+ it "completes file with full path" do
+ tab('rm /f').should == %w{/f1}
+ end
end
end
\ No newline at end of file