Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

Diffs.test.ts

68 lines1.7 KB

1import { describe, expect, it } from "vitest";
2​
3import { parseTurnDiffFilesFromUnifiedDiff } from "./Diffs.ts";
4​
5describe("parseTurnDiffFilesFromUnifiedDiff", () => {
6 it("returns empty list for empty diff", () => {
7 expect(parseTurnDiffFilesFromUnifiedDiff("")).toEqual([]);
8 });
9​
10 it("parses per-file additions and deletions", () => {
11 const diff = [
12 "diff --git a/a.txt b/a.txt",
13 "index 1111111..2222222 100644",
14 "--- a/a.txt",
15 "+++ b/a.txt",
16 "@@ -1,2 +1,3 @@",
17 " one",
18 "-two",
19 "+two updated",
20 "+three",
21 "diff --git a/src/b.ts b/src/b.ts",
22 "index 3333333..4444444 100644",
23 "--- a/src/b.ts",
24 "+++ b/src/b.ts",
25 "@@ -3,2 +3,0 @@",
26 "-old",
27 "-stale",
28 "",
29 ].join("\n");
30​
31 expect(parseTurnDiffFilesFromUnifiedDiff(diff)).toEqual([
32 { path: "a.txt", additions: 2, deletions: 1 },
33 { path: "src/b.ts", additions: 0, deletions: 2 },
34 ]);
35 });
36​
37 it("parses rename-only diffs with zero line changes", () => {
38 const diff = [
39 "diff --git a/src/old.ts b/src/new.ts",
40 "similarity index 100%",
41 "rename from src/old.ts",
42 "rename to src/new.ts",
43 "",
44 ].join("\n");
45​
46 expect(parseTurnDiffFilesFromUnifiedDiff(diff)).toEqual([
47 { path: "src/new.ts", additions: 0, deletions: 0 },
48 ]);
49 });
50​
51 it("normalizes CRLF input before parsing", () => {
52 const diff = [
53 "diff --git a/a.txt b/a.txt",
54 "index 1111111..2222222 100644",
55 "--- a/a.txt",
56 "+++ b/a.txt",
57 "@@ -1 +1,2 @@",
58 "-one",
59 "+one updated",
60 "+two",
61 "",
62 ].join("\r\n");
63​
64 expect(parseTurnDiffFilesFromUnifiedDiff(diff)).toEqual([
65 { path: "a.txt", additions: 2, deletions: 1 },
66 ]);
67 });
68});