-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathdiffRendering.test.ts
More file actions
55 lines (45 loc) · 1.66 KB
/
Copy pathdiffRendering.test.ts
File metadata and controls
55 lines (45 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { describe, expect, it } from "vitest";
import {
buildPatchCacheKey,
canRenderFileDiff,
MAX_RENDERABLE_DIFF_LINE_LENGTH,
} from "./diffRendering";
describe("buildPatchCacheKey", () => {
it("returns a stable cache key for identical content", () => {
const patch = "diff --git a/a.ts b/a.ts\n+console.log('hello')";
expect(buildPatchCacheKey(patch)).toBe(buildPatchCacheKey(patch));
});
it("normalizes outer whitespace before hashing", () => {
const patch = "diff --git a/a.ts b/a.ts\n+console.log('hello')";
expect(buildPatchCacheKey(`\n${patch}\n`)).toBe(buildPatchCacheKey(patch));
});
it("changes when diff content changes", () => {
const before = "diff --git a/a.ts b/a.ts\n+console.log('hello')";
const after = "diff --git a/a.ts b/a.ts\n+console.log('hello world')";
expect(buildPatchCacheKey(before)).not.toBe(buildPatchCacheKey(after));
});
it("changes when cache scope changes", () => {
const patch = "diff --git a/a.ts b/a.ts\n+console.log('hello')";
expect(buildPatchCacheKey(patch, "diff-panel:light")).not.toBe(
buildPatchCacheKey(patch, "diff-panel:dark"),
);
});
});
describe("diff render line limits", () => {
it("rejects file diffs with pathological line lengths", () => {
expect(
canRenderFileDiff({
additionLines: ["small"],
deletionLines: ["x".repeat(MAX_RENDERABLE_DIFF_LINE_LENGTH + 1)],
}),
).toBe(false);
});
it("allows file diffs within the line length limit", () => {
expect(
canRenderFileDiff({
additionLines: ["x".repeat(MAX_RENDERABLE_DIFF_LINE_LENGTH)],
deletionLines: ["small"],
}),
).toBe(true);
});
});