64 lines
1.5 KiB
TypeScript
64 lines
1.5 KiB
TypeScript
import { parseDiffOutput, countDiffStats } from '../../src/utils/git-utils';
|
|
|
|
describe('parseDiffOutput', () => {
|
|
it('should parse empty diff', () => {
|
|
const result = parseDiffOutput('');
|
|
expect(result).toEqual([]);
|
|
});
|
|
|
|
it('should parse diff with one file', () => {
|
|
const diff = `diff --git a/test.ts b/test.ts
|
|
index 1234567..2345678 100644
|
|
--- a/test.ts
|
|
+++ b/test.ts
|
|
@@ -1,3 +1,3 @@
|
|
-const a = 1;
|
|
+const a = 2;
|
|
const b = 3;
|
|
`;
|
|
const result = parseDiffOutput(diff);
|
|
expect(result.length).toBe(1);
|
|
expect(result[0].file).toBe('test.ts');
|
|
});
|
|
|
|
it('should parse diff with multiple files', () => {
|
|
const diff = `diff --git a/test.ts b/test.ts
|
|
index 1234567..2345678 100644
|
|
--- a/test.ts
|
|
+++ b/test.ts
|
|
@@ -1,3 +1,3 @@
|
|
-const a = 1;
|
|
+const a = 2;
|
|
const b = 3;
|
|
diff --git a/other.ts b/other.ts
|
|
index 1234567..2345678 100644
|
|
--- a/other.ts
|
|
+++ b/other.ts
|
|
@@ -1,2 +1,2 @@
|
|
-const x = 1;
|
|
+const x = 2;
|
|
`;
|
|
const result = parseDiffOutput(diff);
|
|
expect(result.length).toBe(2);
|
|
});
|
|
});
|
|
|
|
describe('countDiffStats', () => {
|
|
it('should count additions and deletions', () => {
|
|
const diff = `diff --git a/test.ts b/test.ts
|
|
+const a = 1;
|
|
-const b = 2;
|
|
+const c = 3;
|
|
`;
|
|
const result = countDiffStats(diff);
|
|
expect(result.additions).toBe(2);
|
|
expect(result.deletions).toBe(1);
|
|
});
|
|
|
|
it('should handle empty diff', () => {
|
|
const result = countDiffStats('');
|
|
expect(result.additions).toBe(0);
|
|
expect(result.deletions).toBe(0);
|
|
});
|
|
});
|