From 8ddbe35d9f54c2e25ed171f4d12595ca358b4a6d Mon Sep 17 00:00:00 2001 From: terminalchai <213856599+terminalchai@users.noreply.github.com> Date: Sat, 7 Mar 2026 01:55:55 +0530 Subject: [PATCH] test: add unit tests for wide CJK character handling in setWidth() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Three new cases under 'setWidth > wide (CJK / fullwidth) characters': - Japanese placeholder 'エリアを選択してください' (122ch) minWidth 25ch - Japanese value 'テスト' (32ch) width 7ch - Mixed ASCII + CJK value 'abcテ' (31 + 12 = 5ch) width 6ch All 356 unit tests pass. --- test/scripts/components/input.test.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/scripts/components/input.test.ts b/test/scripts/components/input.test.ts index 86424afc..6d5deba4 100644 --- a/test/scripts/components/input.test.ts +++ b/test/scripts/components/input.test.ts @@ -270,6 +270,32 @@ describe('components/input', () => { expect(instance.element.style.width).to.equal('16ch'); expect(instance.element.style.minWidth).to.equal('22ch'); }); + + describe('wide (CJK / fullwidth) characters', () => { + it('counts each Japanese character as 2ch for placeholder min-width', () => { + // 'エリアを選択してください' = 12 wide chars → 12×2 = 24ch → minWidth 25ch + instance.placeholder = 'エリアを選択してください'; + instance.element.value = ''; + instance.setWidth(); + expect(instance.element.style.minWidth).to.equal('25ch'); + }); + + it('counts each Japanese character as 2ch for value width', () => { + // 'テスト' = 3 wide chars → 3×2 = 6ch → width 7ch + instance.placeholder = ''; + instance.element.value = 'テスト'; + instance.setWidth(); + expect(instance.element.style.width).to.equal('7ch'); + }); + + it('mixes ASCII and CJK characters correctly', () => { + // 'abc' (3×1) + 'テ' (1×2) = 5ch → width 6ch + instance.placeholder = ''; + instance.element.value = 'abcテ'; + instance.setWidth(); + expect(instance.element.style.width).to.equal('6ch'); + }); + }); }); describe('placeholder setter', () => {