The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 03:37 UTC
| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | |
| 3 | import { parseTurnDiffFilesFromNumstat } from "./Diffs.ts"; |
| 4 | |
| 5 | describe("parseTurnDiffFilesFromNumstat", () => { |
| 6 | it("sorts files and preserves addition and deletion counts", () => { |
| 7 | const numstat = ["0\t2\tsrc/b.ts", "2\t1\ta.txt", ""].join("\0"); |
| 8 | expect(parseTurnDiffFilesFromNumstat(numstat)).toEqual([ |
| 9 | { path: "a.txt", additions: 2, deletions: 1 }, |
| 10 | { path: "src/b.ts", additions: 0, deletions: 2 }, |
| 11 | ]); |
| 12 | }); |
| 13 | |
| 14 | it("preserves both paths for renames and copies", () => { |
| 15 | const numstat = [ |
| 16 | "0\t0\t", |
| 17 | "src/old.ts", |
| 18 | "src/new.ts", |
| 19 | "2\t1\t", |
| 20 | "src/source.ts", |
| 21 | "src/copied.ts", |
| 22 | "1\t0\tother.ts", |
| 23 | "", |
| 24 | ].join("\0"); |
| 25 | |
| 26 | expect(parseTurnDiffFilesFromNumstat(numstat)).toEqual([ |
| 27 | { path: "other.ts", additions: 1, deletions: 0 }, |
| 28 | { path: "src/copied.ts", previousPath: "src/source.ts", additions: 2, deletions: 1 }, |
| 29 | { path: "src/new.ts", previousPath: "src/old.ts", additions: 0, deletions: 0 }, |
| 30 | ]); |
| 31 | }); |
| 32 | |
| 33 | it("keeps binary files and empty files with zero line changes", () => { |
| 34 | const numstat = ["-\t-\timage.png", "0\t0\tempty.txt", ""].join("\0"); |
| 35 | expect(parseTurnDiffFilesFromNumstat(numstat)).toEqual([ |
| 36 | { path: "empty.txt", additions: 0, deletions: 0 }, |
| 37 | { path: "image.png", additions: 0, deletions: 0 }, |
| 38 | ]); |
| 39 | }); |
| 40 | |
| 41 | it("preserves Unicode, tabs, line endings, and spaces in paths", () => { |
| 42 | const path = " café\tline\r\nname.txt "; |
| 43 | const numstat = `3\t2\t\0old\tname\n.txt\0${path}\0`; |
| 44 | |
| 45 | expect(parseTurnDiffFilesFromNumstat(numstat)).toEqual([ |
| 46 | { path, previousPath: "old\tname\n.txt", additions: 3, deletions: 2 }, |
| 47 | ]); |
| 48 | expect(parseTurnDiffFilesFromNumstat(`1\t0\t${path}\0`)).toEqual([ |
| 49 | { path, additions: 1, deletions: 0 }, |
| 50 | ]); |
| 51 | }); |
| 52 | }); |