(file: string)
| 50 | } |
| 51 | |
| 52 | async function expectDiff(file: string) { |
| 53 | const testFilePath = path.join( |
| 54 | __dirname, |
| 55 | "edit", |
| 56 | "lazy", |
| 57 | "test-examples", |
| 58 | file + ".diff", |
| 59 | ); |
| 60 | const testFileContents = fs.readFileSync(testFilePath, "utf-8"); |
| 61 | const [oldFile, newFile, expectedDiff] = testFileContents |
| 62 | .split("\n---\n") |
| 63 | .map((s) => s.replace(/^\n+/, "").trimEnd()); |
| 64 | const { ourDiffs: streamDiffs } = await collectDiffs(oldFile, newFile, file); |
| 65 | const displayedDiff = displayDiff(streamDiffs); |
| 66 | |
| 67 | if (!expectedDiff || expectedDiff.trim() === "") { |
| 68 | console.log( |
| 69 | "Expected diff was empty. Writing computed diff to the test file", |
| 70 | ); |
| 71 | fs.writeFileSync( |
| 72 | testFilePath, |
| 73 | `${oldFile}\n\n---\n\n${newFile}\n\n---\n\n${displayDiff( |
| 74 | continueMyersDiff(oldFile, newFile), |
| 75 | )}`, |
| 76 | ); |
| 77 | |
| 78 | throw new Error("Expected diff is empty"); |
| 79 | } |
| 80 | |
| 81 | expect(normalizeDisplayedDiff(displayedDiff)).toEqual( |
| 82 | normalizeDisplayedDiff(expectedDiff), |
| 83 | ); |
| 84 | } |
| 85 | |
| 86 | describe("deterministicApplyLazyEdit(", () => { |
| 87 | test("no changes", async () => { |
no test coverage detected