mirror of
https://github.com/denoland/deno.git
synced 2024-12-23 15:49:44 -05:00
27 lines
599 B
TypeScript
27 lines
599 B
TypeScript
|
// 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");
|
||
|
});
|