mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
Assisted-by: Claude opus 5.5 Signed-off-by: Mert Can Altin <mertgold60@gmail.com> PR-URL: https://github.com/nodejs/node/pull/66831 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Robert Nagy <ronagy@icloud.com>
34 lines
763 B
JavaScript
34 lines
763 B
JavaScript
'use strict';
|
|
|
|
// Tests TextEncoder.prototype.encode() around the short string path.
|
|
|
|
require('../common');
|
|
|
|
const assert = require('assert');
|
|
|
|
const encoder = new TextEncoder();
|
|
|
|
const inputs = [
|
|
'',
|
|
'a',
|
|
'a'.repeat(32),
|
|
'a'.repeat(33),
|
|
'\xff'.repeat(32),
|
|
'ğ'.repeat(32),
|
|
'ࠀ'.repeat(32),
|
|
'\u{1F44B}'.repeat(16),
|
|
'\u{1F44B}'.repeat(17),
|
|
'\ud800',
|
|
'a\udc00b',
|
|
'abc\ud83d',
|
|
];
|
|
|
|
for (const input of inputs) {
|
|
const result = encoder.encode(input);
|
|
const expected = Buffer.from(input, 'utf8');
|
|
assert.strictEqual(Object.getPrototypeOf(result), Uint8Array.prototype);
|
|
assert.strictEqual(result.byteOffset, 0);
|
|
assert.strictEqual(result.buffer.byteLength, expected.length);
|
|
assert.deepStrictEqual(Buffer.from(result), expected);
|
|
}
|