This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { parseDiffOutput, countDiffStats } from '../../src/utils/diff-utils';
|
import { parseDiffOutput, countDiffStats } from '../../src/utils/git-utils';
|
||||||
|
|
||||||
describe('parseDiffOutput', () => {
|
describe('parseDiffOutput', () => {
|
||||||
it('should parse empty diff', () => {
|
it('should parse empty diff', () => {
|
||||||
@@ -7,81 +7,57 @@ describe('parseDiffOutput', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should parse diff with one file', () => {
|
it('should parse diff with one file', () => {
|
||||||
const diffOutput = `diff --git a/test.ts b/test.ts
|
const diff = `diff --git a/test.ts b/test.ts
|
||||||
index 1234567..89abcdef 100644
|
index 1234567..2345678 100644
|
||||||
--- a/test.ts
|
--- a/test.ts
|
||||||
+++ b/test.ts
|
+++ b/test.ts
|
||||||
@@ -1,3 +1,4 @@
|
@@ -1,3 +1,3 @@
|
||||||
+import { useState } from 'react';
|
-const a = 1;
|
||||||
function App() {
|
+const a = 2;
|
||||||
return <div>Hello</div>;
|
const b = 3;
|
||||||
}
|
|
||||||
@@ -5,3 +6,4 @@ function App() {
|
|
||||||
return <div>Hello</div>;
|
|
||||||
}
|
|
||||||
+// comment
|
|
||||||
`;
|
`;
|
||||||
|
const result = parseDiffOutput(diff);
|
||||||
const result = parseDiffOutput(diffOutput);
|
|
||||||
expect(result.length).toBe(1);
|
expect(result.length).toBe(1);
|
||||||
expect(result[0].file).toBe('test.ts');
|
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', () => {
|
it('should parse diff with multiple files', () => {
|
||||||
const diffOutput = `diff --git a/file1.ts b/file1.ts
|
const diff = `diff --git a/test.ts b/test.ts
|
||||||
index 1234567..89abcdef 100644
|
index 1234567..2345678 100644
|
||||||
--- a/file1.ts
|
--- a/test.ts
|
||||||
+++ b/file1.ts
|
+++ b/test.ts
|
||||||
@@ -1,2 +1,3 @@
|
@@ -1,3 +1,3 @@
|
||||||
+const x = 1;
|
-const a = 1;
|
||||||
line 1
|
+const a = 2;
|
||||||
|
const b = 3;
|
||||||
diff --git a/file2.ts b/file2.ts
|
diff --git a/other.ts b/other.ts
|
||||||
index abcdef1..2345678 100644
|
index 1234567..2345678 100644
|
||||||
--- a/file2.ts
|
--- a/other.ts
|
||||||
+++ b/file2.ts
|
+++ b/other.ts
|
||||||
@@ -1,2 +1,2 @@
|
@@ -1,2 +1,2 @@
|
||||||
-old line
|
-const x = 1;
|
||||||
+new line
|
+const x = 2;
|
||||||
line 2
|
|
||||||
`;
|
`;
|
||||||
|
const result = parseDiffOutput(diff);
|
||||||
const result = parseDiffOutput(diffOutput);
|
|
||||||
expect(result.length).toBe(2);
|
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', () => {
|
describe('countDiffStats', () => {
|
||||||
it('should count additions and deletions', () => {
|
it('should count additions and deletions', () => {
|
||||||
const diffContent = `diff --git a/test.ts b/test.ts
|
const diff = `diff --git a/test.ts b/test.ts
|
||||||
@@ -1,3 +1,4 @@
|
+const a = 1;
|
||||||
+import { useState } from 'react';
|
-const b = 2;
|
||||||
function App() {
|
+const c = 3;
|
||||||
return <div>Hello</div>;
|
|
||||||
}
|
|
||||||
@@ -5,3 +6,4 @@ function App() {
|
|
||||||
return <div>Hello</div>;
|
|
||||||
}
|
|
||||||
+// comment
|
|
||||||
`;
|
`;
|
||||||
|
const result = countDiffStats(diff);
|
||||||
const stats = countDiffStats(diffContent);
|
expect(result.additions).toBe(2);
|
||||||
expect(stats.additions).toBe(2);
|
expect(result.deletions).toBe(1);
|
||||||
expect(stats.deletions).toBe(0);
|
|
||||||
expect(stats.files).toBe(1);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle empty diff', () => {
|
it('should handle empty diff', () => {
|
||||||
const stats = countDiffStats('');
|
const result = countDiffStats('');
|
||||||
expect(stats.additions).toBe(0);
|
expect(result.additions).toBe(0);
|
||||||
expect(stats.deletions).toBe(0);
|
expect(result.deletions).toBe(0);
|
||||||
expect(stats.files).toBe(1);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user