@@ -80,7 +80,10 @@ pub fn diff(
8080 /// a faster slightly less optimal diff.
8181 check_lines : bool ,
8282) DiffError ! DiffList {
83- const deadline = @intCast (u64 , std .time .microTimestamp ()) + dmp .diff_timeout ;
83+ const deadline = if (dmp .diff_timeout == 0 )
84+ std .math .maxInt (u64 )
85+ else
86+ @intCast (u64 , std .time .microTimestamp ()) + dmp .diff_timeout ;
8487 return dmp .diffInternal (allocator , before , after , check_lines , deadline );
8588}
8689
@@ -1945,60 +1948,60 @@ test diff {
19451948 var diffs = DiffList {};
19461949 defer diffs .deinit (arena .allocator ());
19471950 var this = DiffMatchPatch {};
1948- try testing .expectEqualDeep (diffs , try this .diff (arena .allocator (), "" , "" , false )); // diff: Null case.
1951+ try testing .expectEqualDeep (diffs . items , ( try this .diff (arena .allocator (), "" , "" , false )). items ); // diff: Null case.
19491952
19501953 diffs .items .len = 0 ;
19511954 try diffs .appendSlice (arena .allocator (), &.{Diff .init (.equal , "abc" )});
1952- try testing .expectEqualDeep (diffs , try this .diff (arena .allocator (), "abc" , "abc" , false )); // diff: Equality.
1955+ try testing .expectEqualDeep (diffs . items , ( try this .diff (arena .allocator (), "abc" , "abc" , false )). items ); // diff: Equality.
19531956
19541957 diffs .items .len = 0 ;
19551958 try diffs .appendSlice (arena .allocator (), &.{ Diff .init (.equal , "ab" ), Diff .init (.insert , "123" ), Diff .init (.equal , "c" ) });
1956- try testing .expectEqualDeep (diffs , try this .diff (arena .allocator (), "abc" , "ab123c" , false )); // diff: Simple insertion.
1959+ try testing .expectEqualDeep (diffs . items , ( try this .diff (arena .allocator (), "abc" , "ab123c" , false )). items ); // diff: Simple insertion.
19571960
19581961 diffs .items .len = 0 ;
19591962 try diffs .appendSlice (arena .allocator (), &.{ Diff .init (.equal , "a" ), Diff .init (.delete , "123" ), Diff .init (.equal , "bc" ) });
1960- try testing .expectEqualDeep (diffs , try this .diff (arena .allocator (), "a123bc" , "abc" , false )); // diff: Simple deletion.
1963+ try testing .expectEqualDeep (diffs . items , ( try this .diff (arena .allocator (), "a123bc" , "abc" , false )). items ); // diff: Simple deletion.
19611964
19621965 diffs .items .len = 0 ;
19631966 try diffs .appendSlice (arena .allocator (), &.{ Diff .init (.equal , "a" ), Diff .init (.insert , "123" ), Diff .init (.equal , "b" ), Diff .init (.insert , "456" ), Diff .init (.equal , "c" ) });
1964- try testing .expectEqualDeep (diffs , try this .diff (arena .allocator (), "abc" , "a123b456c" , false )); // diff: Two insertions.
1967+ try testing .expectEqualDeep (diffs . items , ( try this .diff (arena .allocator (), "abc" , "a123b456c" , false )). items ); // diff: Two insertions.
19651968
19661969 diffs .items .len = 0 ;
19671970 try diffs .appendSlice (arena .allocator (), &.{ Diff .init (.equal , "a" ), Diff .init (.delete , "123" ), Diff .init (.equal , "b" ), Diff .init (.delete , "456" ), Diff .init (.equal , "c" ) });
1968- try testing .expectEqualDeep (diffs , try this .diff (arena .allocator (), "a123b456c" , "abc" , false )); // diff: Two deletions.
1971+ try testing .expectEqualDeep (diffs . items , ( try this .diff (arena .allocator (), "a123b456c" , "abc" , false )). items ); // diff: Two deletions.
19691972
19701973 // Perform a real diff.
19711974 // Switch off the timeout.
19721975 this .diff_timeout = 0 ;
19731976 diffs .items .len = 0 ;
19741977 try diffs .appendSlice (arena .allocator (), &.{ Diff .init (.delete , "a" ), Diff .init (.insert , "b" ) });
1975- try testing .expectEqualDeep (diffs , try this .diff (arena .allocator (), "a" , "b" , false )); // diff: Simple case #1.
1978+ try testing .expectEqualDeep (diffs . items , ( try this .diff (arena .allocator (), "a" , "b" , false )). items ); // diff: Simple case #1.
19761979
19771980 diffs .items .len = 0 ;
19781981 try diffs .appendSlice (arena .allocator (), &.{ Diff .init (.delete , "Apple" ), Diff .init (.insert , "Banana" ), Diff .init (.equal , "s are a" ), Diff .init (.insert , "lso" ), Diff .init (.equal , " fruit." ) });
1979- try testing .expectEqualDeep (diffs , try this .diff (arena .allocator (), "Apples are a fruit." , "Bananas are also fruit." , false )); // diff: Simple case #2.
1982+ try testing .expectEqualDeep (diffs . items , ( try this .diff (arena .allocator (), "Apples are a fruit." , "Bananas are also fruit." , false )). items ); // diff: Simple case #2.
19801983
19811984 diffs .items .len = 0 ;
19821985 try diffs .appendSlice (arena .allocator (), &.{ Diff .init (.delete , "a" ), Diff .init (.insert , "\u{0680} " ), Diff .init (.equal , "x" ), Diff .init (.delete , "\t " ), Diff .init (.insert , "\x00 " ) });
1983- try testing .expectEqualDeep (diffs , try this .diff (arena .allocator (), "ax\t " , "\u{0680} x\x00 " , false )); // diff: Simple case #3.
1986+ try testing .expectEqualDeep (diffs . items , ( try this .diff (arena .allocator (), "ax\t " , "\u{0680} x\x00 " , false )). items ); // diff: Simple case #3.
19841987
19851988 diffs .items .len = 0 ;
19861989 try diffs .appendSlice (arena .allocator (), &.{ Diff .init (.delete , "1" ), Diff .init (.equal , "a" ), Diff .init (.delete , "y" ), Diff .init (.equal , "b" ), Diff .init (.delete , "2" ), Diff .init (.insert , "xab" ) });
1987- try testing .expectEqualDeep (diffs , try this .diff (arena .allocator (), "1ayb2" , "abxab" , false )); // diff: Overlap #1.
1990+ try testing .expectEqualDeep (diffs . items , ( try this .diff (arena .allocator (), "1ayb2" , "abxab" , false )). items ); // diff: Overlap #1.
19881991
19891992 diffs .items .len = 0 ;
19901993 try diffs .appendSlice (arena .allocator (), &.{ Diff .init (.insert , "xaxcx" ), Diff .init (.equal , "abc" ), Diff .init (.delete , "y" ) });
1991- try testing .expectEqualDeep (diffs , try this .diff (arena .allocator (), "abcy" , "xaxcxabc" , false )); // diff: Overlap #2.
1994+ try testing .expectEqualDeep (diffs . items , ( try this .diff (arena .allocator (), "abcy" , "xaxcxabc" , false )). items ); // diff: Overlap #2.
19921995
19931996 diffs .items .len = 0 ;
19941997 try diffs .appendSlice (arena .allocator (), &.{ Diff .init (.delete , "ABCD" ), Diff .init (.equal , "a" ), Diff .init (.delete , "=" ), Diff .init (.insert , "-" ), Diff .init (.equal , "bcd" ), Diff .init (.delete , "=" ), Diff .init (.insert , "-" ), Diff .init (.equal , "efghijklmnopqrs" ), Diff .init (.delete , "EFGHIJKLMNOefg" ) });
1995- try testing .expectEqualDeep (diffs , try this .diff (arena .allocator (), "ABCDa=bcd=efghijklmnopqrsEFGHIJKLMNOefg" , "a-bcd-efghijklmnopqrs" , false )); // diff: Overlap #3.
1998+ try testing .expectEqualDeep (diffs . items , ( try this .diff (arena .allocator (), "ABCDa=bcd=efghijklmnopqrsEFGHIJKLMNOefg" , "a-bcd-efghijklmnopqrs" , false )). items ); // diff: Overlap #3.
19961999
19972000 diffs .items .len = 0 ;
19982001 try diffs .appendSlice (arena .allocator (), &.{ Diff .init (.insert , " " ), Diff .init (.equal , "a" ), Diff .init (.insert , "nd" ), Diff .init (.equal , " [[Pennsylvania]]" ), Diff .init (.delete , " and [[New" ) });
1999- try testing .expectEqualDeep (diffs , try this .diff (arena .allocator (), "a [[Pennsylvania]] and [[New" , " and [[Pennsylvania]]" , false )); // diff: Large equality.
2002+ try testing .expectEqualDeep (diffs . items , ( try this .diff (arena .allocator (), "a [[Pennsylvania]] and [[New" , " and [[Pennsylvania]]" , false )). items ); // diff: Large equality.
20002003
2001- this .diff_timeout = 100 * std .time .ms_per_s ; // 100ms
2004+ this .diff_timeout = 100 * std .time .ns_per_ms ; // 100ms
20022005 // Increase the text lengths by 1024 times to ensure a timeout.
20032006 {
20042007 const a = "`Twas brillig, and the slithy toves\n Did gyre and gimble in the wabe:\n All mimsy were the borogoves,\n And the mome raths outgrabe.\n " ** 10 ;
0 commit comments