@@ -18,17 +18,18 @@ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
1818`
1919
2020 function makeFileContents ( ) {
21- return generate ( {
22- length : Math . floor ( Math . random ( ) * 5 ) ,
23- charset : fileCharSet ,
24- } )
21+ return (
22+ generate ( {
23+ length : Math . floor ( Math . random ( ) * 5 ) ,
24+ charset : fileCharSet ,
25+ } ) || ""
26+ )
2527 }
2628
2729 function makeFileName ( ext ?: boolean ) {
2830 const name = generate ( {
2931 length : Math . ceil ( Math . random ( ) * 12 ) ,
30- charset :
31- "abcdefghijklmnopqrstuvwxyzABCDEFGGHIJKLMNOPQRSTUVWXYZ-_0987654321" ,
32+ charset : "abcdefghijklmnopqrstuvwxyz-_0987654321" ,
3233 } )
3334
3435 return ext ? name + "." + generate ( Math . ceil ( Math . random ( ) * 4 ) ) : name
@@ -234,6 +235,8 @@ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
234235
235236 const patchFileContents = patchResult . stdout . toString ( )
236237
238+ // console.log(patchFileContents)
239+
237240 try {
238241 it ( "works forwards" , ( ) => {
239242 setWorkingFiles ( { ...testCase . cleanFiles } )
@@ -263,7 +266,15 @@ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
263266 setWorkingFiles ( { ...testCase . modifiedFiles } )
264267 const result = patch ( patchFileContents , { reverse : true } )
265268 executeEffects ( result )
266- expect ( getWorkingFiles ( ) ) . toEqual ( testCase . cleanFiles )
269+ try {
270+ expect ( getWorkingFiles ( ) ) . toEqual ( testCase . cleanFiles )
271+ } catch ( e ) {
272+ console . error ( "TEST CASE FAILED" , {
273+ testCase,
274+ workingFiles : getWorkingFiles ( ) ,
275+ } )
276+ throw e
277+ }
267278 } )
268279 } catch ( e ) {
269280 console . error ( "TEST CASE FAILED" , JSON . stringify ( testCase ) )
@@ -272,9 +283,73 @@ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
272283 } )
273284 }
274285
275- for ( let i = 0 ; i < 1 ; i ++ ) {
276- executeTest ( makeTestCase ( ) , i )
277- }
286+ // for (let i = 0; i < 100; i++) {
287+ // executeTest(makeTestCase(), i)
288+ // }
289+
290+ executeTest (
291+ {
292+ cleanFiles : {
293+ nugs : "a" ,
294+ } ,
295+ modifiedFiles : {
296+ nugs : "a\n\n" ,
297+ } ,
298+ } ,
299+ 4 ,
300+ )
301+
302+ // executeTest(
303+ // {
304+ // cleanFiles: {
305+ // b: "\n",
306+ // },
307+ // modifiedFiles: {
308+ // b: "ba\n",
309+ // },
310+ // },
311+ // 3,
312+ // )
313+
314+ // executeTest({
315+ // cleanFiles: {
316+ // "banana": "WMo^",
317+ // },
318+ // modifiedFiles: {
319+ // "banana": "\n\n",
320+ // },
321+ // }, 4)
322+
323+ // executeTest(
324+ // {
325+ // cleanFiles: {
326+ // b: "a",
327+ // },
328+ // modifiedFiles: { b: "a", c: "a\n" },
329+ // },
330+ // 4,
331+ // )
332+
333+ // executeTest(
334+ // {
335+ // cleanFiles: {
336+ // "c-qZ0Qznn1.RWOZ": "$xs\rwim\t}pJ(;£BZxc\\bg9k|zvBufcaa",
337+ // "tK/NEDQ-hff.iaQK": ";4l",
338+ // "KbYXh8-Dk3J/vcjQ.mz": "+4:",
339+ // "r6LXXaS/DO3VbFBswE6.WmHQ": "rX]bnT%j+,\t\r~xc&`lLh^\\n*-J$z<4xu",
340+ // "Fa/lQgW3c/G8LsUj-YFoS.4hoY": "NS",
341+ // },
342+ // modifiedFiles: {
343+ // "c-qZ0Qznn1.RWOZ": "$xs\rwim\t}pJ(;£BZxc\\bg9k|zvBufcaa",
344+ // "tK/NEDQ-hff.iaQK": ";4l",
345+ // "KbYXh8-Dk3J/vcjQ.mz": "+4:",
346+ // "r6LXXaS/DO3VbFBswE6.WmHQ": "",
347+ // "Fa/lQgW3c/G8LsUj-YFoS.4hoY": "NS",
348+ // wW1UMkaGn: "F",
349+ // },
350+ // },
351+ // 3,
352+ // )
278353
279354 // executeTest(
280355 // {
@@ -317,60 +392,3 @@ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
317392 // 5,
318393 // )
319394} )
320- /*
321- oh fuck
322- What's the problem ?
323- The problem is like that line endings are not being applied in one situation
324- - when the patch file is reversed by me
325- - when the clean file has a line ending but the modified file does not
326-
327- When reversed, the patch file is wrong because the same scenario manually
328- reversed is a-ok here's the bad patch file:
329-
330- ```patch
331- diff --git a/1dkfI.J b/1dkfI.J
332- index cfc60af..2d950c4 100644
333- --- a/1dkfI.J
334- +++ b/1dkfI.J
335- @@ -1,0 +1,0 @@
336- -nout
337- +lineend
338- \ No newline at end of file
339- ```
340-
341- here's the good patch file:
342-
343- ```patch
344- diff --git a/1dkfI.J b/1dkfI.J
345- index 2d950c4..cfc60af 100644
346- --- a/1dkfI.J
347- +++ b/1dkfI.J
348- @@ -1 +1 @@
349- -nout
350- \ No newline at end of file
351- +lineend
352- ```
353-
354- here's the differences:
355-
356- - the bad patch file has length 0s in the hunk header
357- That's probably not an issue, since the default value for lengths is 0
358- - The bad patch file has the \ no newline at end of file comment in the wrong place
359- But that's probably not an issue since my code ignores it
360-
361- ```patch
362- @@ -1,0 +1,0 @@
363- -nout
364- +lineend
365- \ No newline at end of file
366- ```
367-
368- here's the good patch file:
369-
370- ```patch
371- @@ -1 +1 @@
372- -nout
373- \ No newline at end of file
374- +lineend
375- ```
376- */
0 commit comments