Make atob follow the spec (#2242)

This commit is contained in:
迷渡 2019-05-01 02:25:37 +08:00 committed by Ryan Dahl
parent a217e55fec
commit bbeb30fc5e
2 changed files with 53 additions and 8 deletions

View file

@ -13,6 +13,43 @@ test(function atobSuccess(): void {
assertEquals(decoded, "hello world");
});
test(function atobWithAsciiWhitespace(): void {
const encodedList = [
" aGVsbG8gd29ybGQ=",
" aGVsbG8gd29ybGQ=",
"aGVsbG8gd29ybGQ= ",
"aGVsbG8gd29ybGQ=\n",
"aGVsbG\t8gd29ybGQ=",
`aGVsbG\t8g
d29ybGQ=`
];
for (let encoded of encodedList) {
let decoded = atob(encoded);
assertEquals(decoded, "hello world");
}
});
test(function atobThrows(): void {
let threw = false;
try {
atob("aGVsbG8gd29ybGQ==");
} catch (e) {
threw = true;
}
assert(threw);
});
test(function atobThrows2(): void {
let threw = false;
try {
atob("aGVsbG8gd29ybGQ===");
} catch (e) {
threw = true;
}
assert(threw);
});
test(function btoaFailed(): void {
const text = "你好";
let err;