test: 新增测试代码文件

This commit is contained in:
claude-code-best
2026-04-02 14:44:56 +08:00
parent 9c3803d16b
commit 006ad97fbb
32 changed files with 1102 additions and 68 deletions

View File

@@ -40,9 +40,10 @@ describe("getPatchFromContents", () => {
oldContent: "hello\nworld",
newContent: "hello\nplanet",
});
expect(hunks.length).toBeGreaterThan(0);
expect(hunks[0].lines.some((l: string) => l.startsWith("-"))).toBe(true);
expect(hunks[0].lines.some((l: string) => l.startsWith("+"))).toBe(true);
expect(hunks.length).toBe(1);
const allLines = hunks[0].lines;
expect(allLines).toContain("-world");
expect(allLines).toContain("+planet");
});
test("returns empty hunks for identical content", () => {
@@ -73,5 +74,44 @@ describe("getPatchFromContents", () => {
newContent: "new content",
});
expect(hunks.length).toBeGreaterThan(0);
const allLines = hunks.flatMap((h: any) => h.lines);
expect(allLines.some((l: string) => l.startsWith("+"))).toBe(true);
});
test("handles content with dollar signs", () => {
const hunks = getPatchFromContents({
filePath: "test.txt",
oldContent: "price: $5",
newContent: "price: $10",
});
expect(hunks.length).toBeGreaterThan(0);
const allLines = hunks.flatMap((h: any) => h.lines);
expect(allLines.some((l: string) => l.includes("$"))).toBe(true);
// Verify dollar signs are unescaped (not the token)
expect(allLines.some((l: string) => l.includes("<<:DOLLAR_TOKEN:>>"))).toBe(false);
});
test("handles deleting all content", () => {
const hunks = getPatchFromContents({
filePath: "test.txt",
oldContent: "line1\nline2\nline3",
newContent: "",
});
expect(hunks.length).toBeGreaterThan(0);
const allLines = hunks.flatMap((h: any) => h.lines);
expect(allLines.some((l: string) => l.startsWith("-"))).toBe(true);
expect(allLines.every((l: string) => l.startsWith("-") || l.startsWith(" ") || l.startsWith("\\"))).toBe(true);
});
test("ignoreWhitespace treats indentation changes as identical", () => {
const old = "function foo() {\n return 42;\n}\n";
const nw = "function foo() {\n\treturn 42;\n}\n";
const hunks = getPatchFromContents({
filePath: "test.txt",
oldContent: old,
newContent: nw,
ignoreWhitespace: true,
});
expect(hunks).toEqual([]);
});
});