Skip to content

Commit 7161463

Browse files
authored
fix: default lines value (#34)
* fix: default line value * Update chunk-context.test.ts.snap
1 parent 0b9dce8 commit 7161463

File tree

5 files changed

+53
-3
lines changed

5 files changed

+53
-3
lines changed

src/__fixtures__/unified

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
diff --git a/test.txt b/test.txt
2+
index 27b30e2..62944e1 100644
3+
--- a/test.txt
4+
+++ b/test.txt
5+
@@ -2,0 +3 @@ bbb
6+
+ddd

src/__tests__/__snapshots__/chunk-context.test.ts.snap

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ exports[`chunk-context parse \`chunk-context\` 1`] = `
1414
"type": "UnchangedLine",
1515
},
1616
{
17-
"content": " console.log(\"hello world\");",
17+
"content": " console.log("hello world");",
1818
"lineAfter": 5,
1919
"type": "AddedLine",
2020
},
2121
],
2222
"context": "function hello() {",
2323
"fromFileRange": {
24-
"lines": 4,
24+
"lines": 1,
2525
"start": 4,
2626
},
2727
"toFileRange": {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`unified parse \`unified 1`] = `
4+
{
5+
"files": [
6+
{
7+
"chunks": [
8+
{
9+
"changes": [
10+
{
11+
"content": "ddd",
12+
"lineAfter": 3,
13+
"type": "AddedLine",
14+
},
15+
],
16+
"context": "bbb",
17+
"fromFileRange": {
18+
"lines": 0,
19+
"start": 2,
20+
},
21+
"toFileRange": {
22+
"lines": 1,
23+
"start": 3,
24+
},
25+
"type": "Chunk",
26+
},
27+
],
28+
"path": "test.txt",
29+
"type": "ChangedFile",
30+
},
31+
],
32+
"type": "GitDiff",
33+
}
34+
`;

src/__tests__/unified.test.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { getFixture } from './test-utils';
2+
import parseGitDiff from '../parse-git-diff';
3+
4+
describe('unified', () => {
5+
const fixture = getFixture('unified');
6+
7+
it('parse `unified', () => {
8+
expect(parseGitDiff(fixture)).toMatchSnapshot();
9+
});
10+
});

src/parse-git-diff.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ function getRange(start: string, lines?: string) {
280280
const startNum = parseInt(start, 10);
281281
return {
282282
start: startNum,
283-
lines: lines === undefined ? startNum : parseInt(lines, 10),
283+
lines: lines === undefined ? 1 : parseInt(lines, 10),
284284
};
285285
}
286286

0 commit comments

Comments
 (0)