69 lines
1.5 KiB
JavaScript
Raw Permalink Normal View History

2020-10-04 17:56:52 +02:00
/*
* Copyright (C) Sapphirecode - All Rights Reserved
* This file is part of encoding-helper which is released under MIT.
* See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, May 2020
*/
// @ts-nocheck
/* eslint-disable no-magic-numbers */
'use strict';
const encoding = require ('../../index');
describe ('encoding', () => {
it ('encoding to_hex', () => {
const hex = encoding.to_hex ('foo');
expect (hex)
.toEqual ('666f6f');
});
it ('encoding to_b64', () => {
const hex = encoding.to_b64 ('foo');
expect (hex)
.toEqual ('Zm9v');
});
2020-12-30 15:42:08 +01:00
it ('encoding to_b58', () => {
const hex = encoding.to_b58 ('foo');
expect (hex)
.toEqual ('bQbp');
});
2020-10-04 17:56:52 +02:00
it ('encoding to_utf8', () => {
const utf = encoding.to_utf8 ('Zm9v', 'base64');
expect (utf)
.toEqual ('foo');
});
2020-12-30 15:42:08 +01:00
it ('encoding to_utf8 from b58', () => {
const utf = encoding.to_utf8 ('bQbp', 'base58');
expect (utf)
.toEqual ('foo');
});
2020-10-04 17:56:52 +02:00
it ('convert num to hex', () => {
const res = encoding.num_to_hex (11);
expect (res)
.toEqual ('b');
});
it ('convert num to hex padded', () => {
const res = encoding.num_to_hex (11, 2);
expect (res)
.toEqual ('0b');
});
it ('convert hex to num', () => {
const res = encoding.hex_to_num ('b');
expect (res)
.toEqual (11);
});
it ('convert hex padded to num', () => {
const res = encoding.hex_to_num ('0b');
expect (res)
.toEqual (11);
});
});