diff options
author | 迷渡 <justjavac@gmail.com> | 2019-05-01 02:25:37 +0800 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-04-30 11:25:37 -0700 |
commit | bbeb30fc5e6fdb461cd219f95efcc5c52ed16f30 (patch) | |
tree | d94bbf7959c838e214f0b239026380bc566fb52a /js/text_encoding_test.ts | |
parent | a217e55fecb4ec99d89633109f6d6cff2b081424 (diff) |
Make `atob` follow the spec (#2242)
Diffstat (limited to 'js/text_encoding_test.ts')
-rw-r--r-- | js/text_encoding_test.ts | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/js/text_encoding_test.ts b/js/text_encoding_test.ts index 30a75f8d4..b5ce78a8f 100644 --- a/js/text_encoding_test.ts +++ b/js/text_encoding_test.ts @@ -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; |