From 554211c457523090ca8cc3a66fe47e155a806734 Mon Sep 17 00:00:00 2001
From: "[1000i100] Millicent Billette" <git@1000i100.fr>
Date: Sun, 28 Mar 2021 14:20:07 +0200
Subject: [PATCH] 100% coverage

---
 src/basex.mjs      |  4 ++--
 src/basex.test.mjs | 21 +++++++++++++++++++++
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/src/basex.mjs b/src/basex.mjs
index d09e9e8..58132ee 100644
--- a/src/basex.mjs
+++ b/src/basex.mjs
@@ -2,8 +2,8 @@
 const B58_ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
 export const b58 = basex(B58_ALPHABET);
 export const b16 = basex('0123456789abcdef');
-
-export default function basex(ALPHABET) {
+export default basex;
+export function basex(ALPHABET) {
 	const ALPHABET_MAP = {};
 	const BASE = ALPHABET.length;
 	const LEADER = ALPHABET.charAt(0);
diff --git a/src/basex.test.mjs b/src/basex.test.mjs
index 9971b3e..2cf198c 100644
--- a/src/basex.test.mjs
+++ b/src/basex.test.mjs
@@ -7,3 +7,24 @@ const pubKey = 'AoxVA41dGL2s4ogMNdbCw3FFYjFo5FPK36LuiW1tjGbG';
 test('b58 should decode/encode well', t => {
 	t.is(app.b58.encode(app.b58.decode(pubKey)), pubKey);
 });
+test('basex dont allow ambigous alphabet (each character must be unique)', t => {
+	t.throws(() => app.basex('zz'));
+});
+test('empty input empty output', t => {
+	t.is(app.b58.encode([]), '');
+});
+test('encode 0000 filled source', t => {
+	t.is(app.b16.encode([0, 0, 0, 0, 15]), '0000f');
+});
+test('decode 0000 filled source', t => {
+	t.deepEqual(app.b16.decode('0000f'), new Uint8Array([0, 0, 0, 0, 15]));
+});
+test('decode out of base chr throw error', t => {
+	t.throws(() => app.b58.decode(pubKey + 'ยง'));
+});
+test('no string decode throw', t => {
+	t.throws(() => app.b58.decode([]));
+});
+test('decode empty string => empty array', t => {
+	t.deepEqual(app.b16.decode(''), new Uint8Array(0));
+});
-- 
GitLab