util.test.js
3.58 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import expect from 'expect.js';
import muk from 'muk';
import {
tenToHex,
hexToTen,
toHex,
log,
returnProc,
spliteRet,
locateOrder
}
from '../../src/lib/util';
import interfaces from '../../src/lib/interface';
describe('util.js', function() {
let util;
before(function() {
util = muk('../../src/lib/util', {
'log4js': {
loadAppender: function() {},
addAppender: function() {},
appenders: {
file: function() {}
},
getLogger: function() {
return {
error: function() {},
info: function() {},
setLevel: function() {}
}
}
}
});
});
describe('tenToHex', function() {
it('tenToHex input 12 expect c', function() {
expect(tenToHex(12)).to.be('c');
});
it('tenToHex input -12 expect fffffff4', function() {
expect(tenToHex(-12)).to.be('fffffff4');
});
it('tenToHex input 0 expect 0', function() {
expect(tenToHex(0)).to.be('0');
});
});
describe('hexToTen', function() {
it('hexToTen input FFD3 ,true expect -45', function() {
expect(hexToTen('FFD3', true)).to.be(-45);
});
it('hexToTen input FFD3 expect 65491', function() {
expect(hexToTen('FFD3')).to.be(65491);
})
});
describe('toHex', function() {
it('toHex input new Buffer("0C0D","hex") expect ["c","d"]', function() {
let input = new Buffer('0C0D', 'hex');
expect(toHex(input)).to.eql(['c', 'd']);
});
});
describe('returnProc', function() {
it('returnProc input null expect false', function() {
expect(returnProc()).to.be(false);
});
it('returnProc input [1,2] 1.1.1.1 {"1":1} expect {}', function() {
expect(returnProc([1, 2], "1.1.1.1", {
"1": 1
})).to.eql({});
});
it('returnProc input ["0", "1"], "1.1.1.1", {"01": {"message": "test","hex": "01"}}', function() {
let ret = util.returnProc(['0', '1'], '1.1.1.1', {
'01': {
'message': 'test'
}
});
expect(ret).to.eql({
'message': 'test',
'hex': '01'
});
});
});
describe('spliteRet', function() {
let mq = ['f5', 'f2', 'f3'];
let data = ['f5', '1', '3', 'f2', '2', '3', '4', 'f3', '0', '12', '2'];
it("expect ['f5','1','3'] ['f2','2','3','4'],['f3','0','12','2']", function() {
expect(spliteRet(mq, data)).to.eql({
rets: [
['f5', '1', '3'],
['f2', '2', '3', '4'],
['f3', '0', '12', '2']
],
mq: []
});
});
let mq2 = ['f1'];
let data2 = ['f1', '1', '2', 'f1', '1', '4'];
it("expect ['f1', '1', '2' ],['f1', '1', '4']", function() {
expect(spliteRet(mq2, data2)).to.eql({
rets: [
['f1', '1', '2'],
['f1', '1', '4']
],
mq: []
});
})
});
describe('locateOrder', function() {
it('input ["a0", "00", "00"] expect {key:"openUhf",val:interfaces.openUhf}', function() {
expect(locateOrder(interfaces, ['a0', '00', '00']).name).to.be('openUhf');
})
})
});