From b936fc7d814a7995507c9b4d78413e0a2973a066 Mon Sep 17 00:00:00 2001 From: YeonJuan Date: Mon, 2 Dec 2024 20:51:37 +0900 Subject: [PATCH] fix: default line value --- src/__fixtures__/unified | 6 ++++ .../__snapshots__/unified.test.ts.snap | 34 +++++++++++++++++++ src/__tests__/unified.test.ts | 10 ++++++ src/parse-git-diff.ts | 2 +- 4 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 src/__fixtures__/unified create mode 100644 src/__tests__/__snapshots__/unified.test.ts.snap create mode 100644 src/__tests__/unified.test.ts 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__/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), }; }