%PDF- <> %âãÏÓ endobj 2 0 obj <> endobj 3 0 obj <>/ExtGState<>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI] >>/Annots[ 28 0 R 29 0 R] /MediaBox[ 0 0 595.5 842.25] /Contents 4 0 R/Group<>/Tabs/S>> endobj ºaâÚÎΞ-ÌE1ÍØÄ÷{òò2ÿ ÛÖ^ÔÀá TÎ{¦?§®¥kuµùÕ5sLOšuY>endobj 2 0 obj<>endobj 2 0 obj<>endobj 2 0 obj<>endobj 2 0 obj<> endobj 2 0 obj<>endobj 2 0 obj<>es 3 0 R>> endobj 2 0 obj<> ox[ 0.000000 0.000000 609.600000 935.600000]/Fi endobj 3 0 obj<> endobj 7 1 obj<>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI]>>/Subtype/Form>> stream
'use strict';
require('../common');
const { StringDecoder } = require('string_decoder');
const util = require('util');
const assert = require('assert');
// Tests that, for random sequences of bytes, our StringDecoder gives the
// same result as a direction conversion using Buffer.toString().
// In particular, it checks that StringDecoder aligns with V8’s own output.
function rand(max) {
return Math.floor(Math.random() * max);
}
function randBuf(maxLen) {
const buf = Buffer.allocUnsafe(rand(maxLen));
for (let i = 0; i < buf.length; i++)
buf[i] = rand(256);
return buf;
}
const encodings = [
'utf16le', 'utf8', 'ascii', 'hex', 'base64', 'latin1', 'base64url',
];
function runSingleFuzzTest() {
const enc = encodings[rand(encodings.length)];
const sd = new StringDecoder(enc);
const bufs = [];
const strings = [];
const N = rand(10);
for (let i = 0; i < N; ++i) {
const buf = randBuf(50);
bufs.push(buf);
strings.push(sd.write(buf));
}
strings.push(sd.end());
assert.strictEqual(strings.join(''), Buffer.concat(bufs).toString(enc),
`Mismatch:\n${util.inspect(strings)}\n` +
util.inspect(bufs.map((buf) => buf.toString('hex'))) +
`\nfor encoding ${enc}`);
}
const start = Date.now();
while (Date.now() - start < 100)
runSingleFuzzTest();