1// META: global=worker 2// META: script=resources/readable-stream-from-array.js 3// META: script=resources/readable-stream-to-array.js 4 5'use strict'; 6 7const inputBytes = [73, 32, 240, 159, 146, 153, 32, 115, 116, 114, 101, 8 97, 109, 115]; 9for (const splitPoint of [2, 3, 4, 5]) { 10 promise_test(async () => { 11 const input = readableStreamFromArray( 12 [new Uint8Array(inputBytes.slice(0, splitPoint)), 13 new Uint8Array(inputBytes.slice(splitPoint))]); 14 const expectedOutput = ['I ', '\u{1F499} streams']; 15 const output = input.pipeThrough(new TextDecoderStream()); 16 const array = await readableStreamToArray(output); 17 assert_array_equals(array, expectedOutput, 18 'the split code point should be in the second chunk ' + 19 'of the output'); 20 }, 'a code point split between chunks should not be emitted until all ' + 21 'bytes are available; split point = ' + splitPoint); 22} 23 24promise_test(async () => { 25 const splitPoint = 6; 26 const input = readableStreamFromArray( 27 [new Uint8Array(inputBytes.slice(0, splitPoint)), 28 new Uint8Array(inputBytes.slice(splitPoint))]); 29 const output = input.pipeThrough(new TextDecoderStream()); 30 const array = await readableStreamToArray(output); 31 assert_array_equals(array, ['I \u{1F499}', ' streams'], 32 'the multibyte character should be in the first chunk ' + 33 'of the output'); 34}, 'a code point should be emitted as soon as all bytes are available'); 35 36for (let splitPoint = 1; splitPoint < 7; ++splitPoint) { 37 promise_test(async () => { 38 const input = readableStreamFromArray( 39 [new Uint8Array(inputBytes.slice(0, splitPoint)), 40 new Uint8Array([]), 41 new Uint8Array(inputBytes.slice(splitPoint))]); 42 const concatenatedOutput = 'I \u{1F499} streams'; 43 const output = input.pipeThrough(new TextDecoderStream()); 44 const array = await readableStreamToArray(output); 45 assert_equals(array.length, 2, 'two chunks should be output'); 46 assert_equals(array[0].concat(array[1]), concatenatedOutput, 47 'output should be unchanged by the empty chunk'); 48 }, 'an empty chunk inside a code point split between chunks should not ' + 49 'change the output; split point = ' + splitPoint); 50} 51