-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditFile.test.ts
More file actions
32 lines (27 loc) · 1.21 KB
/
Copy patheditFile.test.ts
File metadata and controls
32 lines (27 loc) · 1.21 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
import { describe, it, expect } from "vitest";
import { applyExactEdit } from "../src/tools/editFile.js";
describe("applyExactEdit", () => {
it("replaces a unique exact match", () => {
const result = applyExactEdit("const a = 1;\nconst b = 2;\n", "const b = 2;", "const b = 3;");
expect(result).toEqual({ ok: true, result: "const a = 1;\nconst b = 3;\n" });
});
it("errors when old_string is not found", () => {
const result = applyExactEdit("hello\n", "nope", "x");
expect(result.ok).toBe(false);
if (!result.ok) expect(result.error).toMatch(/not found/);
});
it("errors when old_string matches more than once", () => {
const result = applyExactEdit("dup\ndup\n", "dup", "x");
expect(result.ok).toBe(false);
if (!result.ok) expect(result.error).toMatch(/more than once/);
});
it("errors on empty old_string", () => {
const result = applyExactEdit("abc", "", "x");
expect(result.ok).toBe(false);
});
it("matches across CRLF files and preserves CRLF on write", () => {
const original = "line1\r\nline2\r\nline3\r\n";
const result = applyExactEdit(original, "line2\nline3", "lineX");
expect(result).toEqual({ ok: true, result: "line1\r\nlineX\r\n" });
});
});