Skip to content

Commit 9dca0a0

Browse files
authored
test(blame): enhances blame functionality testing (#111)
1 parent 0a7a680 commit 9dca0a0

File tree

1 file changed

+66
-4
lines changed

1 file changed

+66
-4
lines changed

tests/blame.spec.ts

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@ import { type BlameHunk, openRepository } from '../index';
33
import { useFixture } from './fixtures';
44

55
describe('blame', () => {
6-
it('should provide blame information with signature', async () => {
6+
it('should retrieve basic blame information', async () => {
77
const p = await useFixture('blame');
88
const repo = await openRepository(p);
99

1010
const blame = repo.blameFile('blame');
1111
const hunks = [...blame.iter()];
1212
expect(hunks.length).toBeGreaterThan(0);
13+
});
14+
15+
it('should retrieve blame hunk by line number', async () => {
16+
const p = await useFixture('blame');
17+
const repo = await openRepository(p);
18+
const blame = repo.blameFile('blame');
1319

1420
const line1Hunk = blame.getHunkByLine(1);
1521
expect(line1Hunk.finalCommitId).toBeTruthy();
@@ -20,31 +26,59 @@ describe('blame', () => {
2026
const line2Hunk = blame.getHunkByLine(2);
2127
expect(line2Hunk.finalSignature?.name).toBe('Seokju Me');
2228
expect(line2Hunk.finalSignature?.email).toBe('seokju.na@toss.im');
29+
});
30+
31+
it('should retrieve blame hunk by index', async () => {
32+
const p = await useFixture('blame');
33+
const repo = await openRepository(p);
34+
const blame = repo.blameFile('blame');
2335

2436
const hunkByIndex = blame.getHunkByIndex(0);
2537
expect(hunkByIndex.finalCommitId).toBeTruthy();
38+
});
39+
40+
it('should create blame from buffer', async () => {
41+
const p = await useFixture('blame');
42+
const repo = await openRepository(p);
43+
const blame = repo.blameFile('blame');
2644

2745
const buffer = Buffer.from('Line 1\nLine 2\nLine 3\n');
2846
const bufferBlame = blame.buffer(buffer);
2947
expect(bufferBlame.getHunkCount()).toBeGreaterThan(0);
3048
});
3149

32-
it('should handle special files and error cases', async () => {
50+
it('should handle empty files', async () => {
3351
const p = await useFixture('blame');
3452
const repo = await openRepository(p);
3553

3654
const emptyBlame = repo.blameFile('empty_file');
3755
expect(emptyBlame.getHunkCount()).toBe(1);
3856
expect(() => emptyBlame.getHunkByLine(1)).toThrow();
57+
});
58+
59+
it('should handle binary files', async () => {
60+
const p = await useFixture('blame');
61+
const repo = await openRepository(p);
3962

4063
const binaryBlame = repo.blameFile('binary_file');
4164
expect(binaryBlame.getHunkCount()).toBeGreaterThan(0);
65+
});
4266

67+
it('should throw appropriate errors for invalid inputs', async () => {
68+
const p = await useFixture('blame');
69+
const repo = await openRepository(p);
4370
const blame = repo.blameFile('blame');
71+
4472
expect(() => blame.getHunkByLine(0)).toThrow();
4573
expect(() => blame.getHunkByLine(9999)).toThrow();
4674
expect(() => blame.getHunkByIndex(9999)).toThrow();
4775
expect(() => repo.blameFile('non_existent_file')).toThrow();
76+
});
77+
78+
it('should handle special buffer content', async () => {
79+
const p = await useFixture('blame');
80+
const repo = await openRepository(p);
81+
const blame = repo.blameFile('blame');
4882

4983
const specialBuffer = Buffer.from('Line 1\nblah blah blah\nLine 3\nLine 4\n');
5084
const specialBlame = blame.buffer(specialBuffer);
@@ -55,7 +89,7 @@ describe('blame', () => {
5589
expect(zeroCommitHunk.origSignature).toBeUndefined();
5690
});
5791

58-
it('should support blame options', async () => {
92+
it('should support line-specific blame options', async () => {
5993
const p = await useFixture('blame');
6094
const repo = await openRepository(p);
6195

@@ -64,12 +98,22 @@ describe('blame', () => {
6498
const hunk = lineBlame.getHunkByIndex(0);
6599
expect(hunk.finalStartLineNumber).toBe(2);
66100
expect(hunk.finalSignature?.name).toBe('Seokju Me');
101+
});
102+
103+
it('should support range-specific blame options', async () => {
104+
const p = await useFixture('blame');
105+
const repo = await openRepository(p);
67106

68107
const rangeBlame = repo.blameFile('blame', { minLine: 1, maxLine: 3 });
69108
const rangeHunks = [...rangeBlame.iter()];
70109
expect(rangeHunks.length).toBeGreaterThan(0);
71110
expect(rangeHunks.length).toBeLessThanOrEqual(3);
72111
expect(() => rangeBlame.getHunkByLine(4)).toThrow();
112+
});
113+
114+
it('should support advanced blame options', async () => {
115+
const p = await useFixture('blame');
116+
const repo = await openRepository(p);
73117

74118
const advancedBlame = repo.blameFile('blame', {
75119
minLine: 1,
@@ -82,19 +126,37 @@ describe('blame', () => {
82126
expect(advancedBlame.getHunkCount()).toBeGreaterThan(0);
83127
});
84128

85-
it('should support additional methods for working with hunks', async () => {
129+
it('should check if blame is empty', async () => {
86130
const p = await useFixture('blame');
87131
const repo = await openRepository(p);
88132
const blame = repo.blameFile('blame');
89133

90134
expect(blame.isEmpty()).toBe(false);
135+
});
136+
137+
it('should create blame from empty buffer', async () => {
138+
const p = await useFixture('blame');
139+
const repo = await openRepository(p);
140+
const blame = repo.blameFile('blame');
91141

92142
const buffer = Buffer.from(' ');
93143
const emptyBlame = blame.buffer(buffer);
94144
expect(emptyBlame.getHunkCount()).toBeGreaterThan(0);
145+
});
146+
147+
it('should iterate blame hunks by line', async () => {
148+
const p = await useFixture('blame');
149+
const repo = await openRepository(p);
150+
const blame = repo.blameFile('blame');
95151

96152
const lineHunks = [...blame.iterByLine()];
97153
expect(lineHunks.length).toBeGreaterThan(0);
154+
});
155+
156+
it('should iterate all blame hunks', async () => {
157+
const p = await useFixture('blame');
158+
const repo = await openRepository(p);
159+
const blame = repo.blameFile('blame');
98160

99161
const collectedHunks: BlameHunk[] = [...blame.iter()];
100162
expect(collectedHunks.length).toBe(blame.getHunkCount());

0 commit comments

Comments
 (0)