Buckets:
| // Copyright (c) 2026 the Zuke contributors | |
| // SPDX-License-Identifier: MIT | |
| import { assertEquals } from "../../core/tests/_assert.ts"; | |
| import { diffToSuggestions } from "../src/diff_suggest.ts"; | |
| const PRELUDE = "note"; | |
| Deno.test("a modification hunk becomes a replacement suggestion", () => { | |
| const diff = [ | |
| "diff --git a/zuke.ts b/zuke.ts", | |
| "--- a/zuke.ts", | |
| "+++ b/zuke.ts", | |
| "@@ -45,3 +45,3 @@", | |
| " context", | |
| '-const X = "remove me";', | |
| '+const _X = "remove me";', | |
| " more", | |
| ].join("\n"); | |
| const s = diffToSuggestions(diff, PRELUDE); | |
| assertEquals(s.length, 1); | |
| assertEquals(s[0].path, "zuke.ts"); | |
| assertEquals(s[0].startLine, 46); // line after the leading context | |
| assertEquals(s[0].line, 46); | |
| assertEquals(s[0].body.includes("```suggestion"), true); | |
| assertEquals(s[0].body.includes('const _X = "remove me";'), true); | |
| assertEquals(s[0].key, "zuke.ts:46"); | |
| }); | |
| Deno.test("a deletion hunk suggests an empty (delete) block", () => { | |
| const diff = [ | |
| "diff --git a/a.ts b/a.ts", | |
| "--- a/a.ts", | |
| "+++ b/a.ts", | |
| "@@ -10,1 +9,0 @@", | |
| "-const REMOVE = 1;", | |
| ].join("\n"); | |
| const s = diffToSuggestions(diff, PRELUDE); | |
| assertEquals(s.length, 1); | |
| assertEquals(s[0].startLine, 10); | |
| assertEquals(s[0].line, 10); | |
| // An empty suggestion block deletes the targeted line on GitHub. | |
| assertEquals(s[0].body.includes("```suggestion\n```"), true); | |
| }); | |
| Deno.test("a pure insertion is skipped (nothing to anchor)", () => { | |
| const diff = [ | |
| "diff --git a/a.ts b/a.ts", | |
| "--- a/a.ts", | |
| "+++ b/a.ts", | |
| "@@ -5,0 +6,1 @@", | |
| "+const ADDED = 1;", | |
| ].join("\n"); | |
| assertEquals(diffToSuggestions(diff, PRELUDE), []); | |
| }); | |
| Deno.test("multiple files and hunks each produce a suggestion", () => { | |
| const diff = [ | |
| "diff --git a/one.ts b/one.ts", | |
| "--- a/one.ts", | |
| "+++ b/one.ts", | |
| "@@ -1,1 +1,1 @@", | |
| "-let a = 1;", | |
| "+const a = 1;", | |
| "diff --git a/two.ts b/two.ts", | |
| "--- a/two.ts", | |
| "+++ b/two.ts", | |
| "@@ -8,1 +8,1 @@", | |
| "-let b = 2;", | |
| "+const b = 2;", | |
| ].join("\n"); | |
| const s = diffToSuggestions(diff, PRELUDE); | |
| assertEquals(s.map((x) => `${x.path}:${x.startLine}`), [ | |
| "one.ts:1", | |
| "two.ts:8", | |
| ]); | |
| }); | |
| Deno.test("a removed line whose content begins with '--' is a removal, not a header", () => { | |
| const diff = [ | |
| "diff --git a/flags.ts b/flags.ts", | |
| "--- a/flags.ts", | |
| "+++ b/flags.ts", | |
| "@@ -3,2 +3,1 @@", | |
| " keep", | |
| "---verbose", // the removal (`-`) of a line whose content is `--verbose` | |
| "+--quiet", // the addition of `--quiet` | |
| ].join("\n"); | |
| const s = diffToSuggestions(diff, PRELUDE); | |
| // If `---verbose` were mistaken for a header the block would have no removal | |
| // and be skipped; the fix parses it, producing a replacement suggestion. | |
| assertEquals(s.length, 1); | |
| assertEquals([s[0].startLine, s[0].line], [4, 4]); | |
| assertEquals(s[0].body.includes("--quiet"), true); | |
| }); | |
| Deno.test("an empty diff yields no suggestions", () => { | |
| assertEquals(diffToSuggestions("", PRELUDE), []); | |
| }); | |
Xet Storage Details
- Size:
- 3.05 kB
- Xet hash:
- 86855ac70b227e5c36c3dd3d393588a5128f4357a2fbedbd39dcc215385fb0a2
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.