mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-17 13:55:50 +00:00
test: 新增测试代码文件
This commit is contained in:
@@ -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([]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user