diff options
| author | Jack Nagel | 2013-01-13 19:51:19 -0600 |
|---|---|---|
| committer | Jack Nagel | 2013-01-13 21:01:15 -0600 |
| commit | e629f14d56b803ffbc7f3470175f2b021a8816eb (patch) | |
| tree | a2a68e1157263a5a7761f43702933af926157ab7 /Library/Homebrew | |
| parent | 2d445d54b5110e03b6a089fed25865f1d02bfed4 (diff) | |
| download | brew-e629f14d56b803ffbc7f3470175f2b021a8816eb.tar.bz2 | |
Remove <=> from Dependency interface
It is important that dep equality corresponds to the name attribute, but
we may want to use the Comparable interface to sort them by installation
order in the future. Code that needs to sort them alphabetically should
just use sort_by.
Diffstat (limited to 'Library/Homebrew')
| -rw-r--r-- | Library/Homebrew/cmd/deps.rb | 4 | ||||
| -rw-r--r-- | Library/Homebrew/dependencies.rb | 20 | ||||
| -rw-r--r-- | Library/Homebrew/test/test_dependencies.rb | 43 |
3 files changed, 48 insertions, 19 deletions
diff --git a/Library/Homebrew/cmd/deps.rb b/Library/Homebrew/cmd/deps.rb index a26dca03c..b26030082 100644 --- a/Library/Homebrew/cmd/deps.rb +++ b/Library/Homebrew/cmd/deps.rb @@ -22,7 +22,9 @@ module Homebrew extend self end else raise FormulaUnspecifiedError if ARGV.named.empty? - all_deps = ARGV.formulae.map{ |f| ARGV.one? ? f.deps : f.recursive_deps }.intersection + all_deps = ARGV.formulae.map do |f| + ARGV.one? ? f.deps : f.recursive_deps + end.intersection.map(&:name) all_deps.sort! unless ARGV.include? "-n" puts all_deps end diff --git a/Library/Homebrew/dependencies.rb b/Library/Homebrew/dependencies.rb index 8b4916279..623591c78 100644 --- a/Library/Homebrew/dependencies.rb +++ b/Library/Homebrew/dependencies.rb @@ -145,27 +145,23 @@ class Dependency def initialize(name, *tags) @name = name - @tags = [tags].flatten.compact - end - - def hash - @name.hash + @tags = tags.flatten.compact end def to_s - @name + name end def ==(other) - @name == other.to_s + name == other.name end - def <=>(other) - @name <=> other.to_s + def eql?(other) + other.is_a?(self.class) && hash == other.hash end - def eql?(other) - other.is_a? self.class and hash == other.hash + def hash + name.hash end end @@ -199,7 +195,7 @@ class Requirement end def eql?(other) - other.is_a? self.class and hash == other.hash + other.is_a?(self.class) && hash == other.hash end def hash diff --git a/Library/Homebrew/test/test_dependencies.rb b/Library/Homebrew/test/test_dependencies.rb index ebfd8ac01..68c4043cb 100644 --- a/Library/Homebrew/test/test_dependencies.rb +++ b/Library/Homebrew/test/test_dependencies.rb @@ -75,17 +75,48 @@ end class DependableTests < Test::Unit::TestCase def setup @tags = ["foo", "bar", :build] - @deps = Struct.new(:tags).new(@tags) - @deps.extend(Dependable) + @dep = Struct.new(:tags).new(@tags).extend(Dependable) end def test_options - assert_equal %w{--foo --bar}.sort, @deps.options.sort + assert_equal %w{--foo --bar}.sort, @dep.options.sort end def test_interrogation - assert @deps.build? - assert !@deps.optional? - assert !@deps.recommended? + assert @dep.build? + assert !@dep.optional? + assert !@dep.recommended? + end +end + +class DependencyTests < Test::Unit::TestCase + def test_accepts_single_tag + dep = Dependency.new("foo", "bar") + assert_equal %w{bar}, dep.tags + end + + def test_accepts_multiple_tags + dep = Dependency.new("foo", %w{bar baz}) + assert_equal %w{bar baz}.sort, dep.tags.sort + end + + def test_preserves_symbol_tags + dep = Dependency.new("foo", :build) + assert_equal [:build], dep.tags + end + + def test_accepts_symbol_and_string_tags + dep = Dependency.new("foo", [:build, "bar"]) + assert_equal [:build, "bar"], dep.tags + end + + def test_equality + foo1 = Dependency.new("foo") + foo2 = Dependency.new("foo") + bar = Dependency.new("bar") + assert_equal foo1, foo2 + assert foo1.eql?(foo2) + assert_not_equal foo1, bar + assert !foo1.eql?(bar) end end |
