|
1 | | -import { applyContextMatching, applyDMP } from "../edit-strategies" |
| 1 | +import { applyContextMatching, applyDMP, applyGitFallback } from "../edit-strategies" |
2 | 2 | import { Hunk } from "../types" |
3 | 3 |
|
4 | 4 | const testCases = [ |
@@ -257,3 +257,39 @@ describe("applyDMP", () => { |
257 | 257 | }) |
258 | 258 | }) |
259 | 259 | }) |
| 260 | + |
| 261 | +describe("applyGitFallback", () => { |
| 262 | + it("should successfully apply changes using git operations", async () => { |
| 263 | + const hunk = { |
| 264 | + changes: [ |
| 265 | + { type: "context", content: "line1", indent: "" }, |
| 266 | + { type: "remove", content: "line2", indent: "" }, |
| 267 | + { type: "add", content: "new line2", indent: "" }, |
| 268 | + { type: "context", content: "line3", indent: "" } |
| 269 | + ] |
| 270 | + } as Hunk |
| 271 | + |
| 272 | + const content = ["line1", "line2", "line3"] |
| 273 | + const result = await applyGitFallback(hunk, content) |
| 274 | + |
| 275 | + expect(result.result.join("\n")).toEqual("line1\nnew line2\nline3") |
| 276 | + expect(result.confidence).toBe(1) |
| 277 | + expect(result.strategy).toBe("git-fallback") |
| 278 | + }) |
| 279 | + |
| 280 | + it("should return original content with 0 confidence when changes cannot be applied", async () => { |
| 281 | + const hunk = { |
| 282 | + changes: [ |
| 283 | + { type: "context", content: "nonexistent", indent: "" }, |
| 284 | + { type: "add", content: "new line", indent: "" } |
| 285 | + ] |
| 286 | + } as Hunk |
| 287 | + |
| 288 | + const content = ["line1", "line2", "line3"] |
| 289 | + const result = await applyGitFallback(hunk, content) |
| 290 | + |
| 291 | + expect(result.result).toEqual(content) |
| 292 | + expect(result.confidence).toBe(0) |
| 293 | + expect(result.strategy).toBe("git-fallback") |
| 294 | + }) |
| 295 | +}) |
0 commit comments