mirror of
https://github.com/nodejs/node.git
synced 2025-05-09 17:22:44 +00:00

We should use `common.hasIntl` in tests for test cases which are related to ICU. This way we can easily find the test cases that are Intl dependent. Plus, it will be able to make the tests a little faster if we check hasIntl first. Also, this tweaks the log messages to unify the message. Refs: https://github.com/nodejs/node/pull/10707 PR-URL: https://github.com/nodejs/node/pull/10841 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
44 lines
1.8 KiB
JavaScript
44 lines
1.8 KiB
JavaScript
// Flags: --expose_internals
|
|
'use strict';
|
|
const common = require('../common');
|
|
|
|
if (!common.hasIntl) {
|
|
common.skip('missing Intl');
|
|
return;
|
|
}
|
|
|
|
const assert = require('assert');
|
|
const readline = require('internal/readline');
|
|
|
|
// Test column width
|
|
assert.strictEqual(readline.getStringWidth('a'), 1);
|
|
assert.strictEqual(readline.getStringWidth('丁'), 2);
|
|
assert.strictEqual(readline.getStringWidth('\ud83d\udc78\ud83c\udfff'), 2);
|
|
assert.strictEqual(readline.getStringWidth('👅'), 2);
|
|
assert.strictEqual(readline.getStringWidth('\n'), 0);
|
|
assert.strictEqual(readline.getStringWidth('\u200Ef\u200F'), 1);
|
|
assert.strictEqual(readline.getStringWidth(97), 1);
|
|
|
|
// The following is an emoji sequence. In some implementations, it is
|
|
// represented as a single glyph, in other implementations as a sequence
|
|
// of individual glyphs. By default, the algorithm will assume the single
|
|
// glyph interpretation and return a value of 2. By passing the
|
|
// expandEmojiSequence: true option, each component will be counted
|
|
// individually.
|
|
assert.strictEqual(readline.getStringWidth('👩👩👧👧'), 2);
|
|
assert.strictEqual(
|
|
readline.getStringWidth('👩👩👧👧', {expandEmojiSequence: true}), 8);
|
|
|
|
// By default, unicode characters whose width is considered ambiguous will
|
|
// be considered half-width. For these characters, getStringWidth will return
|
|
// 1. In some contexts, however, it is more appropriate to consider them full
|
|
// width. By default, the algorithm will assume half width. By passing
|
|
// the ambiguousAsFullWidth: true option, ambiguous characters will be counted
|
|
// as 2 columns.
|
|
assert.strictEqual(readline.getStringWidth('\u01d4'), 1);
|
|
assert.strictEqual(
|
|
readline.getStringWidth('\u01d4', {ambiguousAsFullWidth: true}), 2);
|
|
|
|
// Control chars and combining chars are zero
|
|
assert.strictEqual(readline.getStringWidth('\u200E\n\u220A\u20D2'), 1);
|