| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  | require "testing_env" | 
					
						
							|  |  |  | require "options" | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:23 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 20:32:51 -05:00
										 |  |  | class OptionTests < Homebrew::TestCase | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:23 -06:00
										 |  |  |   def setup | 
					
						
							|  |  |  |     @option = Option.new("foo") | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_to_s | 
					
						
							|  |  |  |     assert_equal "--foo", @option.to_s | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_equality | 
					
						
							|  |  |  |     foo = Option.new("foo") | 
					
						
							|  |  |  |     bar = Option.new("bar") | 
					
						
							|  |  |  |     assert_equal foo, @option | 
					
						
							| 
									
										
										
										
											2014-06-10 22:43:47 -05:00
										 |  |  |     refute_equal bar, @option | 
					
						
							| 
									
										
										
										
											2014-07-03 16:54:46 -05:00
										 |  |  |     assert_eql @option, foo | 
					
						
							|  |  |  |     refute_eql @option, bar | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:23 -06:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_description | 
					
						
							|  |  |  |     assert_empty @option.description | 
					
						
							|  |  |  |     assert_equal "foo", Option.new("foo", "foo").description | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2015-07-20 21:46:05 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def test_inspect | 
					
						
							|  |  |  |     assert_equal "#<Option: \"--foo\">", @option.inspect | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:23 -06:00
										 |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-16 12:58:34 +01:00
										 |  |  | class DeprecatedOptionTests < Homebrew::TestCase | 
					
						
							|  |  |  |   def setup | 
					
						
							|  |  |  |     @deprecated_option = DeprecatedOption.new("foo", "bar") | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_old | 
					
						
							|  |  |  |     assert_equal "foo", @deprecated_option.old | 
					
						
							| 
									
										
										
										
											2014-10-16 13:00:20 +01:00
										 |  |  |     assert_equal "--foo", @deprecated_option.old_flag | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_current | 
					
						
							| 
									
										
										
										
											2014-12-02 11:15:20 -05:00
										 |  |  |     assert_equal "bar", @deprecated_option.current | 
					
						
							| 
									
										
										
										
											2014-10-16 13:00:20 +01:00
										 |  |  |     assert_equal "--bar", @deprecated_option.current_flag | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_equality | 
					
						
							|  |  |  |     foobar = DeprecatedOption.new("foo", "bar") | 
					
						
							|  |  |  |     boofar = DeprecatedOption.new("boo", "far") | 
					
						
							|  |  |  |     assert_equal foobar, @deprecated_option | 
					
						
							|  |  |  |     refute_equal boofar, @deprecated_option | 
					
						
							|  |  |  |     assert_eql @deprecated_option, foobar | 
					
						
							|  |  |  |     refute_eql @deprecated_option, boofar | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2014-10-16 12:58:34 +01:00
										 |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 20:32:51 -05:00
										 |  |  | class OptionsTests < Homebrew::TestCase | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:23 -06:00
										 |  |  |   def setup | 
					
						
							|  |  |  |     @options = Options.new | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_no_duplicate_options | 
					
						
							|  |  |  |     @options << Option.new("foo") | 
					
						
							|  |  |  |     @options << Option.new("foo") | 
					
						
							| 
									
										
										
										
											2014-06-11 13:03:06 -05:00
										 |  |  |     assert_includes @options, "--foo" | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:23 -06:00
										 |  |  |     assert_equal 1, @options.count | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-22 11:34:23 -05:00
										 |  |  |   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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:23 -06:00
										 |  |  |   def test_include | 
					
						
							|  |  |  |     @options << Option.new("foo") | 
					
						
							| 
									
										
										
										
											2014-06-11 13:03:06 -05:00
										 |  |  |     assert_includes @options, "--foo" | 
					
						
							|  |  |  |     assert_includes @options, "foo" | 
					
						
							|  |  |  |     assert_includes @options, Option.new("foo") | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:23 -06:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_union_returns_options | 
					
						
							| 
									
										
										
										
											2014-08-13 17:13:27 -05:00
										 |  |  |     assert_instance_of Options, @options + Options.new | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:23 -06:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_difference_returns_options | 
					
						
							| 
									
										
										
										
											2014-08-13 17:13:27 -05:00
										 |  |  |     assert_instance_of Options, @options - Options.new | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:23 -06:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_shovel_returns_self | 
					
						
							| 
									
										
										
										
											2014-08-13 17:13:27 -05:00
										 |  |  |     assert_same @options, @options << Option.new("foo") | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:23 -06:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_as_flags | 
					
						
							|  |  |  |     @options << Option.new("foo") | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     assert_equal %w[--foo], @options.as_flags | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:23 -06:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_to_a | 
					
						
							|  |  |  |     option = Option.new("foo") | 
					
						
							|  |  |  |     @options << option | 
					
						
							|  |  |  |     assert_equal [option], @options.to_a | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_to_ary | 
					
						
							|  |  |  |     option = Option.new("foo") | 
					
						
							|  |  |  |     @options << option | 
					
						
							|  |  |  |     assert_equal [option], @options.to_ary | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:28 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def test_intersection | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     foo, bar, baz = %w[foo bar baz].map { |o| Option.new(o) } | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:28 -06:00
										 |  |  |     options = Options.new << foo << bar | 
					
						
							|  |  |  |     @options << foo << baz | 
					
						
							|  |  |  |     assert_equal [foo], (@options & options).to_a | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 14:22:42 -06:00
										 |  |  |   def test_set_union | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     foo, bar, baz = %w[foo bar baz].map { |o| Option.new(o) } | 
					
						
							| 
									
										
										
										
											2014-02-27 14:22:42 -06:00
										 |  |  |     options = Options.new << foo << bar | 
					
						
							|  |  |  |     @options << foo << baz | 
					
						
							| 
									
										
										
										
											2014-08-13 11:09:57 -05:00
										 |  |  |     assert_equal [foo, bar, baz].sort, (@options | options).sort | 
					
						
							| 
									
										
										
										
											2014-02-27 14:22:42 -06:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-20 21:46:05 +02:00
										 |  |  |   def test_times | 
					
						
							|  |  |  |     @options << Option.new("aa") << Option.new("bb") << Option.new("cc") | 
					
						
							|  |  |  |     assert_equal %w[--aa --bb --cc], (@options * "XX").split("XX").sort | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-13 11:09:57 -05:00
										 |  |  |   def test_create_with_array | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     array = %w[--foo --bar] | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:28 -06:00
										 |  |  |     option1 = Option.new("foo") | 
					
						
							|  |  |  |     option2 = Option.new("bar") | 
					
						
							| 
									
										
										
										
											2014-08-13 11:09:57 -05:00
										 |  |  |     assert_equal [option1, option2].sort, Options.create(array).sort | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:28 -06:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2015-07-20 21:46:05 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def test_inspect | 
					
						
							|  |  |  |     assert_equal "#<Options: []>", @options.inspect | 
					
						
							|  |  |  |     @options << Option.new("foo") | 
					
						
							|  |  |  |     assert_equal "#<Options: [#<Option: \"--foo\">]>", @options.inspect | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:23 -06:00
										 |  |  | end |