50 lines
1.1 KiB
JavaScript
Raw Normal View History

2020-03-04 13:07:06 +01:00
/*
* Copyright (C) Sapphirecode - All Rights Reserved
2020-03-25 17:03:40 +01:00
* This file is part of Encoding-Helper which is released under MIT.
* See file 'LICENSE' for full license details.
2020-03-04 13:07:06 +01:00
* Created by Timo Hocker <timo@scode.ovh>, March 2020
*/
// @ts-nocheck
2020-04-24 16:57:50 +02:00
/* eslint-disable no-magic-numbers */
2020-03-04 13:07:06 +01:00
'use strict';
const test = require ('ava');
const encoding = require ('../index');
test ('encoding to_hex', (t) => {
const hex = encoding.to_hex ('foo');
t.is (hex, '666f6f');
});
test ('encoding to_b64', (t) => {
const hex = encoding.to_b64 ('foo');
t.is (hex, 'Zm9v');
});
test ('encoding to_utf8', (t) => {
const utf = encoding.to_utf8 ('Zm9v', 'base64');
t.is (utf, 'foo');
});
2020-04-24 16:57:50 +02:00
test ('convert num to hex', (t) => {
const res = encoding.num_to_hex (11);
t.is (res, 'b');
});
test ('convert num to hex padded', (t) => {
const res = encoding.num_to_hex (11, 2);
t.is (res, '0b');
});
test ('convert hex to num', (t) => {
const res = encoding.hex_to_num ('b');
t.is (res, 11);
});
test ('convert hex padded to num', (t) => {
const res = encoding.hex_to_num ('0b');
t.is (res, 11);
});