From bbeb30fc5e6fdb461cd219f95efcc5c52ed16f30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BF=B7=E6=B8=A1?= Date: Wed, 1 May 2019 02:25:37 +0800 Subject: Make `atob` follow the spec (#2242) --- js/text_encoding_test.ts | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'js/text_encoding_test.ts') 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; -- cgit v1.2.3