encoding-multibyte.js
This file
Path
test/transform/encoding-multibyte.js
80 lines · 3.8 KiB · JavaScript
Last changed by
Require Node.js 22 (#1243)Sindre Sorhusbefore adoption04b4454
History of this fileTake it
Rename files (#977)ehmickybefore adoption4b2e316
lines 1–2why, one step back1import test from 'ava';2import {execa, execaSync} from '../../index.js';Upgrade xo (#980)ehmickybefore adoptionccfa412
line 3why, one step back3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';Rename files (#977)ehmickybefore adoption4b2e316
line 4why, one step back4import {noopGenerator, getOutputsGenerator, addNoopGenerator} from '../helpers/generator.js';Upgrade xo (#980)ehmickybefore adoptionccfa412
lines 5–11why, one step back5import {6 multibyteChar,7 multibyteString,8 multibyteUint8Array,9 breakingLength,10 brokenSymbol,11} from '../helpers/encoding.js';Rename files (#977)ehmickybefore adoption4b2e316
line 12why, one step back12Upgrade xo (#980)ehmickybefore adoptionccfa412
line 13why, one step back13setFixtureDirectory();Rename files (#977)ehmickybefore adoption4b2e316
lines 14–24why, one step back1415const foobarArray = ['fo', 'ob', 'ar', '..'];1617const testMultibyteCharacters = async (t, objectMode, addNoopTransform, execaMethod) => {18 const {stdout} = await execaMethod('noop.js', {19 stdout: addNoopGenerator(getOutputsGenerator(foobarArray)(objectMode, true), addNoopTransform, objectMode),20 encoding: 'base64',21 });22 if (objectMode) {23 t.deepEqual(stdout, foobarArray);24 } else {Require Node.js 22 (#1243)Sindre Sorhusbefore adoption04b4454
line 25why, one step back25 // eslint-disable-next-line n/prefer-global/buffer, unicorn/prefer-uint8array-base64 -- `Uint8Array#toBase64()` is not available on the minimum supported Node.js versionUpgrade xo (#980)ehmickybefore adoptionccfa412
line 26why, one step back26 t.is(stdout, Buffer.from(foobarArray.join('')).toString('base64'));Rename files (#977)ehmickybefore adoption4b2e316
lines 27–80why, one step back27 }28};2930test('Handle multibyte characters', testMultibyteCharacters, false, false, execa);31test('Handle multibyte characters, noop transform', testMultibyteCharacters, false, true, execa);32test('Handle multibyte characters, with objectMode', testMultibyteCharacters, true, false, execa);33test('Handle multibyte characters, with objectMode, noop transform', testMultibyteCharacters, true, true, execa);34test('Handle multibyte characters, sync', testMultibyteCharacters, false, false, execaSync);35test('Handle multibyte characters, noop transform, sync', testMultibyteCharacters, false, true, execaSync);36test('Handle multibyte characters, with objectMode, sync', testMultibyteCharacters, true, false, execaSync);37test('Handle multibyte characters, with objectMode, noop transform, sync', testMultibyteCharacters, true, true, execaSync);3839const testMultibyte = async (t, objectMode, execaMethod) => {40 const {stdout} = await execaMethod('stdin.js', {41 stdin: [42 [multibyteUint8Array.slice(0, breakingLength), multibyteUint8Array.slice(breakingLength)],43 noopGenerator(objectMode, true),44 ],45 });46 t.is(stdout, multibyteString);47};4849test('Generator handles multibyte characters with Uint8Array', testMultibyte, false, execa);50test('Generator handles multibyte characters with Uint8Array, objectMode', testMultibyte, true, execa);51test('Generator handles multibyte characters with Uint8Array, sync', testMultibyte, false, execaSync);52test('Generator handles multibyte characters with Uint8Array, objectMode, sync', testMultibyte, true, execaSync);5354const testMultibytePartial = async (t, objectMode, execaMethod) => {55 const {stdout} = await execaMethod('stdin.js', {56 stdin: [57 [multibyteUint8Array.slice(0, breakingLength)],58 noopGenerator(objectMode, true),59 ],60 });61 t.is(stdout, `${multibyteChar}${brokenSymbol}`);62};6364test('Generator handles partial multibyte characters with Uint8Array', testMultibytePartial, false, execa);65test('Generator handles partial multibyte characters with Uint8Array, objectMode', testMultibytePartial, true, execa);66test('Generator handles partial multibyte characters with Uint8Array, sync', testMultibytePartial, false, execaSync);67test('Generator handles partial multibyte characters with Uint8Array, objectMode, sync', testMultibytePartial, true, execaSync);6869const testMultibytePartialOutput = async (t, execaMethod) => {70 const {stdout} = await execaMethod('noop.js', {71 stdout: getOutputsGenerator([72 multibyteUint8Array.slice(0, breakingLength),73 multibyteUint8Array.slice(breakingLength),74 ])(false, true),75 });76 t.is(stdout, multibyteString);77};7879test('Generator handles output multibyte characters with Uint8Array', testMultibytePartialOutput, execa);80test('Generator handles output multibyte characters with Uint8Array, sync', testMultibytePartialOutput, execaSync);