Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3c82d5b

Browse filesBrowse files
BridgeARMylesBorins
authored andcommitted
test: add repl tests to verify unicode support in previews
This also adds a test to verify that changed writer options also change the preview output depending on the options. PR-URL: #31112 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent b92d65d commit 3c82d5b
Copy full SHA for 3c82d5b

File tree

Expand file treeCollapse file tree

2 files changed

+114
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+114
-5
lines changed
Open diff view settings
Collapse file

‎lib/internal/repl/utils.js‎

Copy file name to clipboardExpand all lines: lib/internal/repl/utils.js
-3Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,6 @@ function setupPreview(repl, contextSymbol, bufferSymbol, active) {
357357

358358
// Support unicode characters of width other than one by checking the
359359
// actual width.
360-
// TODO(BridgeAR): Add a test case to verify full-width characters work as
361-
// expected. Also test that the line break in case of deactivated colors
362-
// work as expected.
363360
if (inspected.length * 2 >= maxColumns &&
364361
getStringWidth(inspected) > maxColumns) {
365362
maxColumns -= 4 + (repl.useColors ? 0 : 3);
Collapse file

‎test/parallel/test-repl-history-navigation.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-repl-history-navigation.js
+114-2Lines changed: 114 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ const BACKSPACE = { name: 'backspace' };
5959
const WORD_LEFT = { name: 'left', ctrl: true };
6060
const WORD_RIGHT = { name: 'right', ctrl: true };
6161
const GO_TO_END = { name: 'end' };
62+
const DELETE_WORD_LEFT = { name: 'backspace', ctrl: true };
63+
const SIGINT = { name: 'c', ctrl: true };
6264

6365
const prompt = '> ';
6466
const WAIT = '€';
@@ -155,6 +157,24 @@ const tests = [
155157
env: { NODE_REPL_HISTORY: defaultHistoryPath },
156158
skip: !process.features.inspector,
157159
test: [
160+
// あ is a fill width character with a length of one.
161+
// 🐕 is a full width character with a length of two.
162+
// 𐐷 is a half width character with the length of two.
163+
// '\u0301', '0x200D', '\u200E' are zero width characters.
164+
`const x1 = '${'あ'.repeat(124)}'`, ENTER, // Fully visible
165+
ENTER,
166+
`const y1 = '${'あ'.repeat(125)}'`, ENTER, // Cut off
167+
ENTER,
168+
`const x2 = '${'🐕'.repeat(124)}'`, ENTER, // Fully visible
169+
ENTER,
170+
`const y2 = '${'🐕'.repeat(125)}'`, ENTER, // Cut off
171+
ENTER,
172+
`const x3 = '${'𐐷'.repeat(248)}'`, ENTER, // Fully visible
173+
ENTER,
174+
`const y3 = '${'𐐷'.repeat(249)}'`, ENTER, // Cut off
175+
ENTER,
176+
`const x4 = 'a${'\u0301'.repeat(1000)}'`, ENTER, // á
177+
ENTER,
158178
`const ${'veryLongName'.repeat(30)} = 'I should be previewed'`,
159179
ENTER,
160180
'const e = new RangeError("visible\\ninvisible")',
@@ -174,6 +194,7 @@ const tests = [
174194
{
175195
env: { NODE_REPL_HISTORY: defaultHistoryPath },
176196
columns: 250,
197+
checkTotal: true,
177198
showEscapeCodes: true,
178199
skip: !process.features.inspector,
179200
test: [
@@ -182,7 +203,21 @@ const tests = [
182203
UP,
183204
WORD_LEFT,
184205
UP,
185-
BACKSPACE
206+
BACKSPACE,
207+
'x1',
208+
BACKSPACE,
209+
'2',
210+
BACKSPACE,
211+
'3',
212+
BACKSPACE,
213+
'4',
214+
DELETE_WORD_LEFT,
215+
'y1',
216+
BACKSPACE,
217+
'2',
218+
BACKSPACE,
219+
'3',
220+
SIGINT
186221
],
187222
// A = Cursor n up
188223
// B = Cursor n down
@@ -240,7 +275,44 @@ const tests = [
240275
'\x1B[1B', '\x1B[2K', '\x1B[1A',
241276
// 6. Backspace
242277
'\x1B[1G', '\x1B[0J',
243-
prompt, '\x1B[3G', '\r\n'
278+
'> ', '\x1B[3G', 'x', '1',
279+
`\n// '${'あ'.repeat(124)}'`,
280+
'\x1B[1C\x1B[1A',
281+
'\x1B[1B', '\x1B[2K', '\x1B[1A',
282+
'\x1B[1G', '\x1B[0J',
283+
'> x', '\x1B[4G', '2',
284+
`\n// '${'🐕'.repeat(124)}'`,
285+
'\x1B[1C\x1B[1A',
286+
'\x1B[1B', '\x1B[2K', '\x1B[1A',
287+
'\x1B[1G', '\x1B[0J',
288+
'> x', '\x1B[4G', '3',
289+
`\n// '${'𐐷'.repeat(248)}'`,
290+
'\x1B[1C\x1B[1A',
291+
'\x1B[1B', '\x1B[2K', '\x1B[1A',
292+
'\x1B[1G', '\x1B[0J',
293+
'> x', '\x1B[4G', '4',
294+
`\n// 'a${'\u0301'.repeat(1000)}'`,
295+
'\x1B[2D\x1B[1A',
296+
'\x1B[1B', '\x1B[2K', '\x1B[1A',
297+
'\x1B[1G', '\x1B[0J',
298+
'> ', '\x1B[3G', 'y', '1',
299+
`\n// '${'あ'.repeat(121)}...`,
300+
'\x1B[245D\x1B[1A',
301+
'\x1B[1B', '\x1B[2K', '\x1B[1A',
302+
'\x1B[1G', '\x1B[0J',
303+
'> y', '\x1B[4G', '2',
304+
`\n// '${'🐕'.repeat(121)}...`,
305+
'\x1B[245D\x1B[1A',
306+
'\x1B[1B', '\x1B[2K', '\x1B[1A',
307+
'\x1B[1G', '\x1B[0J',
308+
'> y', '\x1B[4G', '3',
309+
`\n// '${'𐐷'.repeat(242)}...`,
310+
'\x1B[245D\x1B[1A',
311+
'\x1B[1B', '\x1B[2K', '\x1B[1A',
312+
'\r\n',
313+
'\x1B[1G', '\x1B[0J',
314+
'> ', '\x1B[3G',
315+
'\r\n'
244316
],
245317
clean: true
246318
},
@@ -317,6 +389,46 @@ const tests = [
317389
],
318390
clean: true
319391
},
392+
{
393+
// Check changed inspection defaults.
394+
env: { NODE_REPL_HISTORY: defaultHistoryPath },
395+
skip: !process.features.inspector,
396+
test: [
397+
'util.inspect.replDefaults.showHidden',
398+
ENTER
399+
],
400+
expected: [],
401+
clean: false
402+
},
403+
{
404+
env: { NODE_REPL_HISTORY: defaultHistoryPath },
405+
skip: !process.features.inspector,
406+
checkTotal: true,
407+
test: [
408+
'[ ]',
409+
WORD_LEFT,
410+
WORD_LEFT,
411+
UP,
412+
' = true',
413+
ENTER,
414+
'[ ]',
415+
ENTER
416+
],
417+
expected: [
418+
prompt,
419+
'[', ' ', ']',
420+
'\n// []', '\n// []', '\n// []',
421+
'> util.inspect.replDefaults.showHidden',
422+
'\n// false', ' ', '\n// false',
423+
'=', ' ', 't', 'r', 'u', ' // e', 'e',
424+
'true\n',
425+
'> ', '[', ' ', ']',
426+
'\n// [ [length]: 0 ]',
427+
'[ [length]: 0 ]\n',
428+
'> ',
429+
],
430+
clean: true
431+
},
320432
{
321433
// Check that the completer ignores completions that are outdated.
322434
env: { NODE_REPL_HISTORY: defaultHistoryPath },

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.