tests/utils/mask.test.js   A
last analyzed

Complexity

Total Complexity 5
Complexity/F 1

Size

Lines of Code 42
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 26
mnd 0
bc 0
fnc 5
dl 0
loc 42
bpm 0
cpm 1
noi 0
c 0
b 0
f 0
rs 10
1
import { assert } from 'chai';
2
import { load } from '../utils';
3
4
const { Mask } = load('utils.js');
5
6
suite('utils: Mask');
7
8
const mask = new Mask('aa?a-00\\0', {
9
    a : s => [ 'a', 'b', 'c' ].includes(s),
10
    0 : s => [ '1', '2', '3' ].includes(s)
11
});
12
13
test('Positive: mask', function () {
14
    const valid = [
15
        'bc-120',
16
        'bcc-310'
17
    ];
18
19
    valid.forEach(v => assert.notExists(mask.validate(v)));
20
});
21
22
test('Negative: mask', function () {
23
    assert.deepEqual(
24
        mask.validate('aaat'),
25
        {
26
            'check' : {
27
                'optional' : false,
28
                'symbol'   : '-',
29
                'type'     : 'constant'
30
            },
31
            'value' : 't'
32
        }
33
    );
34
35
    assert.deepEqual(
36
        mask.validate('aa-120k'),
37
        {
38
            'check' : null,
39
            'value' : 'k'
40
        }
41
    );
42
});
43