Use alternate TextEncoder/TextDecoder implementation (#1281)

This is faster and smaller.
This commit is contained in:
Kitson Kelly 2018-12-07 05:01:15 +11:00 committed by Ryan Dahl
parent 60c008d23b
commit 6cc89b9e27
9 changed files with 366 additions and 42 deletions

View file

@ -24,3 +24,49 @@ test(function btoaFailed() {
assert(!!err);
assertEqual(err.name, "InvalidInput");
});
test(function textDecoder() {
// prettier-ignore
const fixture = new Uint8Array([
0xef, 0xbf, 0xbd, 0xef, 0xbf, 0xbd,
0xef, 0xbf, 0xbd, 0xef, 0xbf, 0xbd,
0xef, 0xbf, 0xbd, 0xef, 0xbf, 0xbd
]);
const decoder = new TextDecoder();
assertEqual(decoder.decode(fixture), "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
});
test(function textDecoder2() {
// prettier-ignore
const fixture = new Uint8Array([
0xf0, 0x9d, 0x93, 0xbd,
0xf0, 0x9d, 0x93, 0xae,
0xf0, 0x9d, 0x94, 0x81,
0xf0, 0x9d, 0x93, 0xbd
]);
const decoder = new TextDecoder();
assertEqual(decoder.decode(fixture), "𝓽𝓮𝔁𝓽");
});
test(function textEncoder() {
const fixture = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
const encoder = new TextEncoder();
// prettier-ignore
assertEqual(Array.from(encoder.encode(fixture)), [
0xef, 0xbf, 0xbd, 0xef, 0xbf, 0xbd,
0xef, 0xbf, 0xbd, 0xef, 0xbf, 0xbd,
0xef, 0xbf, 0xbd, 0xef, 0xbf, 0xbd
]);
});
test(function textEncoder2() {
const fixture = "𝓽𝓮𝔁𝓽";
const encoder = new TextEncoder();
// prettier-ignore
assertEqual(Array.from(encoder.encode(fixture)), [
0xf0, 0x9d, 0x93, 0xbd,
0xf0, 0x9d, 0x93, 0xae,
0xf0, 0x9d, 0x94, 0x81,
0xf0, 0x9d, 0x93, 0xbd
]);
});