From 36db03e7133676e4044c94084bd4b7f9ebe8cab7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Breitbart?= Date: Tue, 20 Nov 2018 22:35:51 +0100 Subject: [PATCH] keep old impl in test as reference; minor changes --- src/CharWidth.test.ts | 13 ++++++------- src/CharWidth.ts | 1 - src/InputHandler.ts | 3 +-- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/CharWidth.test.ts b/src/CharWidth.test.ts index c2d10c5c..d4ddd24c 100644 --- a/src/CharWidth.test.ts +++ b/src/CharWidth.test.ts @@ -78,8 +78,8 @@ describe('getStringCellWidth', function(): void { // TODO: multiline tests once #1685 is resolved }); -describe('wcwidth regression', function(): void { - // TODO: remove with one of the next releases +it('wcwidth should match all values from the old implementation', function(): void { + // old implementation const wcwidthOld = (function(opts: {nul: number, control: number}): (ucs: number) => number { // extracted from https://www.cl.cam.ac.uk/%7Emgk25/ucs/wcwidth.c // combining characters @@ -247,9 +247,8 @@ describe('wcwidth regression', function(): void { }; })({nul: 0, control: 0}); // configurable options - it('equality of old and new impl', function(): void { - for (let i = 0; i < 65536; ++i) { - assert.equal(wcwidth(i), wcwidthOld(i), `mismatch for i: ${i}`); - } - }); + // test full BMP range old vs new implmenetation + for (let i = 0; i < 65536; ++i) { + assert.equal(wcwidth(i), wcwidthOld(i), `mismatch for i: ${i}`); + } }); diff --git a/src/CharWidth.ts b/src/CharWidth.ts index 05fb5d37..d099b109 100644 --- a/src/CharWidth.ts +++ b/src/CharWidth.ts @@ -90,7 +90,6 @@ export const wcwidth = (function(opts: {nul: number, control: number}): (ucs: nu const control = opts.control | 0; // create lookup table for BMP plane - // TODO: make callable/configurable from UnicodeManager const table = new Uint8Array(65536); table.fill(1); table[0] = opts.nul; diff --git a/src/InputHandler.ts b/src/InputHandler.ts index 893046bf..b4ce054f 100644 --- a/src/InputHandler.ts +++ b/src/InputHandler.ts @@ -327,7 +327,6 @@ export class InputHandler extends Disposable implements IInputHandler { public print(data: string, start: number, end: number): void { let char: string; let code: number; - let second: number; let chWidth: number; const buffer: IBuffer = this._terminal.buffer; const charset: ICharset = this._terminal.charset; @@ -355,7 +354,7 @@ export class InputHandler extends Disposable implements IInputHandler { this._surrogateFirst = char; continue; } - second = data.charCodeAt(stringPosition); + const second = data.charCodeAt(stringPosition); // if the second part is in surrogate pair range create the high codepoint // otherwise fall back to UCS-2 behavior (handle codepoints independently) if (0xDC00 <= second && second <= 0xDFFF) {