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, 04:45 UTC
| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | |
| 3 | import { reviewPositionInPatch } from "./pullRequestReviewPosition.ts"; |
| 4 | |
| 5 | const patch = [ |
| 6 | "diff --git a/src/a.ts b/src/a.ts", |
| 7 | "--- a/src/a.ts", |
| 8 | "+++ b/src/a.ts", |
| 9 | "@@ -10,3 +10,3 @@ function a() {", |
| 10 | " kept", |
| 11 | "-removed", |
| 12 | "+added", |
| 13 | " also kept", |
| 14 | "diff --git a/gone.ts b/gone.ts", |
| 15 | "--- a/gone.ts", |
| 16 | "+++ /dev/null", |
| 17 | "@@ -1 +0,0 @@", |
| 18 | "-gone", |
| 19 | "diff --git a/other.ts b/other.ts", |
| 20 | "--- a/other.ts", |
| 21 | "+++ b/other.ts", |
| 22 | "@@ -1 +1,2 @@", |
| 23 | " first", |
| 24 | // An added line reading `++ b/src/a.ts`, not a header for src/a.ts. |
| 25 | "+++ b/src/a.ts", |
| 26 | "@@ -20 +21 @@", |
| 27 | " later", |
| 28 | ].join("\n"); |
| 29 | |
| 30 | describe("reviewPositionInPatch", () => { |
| 31 | it.each([ |
| 32 | ["an added line", "src/a.ts", 11, "new", { kind: "added", newLine: 11 }], |
| 33 | ["a removed line", "src/a.ts", 11, "old", { kind: "deleted", oldLine: 11 }], |
| 34 | [ |
| 35 | "a kept line by its head number", |
| 36 | "src/a.ts", |
| 37 | 12, |
| 38 | "new", |
| 39 | { kind: "context", oldLine: 12, newLine: 12, side: "right" }, |
| 40 | ], |
| 41 | [ |
| 42 | "a kept line by its base number", |
| 43 | "src/a.ts", |
| 44 | 10, |
| 45 | "old", |
| 46 | { kind: "context", oldLine: 10, newLine: 10, side: "left" }, |
| 47 | ], |
| 48 | ["a deleted file's line", "gone.ts", 1, "old", { kind: "deleted", oldLine: 1 }], |
| 49 | ["a line outside every hunk", "src/a.ts", 30, "new", null], |
| 50 | ["no line from a later file's header-like source", "src/a.ts", 21, "new", null], |
| 51 | ["a line of a file the patch lacks", "src/b.ts", 11, "new", null], |
| 52 | ] as const)("places %s", (_name, path, line, side, expected) => { |
| 53 | expect(reviewPositionInPatch(patch, path, line, side)).toEqual(expected); |
| 54 | }); |
| 55 | }); |