Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/patch/__snapshots__/parse.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`the patch parser can handle files with CRLF line breaks 1`] = `
Array [
Object {
"lines": Array [
"this is a new file
",
],
"mode": 420,
"noNewlineAtEndOfFile": false,
"path": "banana.ts",
"type": "file creation",
},
]
`;

exports[`the patch parser works for a simple case 1`] = `
Array [
Object {
Expand Down
12 changes: 12 additions & 0 deletions src/patch/parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ index 2de83dd..842652c 100644
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")

describe("the patch parser", () => {
it("works for a simple case", () => {
expect(parsePatch(patch)).toMatchSnapshot()
Expand All @@ -105,4 +114,7 @@ describe("the patch parser", () => {
it("is OK when blank lines are accidentally created", () => {
expect(parsePatch(accidentalBlankLine)).toEqual(parsePatch(patch))
})
it(`can handle files with CRLF line breaks`, () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strictly speaking, I could've written a more focused test that does

expect(parsePatch(crlfLineBreaks)[0].type).toBe("file creation")

Let me know if you'd prefer that instead of a snapshot test

expect(parsePatch(crlfLineBreaks)).toMatchSnapshot()
})
})
2 changes: 1 addition & 1 deletion src/patch/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ class PatchParser {
}

private parseFileModification() {
const startPath = this.currentLine.slice("--- ".length)
const startPath = this.currentLine.trim().slice("--- ".length)
Copy link
Contributor Author

@NMinhNguyen NMinhNguyen Oct 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if there's any implications from using .trim() as opposed to trimming from the end e.g.

const trimEnd = str => str.replace(/\s+$/, '')

this.nextLine()
const endPath = this.currentLine.trim().slice("--- ".length)
this.nextLine()
Expand Down