| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  | require "testing_env" | 
					
						
							|  |  |  | require "patch" | 
					
						
							| 
									
										
										
										
											2014-03-13 19:51:23 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 20:32:51 -05:00
										 |  |  | class PatchTests < Homebrew::TestCase | 
					
						
							| 
									
										
										
										
											2014-03-13 19:51:23 -05:00
										 |  |  |   def test_create_simple | 
					
						
							| 
									
										
										
										
											2014-07-10 12:38:09 -05:00
										 |  |  |     patch = Patch.create(:p2, nil) | 
					
						
							| 
									
										
										
										
											2014-03-13 19:51:23 -05:00
										 |  |  |     assert_kind_of ExternalPatch, patch | 
					
						
							| 
									
										
										
										
											2014-06-11 12:21:03 -05:00
										 |  |  |     assert_predicate patch, :external? | 
					
						
							| 
									
										
										
										
											2014-03-13 19:51:23 -05:00
										 |  |  |     assert_equal :p2, patch.strip | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_create_string | 
					
						
							|  |  |  |     patch = Patch.create(:p0, "foo") | 
					
						
							| 
									
										
										
										
											2014-07-29 16:06:07 -05:00
										 |  |  |     assert_kind_of StringPatch, patch | 
					
						
							| 
									
										
										
										
											2014-03-13 19:51:23 -05:00
										 |  |  |     assert_equal :p0, patch.strip | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_create_string_without_strip | 
					
						
							| 
									
										
										
										
											2014-07-10 12:38:09 -05:00
										 |  |  |     patch = Patch.create("foo", nil) | 
					
						
							| 
									
										
										
										
											2014-07-29 16:06:07 -05:00
										 |  |  |     assert_kind_of StringPatch, patch | 
					
						
							| 
									
										
										
										
											2014-03-13 19:51:23 -05:00
										 |  |  |     assert_equal :p1, patch.strip | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_create_DATA | 
					
						
							|  |  |  |     patch = Patch.create(:p0, :DATA) | 
					
						
							| 
									
										
										
										
											2014-07-29 16:06:06 -05:00
										 |  |  |     assert_kind_of DATAPatch, patch | 
					
						
							| 
									
										
										
										
											2014-03-13 19:51:23 -05:00
										 |  |  |     assert_equal :p0, patch.strip | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_create_DATA_without_strip | 
					
						
							| 
									
										
										
										
											2014-07-10 12:38:09 -05:00
										 |  |  |     patch = Patch.create(:DATA, nil) | 
					
						
							| 
									
										
										
										
											2014-07-29 16:06:06 -05:00
										 |  |  |     assert_kind_of DATAPatch, patch | 
					
						
							| 
									
										
										
										
											2014-03-13 19:51:23 -05:00
										 |  |  |     assert_equal :p1, patch.strip | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_raises_for_unknown_values | 
					
						
							|  |  |  |     assert_raises(ArgumentError) { Patch.create(Object.new) } | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							| 
									
										
										
										
											2014-03-13 19:51:23 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 20:32:51 -05:00
										 |  |  | class LegacyPatchTests < Homebrew::TestCase | 
					
						
							| 
									
										
										
										
											2014-03-13 19:51:23 -05:00
										 |  |  |   def test_patch_single_string | 
					
						
							|  |  |  |     patches = Patch.normalize_legacy_patches("http://example.com/patch.diff") | 
					
						
							|  |  |  |     assert_equal 1, patches.length | 
					
						
							|  |  |  |     assert_equal :p1, patches.first.strip | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_patch_array | 
					
						
							|  |  |  |     patches = Patch.normalize_legacy_patches( | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |       %w[http://example.com/patch1.diff http://example.com/patch2.diff] | 
					
						
							| 
									
										
										
										
											2014-03-13 19:51:23 -05:00
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     assert_equal 2, patches.length | 
					
						
							|  |  |  |     assert_equal :p1, patches[0].strip | 
					
						
							|  |  |  |     assert_equal :p1, patches[1].strip | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_p0_hash_to_string | 
					
						
							|  |  |  |     patches = Patch.normalize_legacy_patches( | 
					
						
							|  |  |  |       :p0 => "http://example.com/patch.diff" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     assert_equal 1, patches.length | 
					
						
							|  |  |  |     assert_equal :p0, patches.first.strip | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_p1_hash_to_string | 
					
						
							|  |  |  |     patches = Patch.normalize_legacy_patches( | 
					
						
							|  |  |  |       :p1 => "http://example.com/patch.diff" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     assert_equal 1, patches.length | 
					
						
							|  |  |  |     assert_equal :p1, patches.first.strip | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_mixed_hash_to_strings | 
					
						
							|  |  |  |     patches = Patch.normalize_legacy_patches( | 
					
						
							|  |  |  |       :p1 => "http://example.com/patch1.diff", | 
					
						
							|  |  |  |       :p0 => "http://example.com/patch0.diff" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     assert_equal 2, patches.length | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     assert_equal 1, patches.count { |p| p.strip == :p0 } | 
					
						
							|  |  |  |     assert_equal 1, patches.count { |p| p.strip == :p1 } | 
					
						
							| 
									
										
										
										
											2014-03-13 19:51:23 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_mixed_hash_to_arrays | 
					
						
							|  |  |  |     patches = Patch.normalize_legacy_patches( | 
					
						
							|  |  |  |       :p1 => ["http://example.com/patch10.diff", | 
					
						
							|  |  |  |               "http://example.com/patch11.diff"], | 
					
						
							|  |  |  |       :p0 => ["http://example.com/patch00.diff", | 
					
						
							|  |  |  |               "http://example.com/patch01.diff"] | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     assert_equal 4, patches.length | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     assert_equal 2, patches.count { |p| p.strip == :p0 } | 
					
						
							|  |  |  |     assert_equal 2, patches.count { |p| p.strip == :p1 } | 
					
						
							| 
									
										
										
										
											2014-03-13 19:51:23 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_nil | 
					
						
							|  |  |  |     assert_empty Patch.normalize_legacy_patches(nil) | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |