-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.test.ts
66 lines (57 loc) · 1.99 KB
/
utils.test.ts
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
import assert from 'assert';
import { describe, it } from 'mocha';
import { Base32StdEncoder } from '../src/base32';
import { checkEncoder, checkPadChar } from '../src/utils';
describe('Test check encoder', () => {
it('Test check encoder', () => {
assert.doesNotThrow(() => checkEncoder(Base32StdEncoder, '=', 32));
// @ts-ignore
assert.throws(() => checkEncoder(undefined, '=', 32));
assert.throws(() => checkEncoder(`${Base32StdEncoder},.`, '=', 32));
assert.throws(() => checkEncoder('å∫ç∂´ƒ©˙ˆ∆˚¬µ˜øπœ®ß†¨√∑≈¥234567', '=', 32));
assert.throws(() => checkEncoder(Base32StdEncoder, 'A', 32));
assert.throws(() => checkEncoder('ABCDEFGHIJKLMNOPQRSTUVWXYZ23456\n', '=', 32));
assert.throws(() => checkEncoder('ABCDEFGHIJKLMNOPQRSTUVWXYZ23456\r', '=', 32));
});
});
describe('Test check pad char', () => {
it('Test check valid pad char', () => {
assert.doesNotThrow(() => {
const padChar = checkPadChar('=');
assert.equal(padChar, '=');
});
// get first character only
assert.doesNotThrow(() => {
const padChar = checkPadChar('=!');
assert.equal(padChar, '=');
});
});
it('Test check empty pad char', () => {
assert.doesNotThrow(() => {
const padChar = checkPadChar('');
assert.equal(padChar, '');
});
});
it('Test check invalid pad char', () => {
assert.throws(() => checkPadChar('\n'));
assert.throws(() => checkPadChar('\r'));
assert.throws(() => checkPadChar('\uffff'));
});
it('Test check undefined or other types pad char', () => {
assert.doesNotThrow(() => {
// @ts-ignore
const padChar = checkPadChar(undefined);
assert.equal(padChar, undefined);
});
assert.doesNotThrow(() => {
// @ts-ignore
const padChar = checkPadChar(1);
assert.equal(padChar, undefined);
});
assert.doesNotThrow(() => {
// @ts-ignore
const padChar = checkPadChar({});
assert.equal(padChar, undefined);
});
});
});