// Auto-generated by scripts/gen_parity_tests.py from docs/runtime-parity.md.
// Module: node:string_decoder
// This file is a byte-for-byte parity test against `node --experimental-strip-types`.

import { StringDecoder } from "node:string_decoder";

try {
  const dec = new StringDecoder("utf8");
  console.log("ctor type:", typeof dec);

  console.log("write whole:", dec.write(Buffer.from([0xe2, 0x82, 0xac]))); // €
  console.log("write empty:", dec.write(Buffer.alloc(0)));

  const dec2 = new StringDecoder("utf8");
  console.log("split write1:", dec2.write(Buffer.from([0xe2, 0x82])));
  console.log("split write2:", dec2.write(Buffer.from([0xac])));

  const dec3 = new StringDecoder("utf8");
  console.log("end no-input:", dec3.end());

  const dec4 = new StringDecoder("utf8");
  dec4.write(Buffer.from([0xe2, 0x82]));
  console.log("lastNeed type:", typeof (dec4 as any).lastNeed);
  console.log("lastTotal type:", typeof (dec4 as any).lastTotal);
  console.log("lastChar type:", typeof (dec4 as any).lastChar);
} catch (e) {
  console.log("StringDecoder ERROR:", (e as Error).message);
}

try {
  const dec = new StringDecoder("utf16le");
  console.log("utf16le write:", dec.write(Buffer.from([0x68, 0x00, 0x69, 0x00])));
} catch (e) {
  console.log("utf16le ERROR:", (e as Error).message);
}

try {
  const dec = new StringDecoder("base64");
  console.log("base64 write:", dec.write(Buffer.from("hello")));
  console.log("base64 end:", dec.end());
} catch (e) {
  console.log("base64 ERROR:", (e as Error).message);
}
