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.
This commit is contained in:
Jack Nagel 2013-08-22 11:34:23 -05:00
parent 1abb8cdf81
commit 7654077752

View File

@ -54,6 +54,15 @@ class OptionsTests < Test::Unit::TestCase
assert_equal 1, @options.count assert_equal 1, @options.count
end 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 def test_include
@options << Option.new("foo") @options << Option.new("foo")
assert @options.include? "--foo" assert @options.include? "--foo"