Skip to content

Commit

Permalink
fix: default line value
Browse files Browse the repository at this point in the history
  • Loading branch information
yeonjuan committed Dec 2, 2024
1 parent 0b9dce8 commit b936fc7
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/__fixtures__/unified
Original file line number Diff line number Diff line change
@@ -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
34 changes: 34 additions & 0 deletions src/__tests__/__snapshots__/unified.test.ts.snap
Original file line number Diff line number Diff line change
@@ -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",
}
`;
10 changes: 10 additions & 0 deletions src/__tests__/unified.test.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
2 changes: 1 addition & 1 deletion src/parse-git-diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};
}

Expand Down

0 comments on commit b936fc7

Please sign in to comment.