From 4d16d54ff85d84723b8493e6a47caf70becc6660 Mon Sep 17 00:00:00 2001 From: "Kevin (Kun) \"Kassimo\" Qian" Date: Thu, 20 Sep 2018 15:53:29 -0700 Subject: Add atob() and btoa() (#776) --- js/text_encoding_test.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 js/text_encoding_test.ts (limited to 'js/text_encoding_test.ts') 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"); +}); -- cgit v1.2.3