From 0ea52127785457e97f9ab6f73691a4f887c8df20 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Sat, 14 Mar 2026 18:31:49 -0600 Subject: [PATCH] test: Add tests for leading zero visual input handling Co-authored-by: aider (gemini/gemini-2.5-pro) --- calculator/test.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/calculator/test.js b/calculator/test.js index 2af0167..e1e306d 100644 --- a/calculator/test.js +++ b/calculator/test.js @@ -509,6 +509,34 @@ test('Number input chaos: leading zeros', () => { checkDisplay('7', 'Can input number with leading zeros after a clear'); }); +test('Leading zeros are visually removed during input', () => { + press('0'); + assert.strictEqual(global.last_display_num, '0', 'Input: 0'); + press('0'); + assert.strictEqual(global.last_display_num, '0', 'Second 0 should not create "00"'); + press('7'); + assert.strictEqual(global.last_display_num, '7', '0 should be replaced by 7'); + press('R'); press('R'); + + press('0'); + press('0'); + press('.'); + assert.strictEqual(global.last_display_num, '0.', 'Input: 00. -> "0."'); + press('4'); + assert.strictEqual(global.last_display_num, '0.4', 'Input: 00.4 -> "0.4"'); + press('R'); press('R'); + + // After a calculation, starting a new number + press('1+2='); + checkDisplay(3); + press('0'); + assert.strictEqual(global.last_display_num, '0', 'Post-calc: 0'); + press('0'); + assert.strictEqual(global.last_display_num, '0', 'Post-calc: 00 -> "0"'); + press('5'); + assert.strictEqual(global.last_display_num, '5', 'Post-calc: 005 -> "5"'); +}); + test('Repeated equals', () => { press('2+3='); checkDisplay('5');