88 lines
2.1 KiB
TypeScript
88 lines
2.1 KiB
TypeScript
import { parseDiffOutput, countDiffStats } from '../../src/utils/diff-utils';
|
|
|
|
describe('parseDiffOutput', () => {
|
|
it('should parse empty diff', () => {
|
|
const result = parseDiffOutput('');
|
|
expect(result).toEqual([]);
|
|
});
|
|
|
|
it('should parse diff with one file', () => {
|
|
const diffOutput = `diff --git a/test.ts b/test.ts
|
|
index 1234567..89abcdef 100644
|
|
--- a/test.ts
|
|
+++ b/test.ts
|
|
@@ -1,3 +1,4 @@
|
|
+import { useState } from 'react';
|
|
function App() {
|
|
return <div>Hello</div>;
|
|
}
|
|
@@ -5,3 +6,4 @@ function App() {
|
|
return <div>Hello</div>;
|
|
}
|
|
+// comment
|
|
`;
|
|
|
|
const result = parseDiffOutput(diffOutput);
|
|
expect(result.length).toBe(1);
|
|
expect(result[0].file).toBe('test.ts');
|
|
expect(result[0].additions).toBe(2);
|
|
expect(result[0].deletions).toBe(0);
|
|
});
|
|
|
|
it('should parse diff with multiple files', () => {
|
|
const diffOutput = `diff --git a/file1.ts b/file1.ts
|
|
index 1234567..89abcdef 100644
|
|
--- a/file1.ts
|
|
+++ b/file1.ts
|
|
@@ -1,2 +1,3 @@
|
|
+const x = 1;
|
|
line 1
|
|
|
|
diff --git a/file2.ts b/file2.ts
|
|
index abcdef1..2345678 100644
|
|
--- a/file2.ts
|
|
+++ b/file2.ts
|
|
@@ -1,2 +1,2 @@
|
|
-old line
|
|
+new line
|
|
line 2
|
|
`;
|
|
|
|
const result = parseDiffOutput(diffOutput);
|
|
expect(result.length).toBe(2);
|
|
expect(result[0].file).toBe('file1.ts');
|
|
expect(result[1].file).toBe('file2.ts');
|
|
expect(result[0].additions).toBe(1);
|
|
expect(result[1].additions).toBe(1);
|
|
expect(result[1].deletions).toBe(1);
|
|
});
|
|
});
|
|
|
|
describe('countDiffStats', () => {
|
|
it('should count additions and deletions', () => {
|
|
const diffContent = `diff --git a/test.ts b/test.ts
|
|
@@ -1,3 +1,4 @@
|
|
+import { useState } from 'react';
|
|
function App() {
|
|
return <div>Hello</div>;
|
|
}
|
|
@@ -5,3 +6,4 @@ function App() {
|
|
return <div>Hello</div>;
|
|
}
|
|
+// comment
|
|
`;
|
|
|
|
const stats = countDiffStats(diffContent);
|
|
expect(stats.additions).toBe(2);
|
|
expect(stats.deletions).toBe(0);
|
|
expect(stats.files).toBe(1);
|
|
});
|
|
|
|
it('should handle empty diff', () => {
|
|
const stats = countDiffStats('');
|
|
expect(stats.additions).toBe(0);
|
|
expect(stats.deletions).toBe(0);
|
|
expect(stats.files).toBe(1);
|
|
});
|
|
});
|