forked from soldair/node-qrcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.test.js
executable file
·73 lines (57 loc) · 1.87 KB
/
utils.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
const test = require('tap').test
const Utils = require('core/utils')
/**
* QR Code sizes. Each element refers to a version
* @type {Array}
*/
const EXPECTED_SYMBOL_SIZES = [
21, 25, 29, 33, 37, 41, 45,
49, 53, 57, 61, 65, 69, 73,
77, 81, 85, 89, 93, 97, 101,
105, 109, 113, 117, 121, 125,
129, 133, 137, 141, 145, 149,
153, 157, 161, 165, 169, 173, 177]
test('Symbol size', function (t) {
t.throws(function () { Utils.getSymbolSize() }, 'Should throw if version is undefined')
t.throws(function () { Utils.getSymbolSize(0) }, 'Should throw if version is not in range')
t.throws(function () { Utils.getSymbolSize(41) }, 'Should throw if version is not in range')
for (let i = 1; i <= 40; i++) {
t.equal(Utils.getSymbolSize(i), EXPECTED_SYMBOL_SIZES[i - 1], 'Should return correct symbol size')
}
t.end()
})
test('Symbol codewords', function (t) {
for (let i = 1; i <= 40; i++) {
t.ok(Utils.getSymbolTotalCodewords(i), 'Should return positive number')
}
t.end()
})
test('BCH Digit', function (t) {
const testData = [
{ data: 0, bch: 0 },
{ data: 1, bch: 1 },
{ data: 2, bch: 2 },
{ data: 4, bch: 3 },
{ data: 8, bch: 4 }
]
testData.forEach(function (d) {
t.equal(Utils.getBCHDigit(d.data), d.bch,
'Should return correct BCH for value: ' + d.data)
})
t.end()
})
test('Set/Get SJIS function', function (t) {
t.throws(function () { Utils.setToSJISFunction() },
'Should throw if param is not a function')
t.notOk(Utils.isKanjiModeEnabled(),
'Kanji mode should be disabled if "toSJIS" function is not set')
const testFunc = function testFunc (c) {
return 'test_' + c
}
Utils.setToSJISFunction(testFunc)
t.ok(Utils.isKanjiModeEnabled(),
'Kanji mode should be enabled if "toSJIS" function is set')
t.equal(Utils.toSJIS('a'), 'test_a',
'Should correctly call "toSJIS" function')
t.end()
})