function utf8() {
function verify(name, src, chars, str) {
console.log();
console.log(`${name} UTF8 test`);
console.log(`${name} source: ${displayArray(src)}`);
console.log(`${name} chars: ${displayArray(chars)}`);
console.log(`${name} string: ${str}`);
const output = converter.decode('UTF8', src);
assert(arraysEqual(chars, output), `${name} :decode UTF8 failed`);
const dst = converter.encode('UTF8', chars);
assert(arraysEqual(src, dst), `${name} :encode UTF8 failed`);
}
const byte1_str = 'abc\tXYZ\r\n';
const byte1_utf8 = Buffer.from([97, 98, 99, 9, 88, 89, 90, 13, 10]);
const byte1_chars = [97, 98, 99, 9, 88, 89, 90, 13, 10];
verify('ASCII(1-byte)', byte1_utf8, byte1_chars, byte1_str);
const byte2_str = '\xa7\xa9\xae\xb6\xfc';
const byte2_utf8 = Buffer.from([0xc2, 0xa7, 0xc2, 0xa9, 0xc2, 0xae, 0xc2, 0xb6, 0xc3, 0xbc]);
const byte2_chars = [0xa7, 0xa9, 0xae, 0xb6, 0xfc];
verify('BINARY(2-byte)', byte2_utf8, byte2_chars, byte2_str);
const byte3_str = '\u13a3\u13ad\u13b2\u13cd\u13db';
const byte3_utf8 = Buffer.from([
0xe1, 0x8e, 0xa3, 0xe1, 0x8e, 0xad, 0xe1, 0x8e, 0xb2, 0xe1, 0x8f, 0x8d, 0xe1, 0x8f, 0x9b,
]);
const byte3_chars = [0x13a3, 0x13ad, 0x13b2, 0x13cd, 0x13db];
verify('Cherokee(3-byte)', byte3_utf8, byte3_chars, byte3_str);
const byte4_str = '\u{1F0A1}\u{1F0B1}\u{1F0C1}\u{1F0D1}';
const byte4_utf8 = Buffer.from([
0xf0, 0x9f, 0x82, 0xa1, 0xf0, 0x9f, 0x82, 0xb1, 0xf0, 0x9f, 0x83, 0x81, 0xf0, 0x9f, 0x83, 0x91,
]);
const byte4_chars = [0x1f0a1, 0x1f0b1, 0x1f0c1, 0x1f0d1];
verify('Playing Cards(4-byte)', byte4_utf8, byte4_chars, byte4_str);
}