From 5e5d05358505a24970b535df35734a599896d066 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Sat, 4 Jan 2020 11:19:57 +0100 Subject: [PATCH] test: add repl tests to verify unicode support in previews MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This also adds a test to verify that changed writer options also change the preview output depending on the options. PR-URL: https://github.com/nodejs/node/pull/31112 Reviewed-By: MichaΓ«l Zasso Reviewed-By: James M Snell --- lib/internal/repl/utils.js | 3 - test/parallel/test-repl-history-navigation.js | 116 +++++++++++++++++- 2 files changed, 114 insertions(+), 5 deletions(-) diff --git a/lib/internal/repl/utils.js b/lib/internal/repl/utils.js index 69910e886848bb..20904d9d6a2445 100644 --- a/lib/internal/repl/utils.js +++ b/lib/internal/repl/utils.js @@ -357,9 +357,6 @@ function setupPreview(repl, contextSymbol, bufferSymbol, active) { // Support unicode characters of width other than one by checking the // actual width. - // TODO(BridgeAR): Add a test case to verify full-width characters work as - // expected. Also test that the line break in case of deactivated colors - // work as expected. if (inspected.length * 2 >= maxColumns && getStringWidth(inspected) > maxColumns) { maxColumns -= 4 + (repl.useColors ? 0 : 3); diff --git a/test/parallel/test-repl-history-navigation.js b/test/parallel/test-repl-history-navigation.js index c3710fa5a9b03d..3591f0f336b6e6 100644 --- a/test/parallel/test-repl-history-navigation.js +++ b/test/parallel/test-repl-history-navigation.js @@ -59,6 +59,8 @@ const BACKSPACE = { name: 'backspace' }; const WORD_LEFT = { name: 'left', ctrl: true }; const WORD_RIGHT = { name: 'right', ctrl: true }; const GO_TO_END = { name: 'end' }; +const DELETE_WORD_LEFT = { name: 'backspace', ctrl: true }; +const SIGINT = { name: 'c', ctrl: true }; const prompt = '> '; const WAIT = '€'; @@ -155,6 +157,24 @@ const tests = [ env: { NODE_REPL_HISTORY: defaultHistoryPath }, skip: !process.features.inspector, test: [ + // あ is a fill width character with a length of one. + // πŸ• is a full width character with a length of two. + // 𐐷 is a half width character with the length of two. + // '\u0301', '0x200D', '\u200E' are zero width characters. + `const x1 = '${'あ'.repeat(124)}'`, ENTER, // Fully visible + ENTER, + `const y1 = '${'あ'.repeat(125)}'`, ENTER, // Cut off + ENTER, + `const x2 = '${'πŸ•'.repeat(124)}'`, ENTER, // Fully visible + ENTER, + `const y2 = '${'πŸ•'.repeat(125)}'`, ENTER, // Cut off + ENTER, + `const x3 = '${'𐐷'.repeat(248)}'`, ENTER, // Fully visible + ENTER, + `const y3 = '${'𐐷'.repeat(249)}'`, ENTER, // Cut off + ENTER, + `const x4 = 'a${'\u0301'.repeat(1000)}'`, ENTER, // á + ENTER, `const ${'veryLongName'.repeat(30)} = 'I should be previewed'`, ENTER, 'const e = new RangeError("visible\\ninvisible")', @@ -174,6 +194,7 @@ const tests = [ { env: { NODE_REPL_HISTORY: defaultHistoryPath }, columns: 250, + checkTotal: true, showEscapeCodes: true, skip: !process.features.inspector, test: [ @@ -182,7 +203,21 @@ const tests = [ UP, WORD_LEFT, UP, - BACKSPACE + BACKSPACE, + 'x1', + BACKSPACE, + '2', + BACKSPACE, + '3', + BACKSPACE, + '4', + DELETE_WORD_LEFT, + 'y1', + BACKSPACE, + '2', + BACKSPACE, + '3', + SIGINT ], // A = Cursor n up // B = Cursor n down @@ -240,7 +275,44 @@ const tests = [ '\x1B[1B', '\x1B[2K', '\x1B[1A', // 6. Backspace '\x1B[1G', '\x1B[0J', - prompt, '\x1B[3G', '\r\n' + '> ', '\x1B[3G', 'x', '1', + `\n// '${'あ'.repeat(124)}'`, + '\x1B[1C\x1B[1A', + '\x1B[1B', '\x1B[2K', '\x1B[1A', + '\x1B[1G', '\x1B[0J', + '> x', '\x1B[4G', '2', + `\n// '${'πŸ•'.repeat(124)}'`, + '\x1B[1C\x1B[1A', + '\x1B[1B', '\x1B[2K', '\x1B[1A', + '\x1B[1G', '\x1B[0J', + '> x', '\x1B[4G', '3', + `\n// '${'𐐷'.repeat(248)}'`, + '\x1B[1C\x1B[1A', + '\x1B[1B', '\x1B[2K', '\x1B[1A', + '\x1B[1G', '\x1B[0J', + '> x', '\x1B[4G', '4', + `\n// 'a${'\u0301'.repeat(1000)}'`, + '\x1B[2D\x1B[1A', + '\x1B[1B', '\x1B[2K', '\x1B[1A', + '\x1B[1G', '\x1B[0J', + '> ', '\x1B[3G', 'y', '1', + `\n// '${'あ'.repeat(121)}...`, + '\x1B[245D\x1B[1A', + '\x1B[1B', '\x1B[2K', '\x1B[1A', + '\x1B[1G', '\x1B[0J', + '> y', '\x1B[4G', '2', + `\n// '${'πŸ•'.repeat(121)}...`, + '\x1B[245D\x1B[1A', + '\x1B[1B', '\x1B[2K', '\x1B[1A', + '\x1B[1G', '\x1B[0J', + '> y', '\x1B[4G', '3', + `\n// '${'𐐷'.repeat(242)}...`, + '\x1B[245D\x1B[1A', + '\x1B[1B', '\x1B[2K', '\x1B[1A', + '\r\n', + '\x1B[1G', '\x1B[0J', + '> ', '\x1B[3G', + '\r\n' ], clean: true }, @@ -317,6 +389,46 @@ const tests = [ ], clean: true }, + { + // Check changed inspection defaults. + env: { NODE_REPL_HISTORY: defaultHistoryPath }, + skip: !process.features.inspector, + test: [ + 'util.inspect.replDefaults.showHidden', + ENTER + ], + expected: [], + clean: false + }, + { + env: { NODE_REPL_HISTORY: defaultHistoryPath }, + skip: !process.features.inspector, + checkTotal: true, + test: [ + '[ ]', + WORD_LEFT, + WORD_LEFT, + UP, + ' = true', + ENTER, + '[ ]', + ENTER + ], + expected: [ + prompt, + '[', ' ', ']', + '\n// []', '\n// []', '\n// []', + '> util.inspect.replDefaults.showHidden', + '\n// false', ' ', '\n// false', + '=', ' ', 't', 'r', 'u', ' // e', 'e', + 'true\n', + '> ', '[', ' ', ']', + '\n// [ [length]: 0 ]', + '[ [length]: 0 ]\n', + '> ', + ], + clean: true + }, { // Check that the completer ignores completions that are outdated. env: { NODE_REPL_HISTORY: defaultHistoryPath },