forked from ruby/spec
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactored + added spec to test for optional pattern parameter
- Loading branch information
1 parent
08a1465
commit d9144ec
Showing
1 changed file
with
44 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,51 @@ | ||
require File.dirname(__FILE__) + '/../../spec_helper' | ||
require 'abbrev' | ||
|
||
#test both Abbrev::abbrev and Array#abbrev in | ||
#the same manner, as they're more or less aliases | ||
#of one another | ||
|
||
[["Abbrev::abbrev", lambda {|a| Abbrev::abbrev(a)}], | ||
["Array#abbrev", lambda {|a| a.abbrev}] | ||
].each do |(name, func)| | ||
describe "Abbrev::abbrev" do | ||
it "returns a hash of all unambiguous abbreviations of the array of strings passed in" do | ||
Abbrev::abbrev(['ruby', 'rules']).should == {"rub" => "ruby", | ||
"ruby" => "ruby", | ||
"rul" => "rules", | ||
"rule" => "rules", | ||
"rules" => "rules"} | ||
|
||
Abbrev::abbrev(["car", "cone"]).should == {"ca" => "car", | ||
"car" => "car", | ||
"co" => "cone", | ||
"con" => "cone", | ||
"cone" => "cone"} | ||
end | ||
|
||
describe name do | ||
it "returns a hash of all unambiguous abbreviations of the array of strings passed in" do | ||
func.call(['ruby', 'rules']).should == {"rub" => "ruby", | ||
"ruby" => "ruby", | ||
"rul" => "rules", | ||
"rule" => "rules", | ||
"rules" => "rules"} | ||
|
||
func.call(["car", "cone"]).should == {"ca" => "car", | ||
"car" => "car", | ||
"co" => "cone", | ||
"con" => "cone", | ||
"cone" => "cone"} | ||
end | ||
it "passing in a pattern as an optional parameter should filter the abbreviations returned in the hash" do | ||
Abbrev::abbrev(['ruby','rules'],'rub').should == {"ruby"=>"ruby", "rub"=>"ruby"} | ||
end | ||
|
||
it "returns an empty hash when called on an empty array" do | ||
Abbrev::abbrev([]).should == {} | ||
end | ||
end | ||
|
||
describe "Array#abbrev" do | ||
it "returns a hash of all unambiguous abbreviations of the array of strings passed in" do | ||
['ruby', 'rules'].abbrev.should == {"rub" => "ruby", | ||
"ruby" => "ruby", | ||
"rul" => "rules", | ||
"rule" => "rules", | ||
"rules" => "rules"} | ||
|
||
it "returns an empty hash when called on an empty array" do | ||
func.call([]).should == {} | ||
end | ||
["car", "cone"].abbrev.should == {"ca" => "car", | ||
"car" => "car", | ||
"co" => "cone", | ||
"con" => "cone", | ||
"cone" => "cone"} | ||
end | ||
|
||
it "passing in a pattern as an optional parameter should filter the abbreviations returned in the hash" do | ||
['ruby','rules'].abbrev('rub').should == {"ruby"=>"ruby", "rub"=>"ruby"} | ||
end | ||
|
||
it "returns an empty hash when called on an empty array" do | ||
[].abbrev.should == {} | ||
end | ||
end | ||
|