From 06859ee9bf2f56fe2cce8d20a9ee33aa33abefd7 Mon Sep 17 00:00:00 2001 From: Nate Date: Mon, 16 Sep 2024 22:42:38 -0700 Subject: [PATCH] found a failing edge case --- core/edit/lazy/deterministic.test.ts | 6 +- .../test-examples/calculator-exp2.js.diff | 93 +++++++++++++++++++ 2 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 core/edit/lazy/test-examples/calculator-exp2.js.diff diff --git a/core/edit/lazy/deterministic.test.ts b/core/edit/lazy/deterministic.test.ts index a000803af..e47ae3e37 100644 --- a/core/edit/lazy/deterministic.test.ts +++ b/core/edit/lazy/deterministic.test.ts @@ -133,10 +133,14 @@ describe("deterministicApplyLazyEdit(", () => { await expectDiff("fastapi.py"); }); - test.only("calculator exp", async () => { + test("calculator exp", async () => { await expectDiff("calculator-exp.js"); }); + test.only("calculator exp2", async () => { + await expectDiff("calculator-exp2.js"); + }); + test("calculator comments", async () => { await expectDiff("calculator-comments.js"); }); diff --git a/core/edit/lazy/test-examples/calculator-exp2.js.diff b/core/edit/lazy/test-examples/calculator-exp2.js.diff new file mode 100644 index 000000000..a580f5ee1 --- /dev/null +++ b/core/edit/lazy/test-examples/calculator-exp2.js.diff @@ -0,0 +1,93 @@ +class Calculator { + constructor() { + this.result = 0; + } + + add(number) { + this.result += number; + return this; + } + + subtract(number) { + this.result -= number; + return this; + } + + multiply(number) { + this.result *= number; + return this; + } + + divide(number) { + if (number === 0) { + throw new Error("Cannot divide by zero"); + } + this.result /= number; + return this; + } + + getResult() { + return this.result; + } + + reset() { + this.result = 0; + return this; + } +} + +--- + +class Calculator { + // ... existing code ... + + exp(number) { + this.result = Math.pow(this.result, number); + return this; + } +} + +--- + +class Calculator { + constructor() { + this.result = 0; + } + + add(number) { + this.result += number; + return this; + } + + subtract(number) { + this.result -= number; + return this; + } + + multiply(number) { + this.result *= number; + return this; + } + + divide(number) { + if (number === 0) { + throw new Error("Cannot divide by zero"); + } + this.result /= number; + return this; + } + + getResult() { + return this.result; + } + + reset() { + this.result = 0; + return this; + } ++ ++ exp(a) { ++ this.result = Math.pow(this.result, a); ++ return this; ++ } +} \ No newline at end of file