Add ASCII support to TextDecoder

This commit is contained in:
Kitson Kelly 2018-12-07 10:23:29 +11:00 committed by Ryan Dahl
parent 6cc89b9e27
commit 568ac0c902
2 changed files with 127 additions and 13 deletions

View file

@ -48,6 +48,23 @@ test(function textDecoder2() {
assertEqual(decoder.decode(fixture), "𝓽𝓮𝔁𝓽");
});
test(function textDecoderASCII() {
const fixture = new Uint8Array([0x89, 0x95, 0x9f, 0xbf]);
const decoder = new TextDecoder("ascii");
assertEqual(decoder.decode(fixture), "‰•Ÿ¿");
});
test(function textDecoderErrorEncoding() {
let didThrow = false;
try {
const decoder = new TextDecoder("foo");
} catch (e) {
didThrow = true;
assertEqual(e.message, "The encoding label provided ('foo') is invalid.");
}
assert(didThrow);
});
test(function textEncoder() {
const fixture = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
const encoder = new TextEncoder();