MCPcopy Index your code
hub / github.com/nodejs/node / test

Function test

test/parallel/test-string-decoder.js:225–250  ·  view source on GitHub ↗
(encoding, input, expected, singleSequence)

Source from the content-addressed store, hash-verified

223// singleSequence allows for easy debugging of a specific sequence which is
224// useful in case of test failures.
225function test(encoding, input, expected, singleSequence) {
226 let sequences;
227 if (!singleSequence) {
228 sequences = writeSequences(input.length);
229 } else {
230 sequences = [singleSequence];
231 }
232 const hexNumberRE = /.{2}/g;
233 sequences.forEach((sequence) => {
234 const decoder = new StringDecoder(encoding);
235 let output = '';
236 sequence.forEach((write) => {
237 output += decoder.write(input.slice(write[0], write[1]));
238 });
239 output += decoder.end();
240 if (output !== expected) {
241 const message =
242 `Expected "${unicodeEscape(expected)}", ` +
243 `but got "${unicodeEscape(output)}"\n` +
244 `input: ${input.toString('hex').match(hexNumberRE)}\n` +
245 `Write sequence: ${JSON.stringify(sequence)}\n` +
246 `Full Decoder State: ${inspect(decoder)}`;
247 assert.fail(message);
248 }
249 });
250}
251
252// unicodeEscape prints the str contents as unicode escape codes.
253function unicodeEscape(str) {

Callers 1

Calls 10

writeSequencesFunction · 0.85
unicodeEscapeFunction · 0.85
inspectFunction · 0.70
forEachMethod · 0.65
sliceMethod · 0.65
matchMethod · 0.65
writeMethod · 0.45
endMethod · 0.45
toStringMethod · 0.45
failMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…