1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
import {parsePatchFile} from '../sources/tools/parse';
const patch = `diff --git a/banana.ts b/banana.ts
index 2de83dd..842652c 100644
--- a/banana.ts
+++ b/banana.ts
@@ -1,5 +1,5 @@
this
is
-a
+
file
`;
const invalidHeaders1 = `diff --git a/banana.ts b/banana.ts
index 2de83dd..842652c 100644
--- a/banana.ts
+++ b/banana.ts
@@ -1,5 +1,4 @@
this
is
-a
+
file
`;
const invalidHeaders2 = `diff --git a/banana.ts b/banana.ts
index 2de83dd..842652c 100644
--- a/banana.ts
+++ b/banana.ts
@@ -1,4 +1,5 @@
this
is
-a
+
file
`;
const invalidHeaders3 = `diff --git a/banana.ts b/banana.ts
index 2de83dd..842652c 100644
--- a/banana.ts
+++ b/banana.ts
@@ -1,0 +1,5 @@
this
is
-a
+
file
`;
const invalidHeaders4 = `diff --git a/banana.ts b/banana.ts
index 2de83dd..842652c 100644
--- a/banana.ts
+++ b/banana.ts
@@ -1,5 +1,0 @@
this
is
-a
+
file
`;
const invalidHeaders5 = `diff --git a/banana.ts b/banana.ts
index 2de83dd..842652c 100644
--- a/banana.ts
+++ b/banana.ts
@@ -1,5 +1,5@@
this
is
-a
+
file
`;
const accidentalBlankLine = `diff --git a/banana.ts b/banana.ts
index 2de83dd..842652c 100644
--- a/banana.ts
+++ b/banana.ts
@@ -1,5 +1,5 @@
this
is
-a
+
file
`;
const crlfLineBreaks = `diff --git a/banana.ts b/banana.ts
new file mode 100644
index 0000000..3e1267f
--- /dev/null
+++ b/banana.ts
@@ -0,0 +1 @@
+this is a new file
`.replace(/\n/g, `\r\n`);
const modeChangeAndModifyAndRename = `diff --git a/numbers.txt b/banana.txt
old mode 100644
new mode 100755
similarity index 96%
rename from numbers.txt
rename to banana.txt
index fbf1785..92d2c5f
--- a/numbers.txt
+++ b/banana.txt
@@ -1,4 +1,4 @@
-one
+ne
two
`;
describe(`parsepatchFile`, () => {
it(`works for a simple case`, () => {
expect(parsePatchFile(patch)).toMatchSnapshot();
});
it(`fails when the patch file has invalid headers`, () => {
expect(() => parsePatchFile(invalidHeaders1)).toThrow();
expect(() => parsePatchFile(invalidHeaders2)).toThrow();
expect(() => parsePatchFile(invalidHeaders3)).toThrow();
expect(() => parsePatchFile(invalidHeaders4)).toThrow();
expect(() => parsePatchFile(invalidHeaders5)).toThrow();
});
it(`is OK when blank lines are accidentally created`, () => {
expect(parsePatchFile(accidentalBlankLine)).toEqual(parsePatchFile(patch));
});
it(`can handle files with CRLF line breaks`, () => {
expect(parsePatchFile(crlfLineBreaks)).toMatchSnapshot();
});
it(`works`, () => {
expect(parsePatchFile(modeChangeAndModifyAndRename)).toMatchSnapshot();
expect(parsePatchFile(accidentalBlankLine)).toMatchSnapshot();
expect(parsePatchFile(modeChangeAndModifyAndRename)).toMatchSnapshot();
});
});
|