From 7654077752b1a43f034aca907cb23ee98dc80c2c Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Thu, 22 Aug 2013 11:34:23 -0500 Subject: [PATCH] Demonstrate the Set-like nature of Options collections Options collections are backed by Sets, and thus trying to push a new option with a name that duplicates an existing option cannot succeed. Later, we can exploit this behavior and remove some conditionals. --- Library/Homebrew/test/test_options.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Library/Homebrew/test/test_options.rb b/Library/Homebrew/test/test_options.rb index 0cc16ff2e6..b0f5603541 100644 --- a/Library/Homebrew/test/test_options.rb +++ b/Library/Homebrew/test/test_options.rb @@ -54,6 +54,15 @@ class OptionsTests < Test::Unit::TestCase assert_equal 1, @options.count end + def test_preserves_existing_member_when_pushing_duplicate + a = Option.new("foo", "bar") + b = Option.new("foo", "qux") + @options << a << b + assert_equal 1, @options.count + assert_same a, @options.first + assert_equal a.description, @options.first.description + end + def test_include @options << Option.new("foo") assert @options.include? "--foo"