Skip to content
Myr

encoding-multibyte.js

This file

Path

test/transform/encoding-multibyte.js

79 lines · 3.6 KiB · JavaScript

Last changed by

Upgrade xo (#980)ehmickybefore adoptionccfa412

History of this file

Take it

Rename files (#977)ehmickybefore adoption4b2e316

lines 1–2why, one step back
1import test from 'ava';
2import {execa, execaSync} from '../../index.js';

Upgrade xo (#980)ehmickybefore adoptionccfa412

line 3why, one step back
3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';

Rename files (#977)ehmickybefore adoption4b2e316

line 4why, one step back
4import {noopGenerator, getOutputsGenerator, addNoopGenerator} from '../helpers/generator.js';

Upgrade xo (#980)ehmickybefore adoptionccfa412

lines 5–11why, one step back
5import {
6 multibyteChar,7 multibyteString,8 multibyteUint8Array,9 breakingLength,10 brokenSymbol,11} from '../helpers/encoding.js';

Rename files (#977)ehmickybefore adoption4b2e316

line 12why, one step back
12

Upgrade xo (#980)ehmickybefore adoptionccfa412

line 13why, one step back
13setFixtureDirectory();

Rename files (#977)ehmickybefore adoption4b2e316

lines 14–24why, one step back
14
15const 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 {

Upgrade xo (#980)ehmickybefore adoptionccfa412

line 25why, one step back
25 t.is(stdout, Buffer.from(foobarArray.join('')).toString('base64'));

Rename files (#977)ehmickybefore adoption4b2e316

lines 26–79why, one step back
26 }
27};2829test('Handle multibyte characters', testMultibyteCharacters, false, false, execa);30test('Handle multibyte characters, noop transform', testMultibyteCharacters, false, true, execa);31test('Handle multibyte characters, with objectMode', testMultibyteCharacters, true, false, execa);32test('Handle multibyte characters, with objectMode, noop transform', testMultibyteCharacters, true, true, execa);33test('Handle multibyte characters, sync', testMultibyteCharacters, false, false, execaSync);34test('Handle multibyte characters, noop transform, sync', testMultibyteCharacters, false, true, execaSync);35test('Handle multibyte characters, with objectMode, sync', testMultibyteCharacters, true, false, execaSync);36test('Handle multibyte characters, with objectMode, noop transform, sync', testMultibyteCharacters, true, true, execaSync);3738const testMultibyte = async (t, objectMode, execaMethod) => {39 const {stdout} = await execaMethod('stdin.js', {40 stdin: [41 [multibyteUint8Array.slice(0, breakingLength), multibyteUint8Array.slice(breakingLength)],42 noopGenerator(objectMode, true),43 ],44 });45 t.is(stdout, multibyteString);46};4748test('Generator handles multibyte characters with Uint8Array', testMultibyte, false, execa);49test('Generator handles multibyte characters with Uint8Array, objectMode', testMultibyte, true, execa);50test('Generator handles multibyte characters with Uint8Array, sync', testMultibyte, false, execaSync);51test('Generator handles multibyte characters with Uint8Array, objectMode, sync', testMultibyte, true, execaSync);5253const testMultibytePartial = async (t, objectMode, execaMethod) => {54 const {stdout} = await execaMethod('stdin.js', {55 stdin: [56 [multibyteUint8Array.slice(0, breakingLength)],57 noopGenerator(objectMode, true),58 ],59 });60 t.is(stdout, `${multibyteChar}${brokenSymbol}`);61};6263test('Generator handles partial multibyte characters with Uint8Array', testMultibytePartial, false, execa);64test('Generator handles partial multibyte characters with Uint8Array, objectMode', testMultibytePartial, true, execa);65test('Generator handles partial multibyte characters with Uint8Array, sync', testMultibytePartial, false, execaSync);66test('Generator handles partial multibyte characters with Uint8Array, objectMode, sync', testMultibytePartial, true, execaSync);6768const testMultibytePartialOutput = async (t, execaMethod) => {69 const {stdout} = await execaMethod('noop.js', {70 stdout: getOutputsGenerator([71 multibyteUint8Array.slice(0, breakingLength),72 multibyteUint8Array.slice(breakingLength),73 ])(false, true),74 });75 t.is(stdout, multibyteString);76};7778test('Generator handles output multibyte characters with Uint8Array', testMultibytePartialOutput, execa);79test('Generator handles output multibyte characters with Uint8Array, sync', testMultibytePartialOutput, execaSync);