MCPcopy Create free account
hub / github.com/Ray-D-Song/lexe / testBuf

Function testBuf

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

Source from the content-addressed store, hash-verified

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