diff --git a/src/__fixtures__/unified b/src/__fixtures__/unified new file mode 100644 index 0000000..9c7e37f --- /dev/null +++ b/src/__fixtures__/unified @@ -0,0 +1,6 @@ +diff --git a/test.txt b/test.txt +index 27b30e2..62944e1 100644 +--- a/test.txt ++++ b/test.txt +@@ -2,0 +3 @@ bbb ++ddd \ No newline at end of file diff --git a/src/__tests__/__snapshots__/chunk-context.test.ts.snap b/src/__tests__/__snapshots__/chunk-context.test.ts.snap index f2fa843..85ef29e 100644 --- a/src/__tests__/__snapshots__/chunk-context.test.ts.snap +++ b/src/__tests__/__snapshots__/chunk-context.test.ts.snap @@ -14,14 +14,14 @@ exports[`chunk-context parse \`chunk-context\` 1`] = ` "type": "UnchangedLine", }, { - "content": " console.log(\"hello world\");", + "content": " console.log("hello world");", "lineAfter": 5, "type": "AddedLine", }, ], "context": "function hello() {", "fromFileRange": { - "lines": 4, + "lines": 1, "start": 4, }, "toFileRange": { diff --git a/src/__tests__/__snapshots__/unified.test.ts.snap b/src/__tests__/__snapshots__/unified.test.ts.snap new file mode 100644 index 0000000..ffe28b1 --- /dev/null +++ b/src/__tests__/__snapshots__/unified.test.ts.snap @@ -0,0 +1,34 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`unified parse \`unified 1`] = ` +{ + "files": [ + { + "chunks": [ + { + "changes": [ + { + "content": "ddd", + "lineAfter": 3, + "type": "AddedLine", + }, + ], + "context": "bbb", + "fromFileRange": { + "lines": 0, + "start": 2, + }, + "toFileRange": { + "lines": 1, + "start": 3, + }, + "type": "Chunk", + }, + ], + "path": "test.txt", + "type": "ChangedFile", + }, + ], + "type": "GitDiff", +} +`; diff --git a/src/__tests__/unified.test.ts b/src/__tests__/unified.test.ts new file mode 100644 index 0000000..87e5c54 --- /dev/null +++ b/src/__tests__/unified.test.ts @@ -0,0 +1,10 @@ +import { getFixture } from './test-utils'; +import parseGitDiff from '../parse-git-diff'; + +describe('unified', () => { + const fixture = getFixture('unified'); + + it('parse `unified', () => { + expect(parseGitDiff(fixture)).toMatchSnapshot(); + }); +}); diff --git a/src/parse-git-diff.ts b/src/parse-git-diff.ts index 4c74fce..1075956 100644 --- a/src/parse-git-diff.ts +++ b/src/parse-git-diff.ts @@ -280,7 +280,7 @@ function getRange(start: string, lines?: string) { const startNum = parseInt(start, 10); return { start: startNum, - lines: lines === undefined ? startNum : parseInt(lines, 10), + lines: lines === undefined ? 1 : parseInt(lines, 10), }; }