summaryrefslogtreecommitdiff
path: root/js/text_encoding_test.ts
diff options
context:
space:
mode:
authorKevin (Kun) "Kassimo" Qian <kevinkassimo@gmail.com>2018-09-20 15:53:29 -0700
committerRyan Dahl <ry@tinyclouds.org>2018-09-20 18:53:29 -0400
commit4d16d54ff85d84723b8493e6a47caf70becc6660 (patch)
tree3eff7fdb9c77717e2930a548db374e40f7547279 /js/text_encoding_test.ts
parent52d415537b6b9f6be115dca4daee3f3a36be0ce9 (diff)
Add atob() and btoa() (#776)
Diffstat (limited to 'js/text_encoding_test.ts')
-rw-r--r--js/text_encoding_test.ts26
1 files changed, 26 insertions, 0 deletions
diff --git a/js/text_encoding_test.ts b/js/text_encoding_test.ts
new file mode 100644
index 000000000..7a9aec833
--- /dev/null
+++ b/js/text_encoding_test.ts
@@ -0,0 +1,26 @@
+// Copyright 2018 the Deno authors. All rights reserved. MIT license.
+import { test, assert, assertEqual } from "./test_util.ts";
+
+test(function atobSuccess() {
+ const text = "hello world";
+ const encoded = btoa(text);
+ assertEqual(encoded, "aGVsbG8gd29ybGQ=");
+});
+
+test(function btoaSuccess() {
+ const encoded = "aGVsbG8gd29ybGQ=";
+ const decoded = atob(encoded);
+ assertEqual(decoded, "hello world");
+});
+
+test(function btoaFailed() {
+ const text = "你好";
+ let err;
+ try {
+ btoa(text);
+ } catch (e) {
+ err = e;
+ }
+ assert(!!err);
+ assertEqual(err.name, "InvalidInput");
+});