-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
105 lines (98 loc) · 2.78 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import test from '@loomat/testkit'
import utils from './index.js'
const GUID_LENGHT = 36
/// CASES
const text = 'hello world!'
const hex = '68656c6c6f20776f726c6421'
const b64 = 'aGVsbG8gd29ybGQh'
const b32 = 'nbswy3dpeb3w64tmmqqq'
const buf = Buffer.from(text)
var cases = ([
// GUID
{
name: 'guid generation',
fn: () => utils.guid().length == GUID_LENGHT,
},
//CONVERSION
{
name: 'convert text to hex',
fn: () => utils.convert(text).from('text').to('hex') == hex,
},
{
name: 'convert text to b64',
fn: () => utils.convert(text).from('text').to('b64') == b64,
},
{
name: 'convert text to 32',
fn: () => utils.convert(text).from('text').to('b32') == b32,
},
{
name: 'convert text to buf',
fn: () => Buffer.compare(buf, utils.convert(text).from('text').to('buf')) == 0,
},
{
name: 'convert hex to text',
fn: () => utils.convert(hex).from('hex').to('text') == text,
},
{
name: 'convert hex to b64',
fn: () => utils.convert(hex).from('hex').to('b64') == b64,
},
{
name: 'convert hex to 32',
fn: () => utils.convert(hex).from('hex').to('b32') == b32,
},
{
name: 'convert hex to buf',
fn: () => Buffer.compare(buf, utils.convert(hex).from('hex').to('buf')) == 0,
},
{
name: 'convert b64 to text',
fn: () => utils.convert(b64).from('b64').to('text') == text,
},
{
name: 'convert b64 to hex',
fn: () => utils.convert(b64).from('b64').to('hex') == hex,
},
{
name: 'convert b64 to 32',
fn: () => utils.convert(b64).from('b64').to('b32') == b32,
},
{
name: 'convert b64 to buf',
fn: () => Buffer.compare(buf, utils.convert(b64).from('b64').to('buf')) == 0,
},
{
name: 'convert b32 to text',
fn: () => utils.convert(b32).from('b32').to('text') == text,
},
{
name: 'convert b32 to hex',
fn: () => utils.convert(b32).from('b32').to('hex') == hex,
},
{
name: 'convert b32 to b64',
fn: () => utils.convert(b32).from('b32').to('b64') == b64,
},
{
name: 'convert b32 to buf',
fn: () => Buffer.compare(buf, utils.convert(b32).from('b32').to('buf')) == 0,
},
{
name: 'convert buf to text',
fn: () => utils.convert(buf).from('buf').to('text') == text,
},
{
name: 'convert buf to hex',
fn: () => utils.convert(buf).from('buf').to('hex') == hex,
},
{
name: 'convert buf to b64',
fn: () => utils.convert(buf).from('buf').to('b64') == b64,
},
{
name: 'convert buf to b32',
fn: () => utils.convert(buf).from('buf').to('b32') == b32,
},
])
test(cases)