@@ -221,6 +221,7 @@ defmodule PatchTest do
221221 assert diffs == patch_diffs
222222 end
223223
224+ @ tag :match_max_32
224225 test "long string with repeats" do
225226 text1 = repeats ( )
226227 text2 = text1 <> "123"
@@ -241,12 +242,30 @@ defmodule PatchTest do
241242 )
242243
243244 patches = Patch . split_max ( patches , 4 )
244- assert patches != [ ]
245245
246246 assert "@@ -1,32 +1,46 @@\n +X\n ab\n +X\n cd\n +X\n ef\n +X\n gh\n +X\n ij\n +X\n kl\n +X\n mn\n +X\n op\n +X\n qr\n +X\n st\n +X\n uv\n +X\n wx\n +X\n yz\n +X\n 012345\n @@ -25,13 +39,18 @@\n zX01\n +X\n 23\n +X\n 45\n +X\n 67\n +X\n 89\n +X\n 0\n " ==
247247 Patch . to_text ( patches )
248248 end
249249
250+ test "example 1, no splitting" do
251+ opts = [ match_max_bits: 0 ]
252+
253+ patches =
254+ Patch . make (
255+ "abcdefghijklmnopqrstuvwxyz01234567890" ,
256+ "XabXcdXefXghXijXklXmnXopXqrXstXuvXwxXyzX01X23X45X67X89X0" ,
257+ opts
258+ )
259+
260+ unsplit =
261+ "@@ -1,37 +1,56 @@\n +X\n ab\n +X\n cd\n +X\n ef\n +X\n gh\n +X\n ij\n +X\n kl\n +X\n mn\n +X\n op\n +X\n qr\n +X\n st\n +X\n uv\n +X\n wx\n +X\n yz\n +X\n 01\n +X\n 23\n +X\n 45\n +X\n 67\n +X\n 89\n +X\n 0\n "
262+
263+ assert unsplit == Patch . to_text ( patches )
264+
265+ patches = Patch . split_max ( patches , 4 , opts )
266+ assert unsplit == Patch . to_text ( patches )
267+ end
268+
250269 test "example 2" do
251270 patches =
252271 Patch . make (
@@ -272,7 +291,8 @@ defmodule PatchTest do
272291 Patch . to_text ( patches )
273292 end
274293
275- test "example 4" do
294+ @ tag :match_max_32
295+ test "example 4, 32 bits" do
276296 patches =
277297 Patch . make (
278298 "abcdefghij , h : 0 , t : 1 abcdefghij , h : 0 , t : 1 abcdefghij , h : 0 , t : 1" ,
@@ -284,6 +304,60 @@ defmodule PatchTest do
284304 assert "@@ -2,32 +2,32 @@\n bcdefghij , h : \n -0\n +1\n , t : 1 abcdef\n @@ -29,32 +29,32 @@\n bcdefghij , h : \n -0\n +1\n , t : 1 abcdef\n " ==
285305 Patch . to_text ( patches )
286306 end
307+
308+ @ tag :match_max_64
309+ test "example 4, 64 bits" do
310+ text1 = "abcdefghij , h : 0 , t : 1 abcdefghij , h : 0 , t : 1 abcdefghij , h : 0 , t : 1"
311+ text2 = "abcdefghij , h : 1 , t : 1 abcdefghij , h : 1 , t : 1 abcdefghij , h : 0 , t : 1"
312+ # text1, with only the first patch applied
313+ expected3 =
314+ "abcdefghij , h : 1 , t : 1 abcdefghij , h : 0 , t : 1 abcdefghij , h : 0 , t : 1"
315+
316+ patches_32 = Patch . make ( text1 , text2 )
317+
318+ assert "@@ -2,33 +2,33 @@\n bcdefghij , h : \n -0\n +1\n , t : 1 abcdefg\n @@ -29,33 +29,33 @@\n bcdefghij , h : \n -0\n +1\n , t : 1 abcdefg\n " ==
319+ Patch . to_text ( patches_32 )
320+
321+ # Only apply the first patch
322+ { text3 , _ } = patches_32 |> Enum . take ( 1 ) |> Patch . apply ( text1 )
323+ # Only the first "h : 0" was changed
324+ assert expected3 == text3
325+
326+ # Then apply the second patch
327+ { text4 , _ } = patches_32 |> Enum . drop ( 1 ) |> Patch . apply ( text3 )
328+ assert text2 == text4
329+
330+ patches_32 = Patch . split_max ( patches_32 , 4 )
331+ # After splitting, the patches are slightly different
332+ assert "@@ -2,32 +2,32 @@\n bcdefghij , h : \n -0\n +1\n , t : 1 abcdef\n @@ -29,32 +29,32 @@\n bcdefghij , h : \n -0\n +1\n , t : 1 abcdef\n " ==
333+ Patch . to_text ( patches_32 )
334+
335+ { text3 , _ } = Patch . apply ( patches_32 , text1 )
336+ assert text2 == text3
337+
338+ opts_64 = [ match_max_bits: 64 ]
339+ patches_64 = Patch . make ( text1 , text2 , opts_64 )
340+ # The patches are different than the 32-bit case
341+ assert "@@ -1,58 +1,58 @@\n abcdefghij , h : \n -0\n +1\n , t : 1 abcdefghij , h : 0 , t : 1 abcd\n @@ -29,33 +29,33 @@\n bcdefghij , h : \n -0\n +1\n , t : 1 abcdefg\n " ==
342+ Patch . to_text ( patches_64 )
343+
344+ # Only apply the first patch
345+ { text3 , _ } = patches_64 |> Enum . take ( 1 ) |> Patch . apply ( text1 )
346+ # Only the first "h : 0" was changed
347+ assert expected3 == text3
348+
349+ # Then apply the second patch
350+ { text4 , _ } = patches_64 |> Enum . drop ( 1 ) |> Patch . apply ( text3 )
351+ assert text2 == text4
352+
353+ patches_64 = Patch . split_max ( patches_64 , 4 , opts_64 )
354+ # split_max has no effect
355+ assert "@@ -1,58 +1,58 @@\n abcdefghij , h : \n -0\n +1\n , t : 1 abcdefghij , h : 0 , t : 1 abcd\n @@ -29,33 +29,33 @@\n bcdefghij , h : \n -0\n +1\n , t : 1 abcdefg\n " ==
356+ Patch . to_text ( patches_64 )
357+
358+ { text3 , _ } = Patch . apply ( patches_64 , text1 )
359+ assert text2 == text3
360+ end
287361 end
288362
289363 describe "add_padding" do
@@ -337,6 +411,7 @@ defmodule PatchTest do
337411 assert { "I am the very model of a modern major general." , [ false , false ] } == results
338412 end
339413
414+ @ tag :match_max_32
340415 test "big delete, small change" do
341416 patches =
342417 Patch . make (
@@ -353,6 +428,7 @@ defmodule PatchTest do
353428 assert { "xabcy" , [ true , true ] } == results
354429 end
355430
431+ @ tag :match_max_32
356432 test "big delete, big change 1" do
357433 patches =
358434 Patch . make (
@@ -370,6 +446,7 @@ defmodule PatchTest do
370446 [ false , true ] } == results
371447 end
372448
449+ @ tag :match_max_32
373450 test "big delete, big change 2" do
374451 patches =
375452 Patch . make (
@@ -415,6 +492,7 @@ defmodule PatchTest do
415492 assert { "test" , [ true ] } == results
416493 end
417494
495+ @ tag :match_max_32
418496 test "no side effects with major delete" do
419497 patches = Patch . make ( "The quick brown fox jumps over the lazy dog." , "Woof" )
420498 patchstr = Patch . to_text ( patches )
0 commit comments