MCPcopy Create free account
hub / github.com/cloudflare/workerd / testBuf

Function testBuf

src/workerd/api/node/tests/string-decoder-test.js:387–409  ·  view source on GitHub ↗
(encoding, buf)

Source from the content-addressed store, hash-verified

385 }
386
387 function testBuf(encoding, buf) {
388 // Write one byte at a time.
389 let s = new StringDecoder(encoding);
390 let res1 = '';
391 for (let i = 0; i < buf.length; i++) {
392 res1 += s.write(buf.slice(i, i + 1));
393 }
394 res1 += s.end();
395
396 // Write the whole buffer at once.
397 let res2 = '';
398 s = new StringDecoder(encoding);
399 res2 += s.write(buf);
400 res2 += s.end();
401
402 // .toString() on the buffer
403 const res3 = buf.toString(encoding);
404
405 // One byte at a time should match toString
406 strictEqual(res1, res3);
407 // All bytes at once should match toString
408 strictEqual(res2, res3);
409 }
410
411 function testEnd(encoding, incomplete, next, expected) {
412 let res = '';

Callers 1

testEncodingFunction · 0.85

Calls 4

writeMethod · 0.95
endMethod · 0.95
strictEqualFunction · 0.85
toStringMethod · 0.65

Tested by

no test coverage detected