summaryrefslogtreecommitdiff
path: root/js/text_encoding_test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'js/text_encoding_test.ts')
-rw-r--r--js/text_encoding_test.ts37
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;