(encoding: BufferEncoding, buf: Buffer)
| 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"]; |
no test coverage detected