GeezerVison is showing github.com — test: add repl tests to verify unicode support in previews · nodejs/node@3c82d5b
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/repl/utils.js -3Lines changed: 0 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -357,9 +357,6 @@ function setupPreview(repl, contextSymbol, bufferSymbol, active) { | 357 | 357 |
| 358 | 358 | // Support unicode characters of width other than one by checking the | 359 | 359 | // 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. | 363 | 360 | if (inspected.length * 2 >= maxColumns && | 364 | 361 | getStringWidth(inspected) > maxColumns) { | 365 | 362 | maxColumns -= 4 + (repl.useColors ? 0 : 3); | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-repl-history-navigation.js +114-2Lines changed: 114 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -59,6 +59,8 @@ const BACKSPACE = { name: 'backspace' }; | 59 | 59 | const WORD_LEFT = { name: 'left', ctrl: true }; | 60 | 60 | const WORD_RIGHT = { name: 'right', ctrl: true }; | 61 | 61 | const GO_TO_END = { name: 'end' }; | | 62 | +const DELETE_WORD_LEFT = { name: 'backspace', ctrl: true }; | | 63 | +const SIGINT = { name: 'c', ctrl: true }; | 62 | 64 |
| 63 | 65 | const prompt = '> '; | 64 | 66 | const WAIT = '€'; | @@ -155,6 +157,24 @@ const tests = [ | 155 | 157 | env: { NODE_REPL_HISTORY: defaultHistoryPath }, | 156 | 158 | skip: !process.features.inspector, | 157 | 159 | 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, | 158 | 178 | `const ${'veryLongName'.repeat(30)} = 'I should be previewed'`, | 159 | 179 | ENTER, | 160 | 180 | 'const e = new RangeError("visible\\ninvisible")', | @@ -174,6 +194,7 @@ const tests = [ | 174 | 194 | { | 175 | 195 | env: { NODE_REPL_HISTORY: defaultHistoryPath }, | 176 | 196 | columns: 250, | | 197 | + checkTotal: true, | 177 | 198 | showEscapeCodes: true, | 178 | 199 | skip: !process.features.inspector, | 179 | 200 | test: [ | @@ -182,7 +203,21 @@ const tests = [ | 182 | 203 | UP, | 183 | 204 | WORD_LEFT, | 184 | 205 | 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 | 186 | 221 | ], | 187 | 222 | // A = Cursor n up | 188 | 223 | // B = Cursor n down | @@ -240,7 +275,44 @@ const tests = [ | 240 | 275 | '\x1B[1B', '\x1B[2K', '\x1B[1A', | 241 | 276 | // 6. Backspace | 242 | 277 | '\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' | 244 | 316 | ], | 245 | 317 | clean: true | 246 | 318 | }, | @@ -317,6 +389,46 @@ const tests = [ | 317 | 389 | ], | 318 | 390 | clean: true | 319 | 391 | }, | | 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 | + }, | 320 | 432 | { | 321 | 433 | // Check that the completer ignores completions that are outdated. | 322 | 434 | env: { NODE_REPL_HISTORY: defaultHistoryPath }, | |
|