MCPcopy Create free account
hub / github.com/awslabs/llrt / testBuf

Function testBuf

tests/unit/string_decoder.test.ts:231–253  ·  view source on GitHub ↗
(encoding: BufferEncoding, buf: Buffer)

Source from the content-addressed store, hash-verified

229 }
230
231 function testBuf(encoding: BufferEncoding, buf: Buffer) {
232 // Write one byte at a time.
233 let s = new StringDecoder(encoding);
234 let res1 = "";
235 for (let i = 0; i < buf.length; i++) {
236 res1 += s.write(buf.slice(i, i + 1));
237 }
238 res1 += s.end();
239
240 // Write the whole buffer at once.
241 let res2 = "";
242 s = new StringDecoder(encoding);
243 res2 += s.write(buf);
244 res2 += s.end();
245
246 // .toString() on the buffer
247 const res3 = buf.toString(encoding);
248
249 // One byte at a time should match toString
250 expect(res1).toEqual(res3);
251 // All bytes at once should match toString
252 expect(res2).toEqual(res3);
253 }
254
255 it("encodings", () => {
256 const encodings: BufferEncoding[] = ["base64", "hex", "utf8", "utf16le"];

Callers 1

testEncodingFunction · 0.85

Calls 4

writeMethod · 0.95
endMethod · 0.95
toStringMethod · 0.65
sliceMethod · 0.45

Tested by

no test coverage detected