sportident.js 1.3.0 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/SiCard/BaseSiCard.js +45 -8
- package/SiCard/BaseSiCard.js.map +1 -1
- package/SiCard/BaseSiCard.test.js +66 -64
- package/SiCard/BaseSiCard.test.js.map +1 -1
- package/SiCard/IRaceResultData.js +2 -1
- package/SiCard/ISiCard.js +2 -1
- package/SiCard/ISiCardExamples.js +2 -1
- package/SiCard/index.js +20 -2
- package/SiCard/index.js.map +1 -1
- package/SiCard/raceResultTools.js +52 -10
- package/SiCard/raceResultTools.js.map +1 -1
- package/SiCard/raceResultTools.test.js +51 -49
- package/SiCard/raceResultTools.test.js.map +1 -1
- package/SiCard/types/FCard.js +41 -4
- package/SiCard/types/FCard.js.map +1 -1
- package/SiCard/types/FCard.test.js +13 -11
- package/SiCard/types/FCard.test.js.map +1 -1
- package/SiCard/types/ModernSiCard.js +67 -25
- package/SiCard/types/ModernSiCard.js.map +1 -1
- package/SiCard/types/ModernSiCard.test.js +104 -69
- package/SiCard/types/ModernSiCard.test.js.map +1 -1
- package/SiCard/types/PCard.js +41 -4
- package/SiCard/types/PCard.js.map +1 -1
- package/SiCard/types/PCard.test.js +13 -11
- package/SiCard/types/PCard.test.js.map +1 -1
- package/SiCard/types/SIAC.js +8 -4
- package/SiCard/types/SIAC.js.map +1 -1
- package/SiCard/types/SIAC.test.js +73 -38
- package/SiCard/types/SIAC.test.js.map +1 -1
- package/SiCard/types/SiCard10.js +8 -4
- package/SiCard/types/SiCard10.js.map +1 -1
- package/SiCard/types/SiCard10.test.js +76 -41
- package/SiCard/types/SiCard10.test.js.map +1 -1
- package/SiCard/types/SiCard11.js +8 -4
- package/SiCard/types/SiCard11.js.map +1 -1
- package/SiCard/types/SiCard11.test.js +73 -38
- package/SiCard/types/SiCard11.test.js.map +1 -1
- package/SiCard/types/SiCard5.js +55 -16
- package/SiCard/types/SiCard5.js.map +1 -1
- package/SiCard/types/SiCard5.test.js +116 -81
- package/SiCard/types/SiCard5.test.js.map +1 -1
- package/SiCard/types/SiCard6.js +56 -17
- package/SiCard/types/SiCard6.js.map +1 -1
- package/SiCard/types/SiCard6.test.js +114 -79
- package/SiCard/types/SiCard6.test.js.map +1 -1
- package/SiCard/types/SiCard8.js +54 -16
- package/SiCard/types/SiCard8.js.map +1 -1
- package/SiCard/types/SiCard8.test.js +104 -69
- package/SiCard/types/SiCard8.test.js.map +1 -1
- package/SiCard/types/SiCard9.js +53 -15
- package/SiCard/types/SiCard9.js.map +1 -1
- package/SiCard/types/SiCard9.test.js +100 -65
- package/SiCard/types/SiCard9.test.js.map +1 -1
- package/SiCard/types/TCard.js +41 -4
- package/SiCard/types/TCard.js.map +1 -1
- package/SiCard/types/TCard.test.js +13 -11
- package/SiCard/types/TCard.test.js.map +1 -1
- package/SiCard/types/index.js +33 -15
- package/SiCard/types/index.js.map +1 -1
- package/SiCard/types/index.test.js +48 -13
- package/SiCard/types/index.test.js.map +1 -1
- package/SiCard/types/modernSiCardExamples.js +58 -21
- package/SiCard/types/modernSiCardExamples.js.map +1 -1
- package/SiCard/types/siCard5Examples.js +43 -6
- package/SiCard/types/siCard5Examples.js.map +1 -1
- package/SiCard/types/siCard6Examples.js +47 -10
- package/SiCard/types/siCard6Examples.js.map +1 -1
- package/SiCard/types/siCard8Examples.js +45 -8
- package/SiCard/types/siCard8Examples.js.map +1 -1
- package/SiCard/types/siCard9Examples.js +45 -8
- package/SiCard/types/siCard9Examples.js.map +1 -1
- package/SiDevice/ISiDevice.js +45 -6
- package/SiDevice/ISiDevice.js.map +1 -1
- package/SiDevice/ISiDeviceDriver.js +41 -3
- package/SiDevice/ISiDeviceDriver.js.map +1 -1
- package/SiDevice/SiDevice.js +57 -20
- package/SiDevice/SiDevice.js.map +1 -1
- package/SiDevice/SiDevice.test.js +138 -103
- package/SiDevice/SiDevice.test.js.map +1 -1
- package/SiDevice/WebSerialSiDeviceDriver.js +49 -11
- package/SiDevice/WebSerialSiDeviceDriver.js.map +1 -1
- package/SiDevice/WebUsbSiDeviceDriver.js +49 -11
- package/SiDevice/WebUsbSiDeviceDriver.js.map +1 -1
- package/SiDevice/index.js +5 -1
- package/SiDevice/index.js.map +1 -1
- package/SiDevice/testUtils/index.js +7 -2
- package/SiDevice/testUtils/index.js.map +1 -1
- package/SiDevice/testUtils/testISiDeviceDriver.js +47 -10
- package/SiDevice/testUtils/testISiDeviceDriver.js.map +1 -1
- package/SiDevice/testUtils/testISiDeviceDriverWithAutodetection.js +52 -15
- package/SiDevice/testUtils/testISiDeviceDriverWithAutodetection.js.map +1 -1
- package/SiStation/BaseSiStation.js +55 -18
- package/SiStation/BaseSiStation.js.map +1 -1
- package/SiStation/BaseSiStation.test.js +95 -60
- package/SiStation/BaseSiStation.test.js.map +1 -1
- package/SiStation/CoupledSiStation.js +53 -16
- package/SiStation/CoupledSiStation.js.map +1 -1
- package/SiStation/CoupledSiStation.test.js +62 -27
- package/SiStation/CoupledSiStation.test.js.map +1 -1
- package/SiStation/ISiMainStation.js +43 -4
- package/SiStation/ISiMainStation.js.map +1 -1
- package/SiStation/ISiSendTask.js +5 -2
- package/SiStation/ISiSendTask.js.map +1 -1
- package/SiStation/ISiStation.js +8 -5
- package/SiStation/ISiStation.js.map +1 -1
- package/SiStation/ISiTargetMultiplexer.js +45 -6
- package/SiStation/ISiTargetMultiplexer.js.map +1 -1
- package/SiStation/SiMainStation.js +56 -19
- package/SiStation/SiMainStation.js.map +1 -1
- package/SiStation/SiMainStation.test.js +123 -88
- package/SiStation/SiMainStation.test.js.map +1 -1
- package/SiStation/SiSendTask.js +48 -11
- package/SiStation/SiSendTask.js.map +1 -1
- package/SiStation/SiTargetMultiplexer.js +83 -46
- package/SiStation/SiTargetMultiplexer.js.map +1 -1
- package/SiStation/SiTargetMultiplexer.targeting.test.js +77 -42
- package/SiStation/SiTargetMultiplexer.targeting.test.js.map +1 -1
- package/SiStation/SiTargetMultiplexer.test.js +236 -201
- package/SiStation/SiTargetMultiplexer.test.js.map +1 -1
- package/SiStation/index.js +13 -5
- package/SiStation/index.js.map +1 -1
- package/SiStation/siStationExamples.js +43 -6
- package/SiStation/siStationExamples.js.map +1 -1
- package/constants.js +7 -4
- package/constants.js.map +1 -1
- package/constants.test.js +47 -12
- package/constants.test.js.map +1 -1
- package/fakes/FakeSiCard/BaseFakeSiCard.js +5 -1
- package/fakes/FakeSiCard/BaseFakeSiCard.js.map +1 -1
- package/fakes/FakeSiCard/BaseFakeSiCard.test.js +41 -6
- package/fakes/FakeSiCard/BaseFakeSiCard.test.js.map +1 -1
- package/fakes/FakeSiCard/IFakeSiCard.js +2 -1
- package/fakes/FakeSiCard/index.js +20 -2
- package/fakes/FakeSiCard/index.js.map +1 -1
- package/fakes/FakeSiCard/types/FakeModernSiCard.js +49 -12
- package/fakes/FakeSiCard/types/FakeModernSiCard.js.map +1 -1
- package/fakes/FakeSiCard/types/FakeModernSiCard.test.js +60 -25
- package/fakes/FakeSiCard/types/FakeModernSiCard.test.js.map +1 -1
- package/fakes/FakeSiCard/types/FakeSIAC.js +12 -8
- package/fakes/FakeSiCard/types/FakeSIAC.js.map +1 -1
- package/fakes/FakeSiCard/types/FakeSiCard10.js +12 -8
- package/fakes/FakeSiCard/types/FakeSiCard10.js.map +1 -1
- package/fakes/FakeSiCard/types/FakeSiCard11.js +12 -8
- package/fakes/FakeSiCard/types/FakeSiCard11.js.map +1 -1
- package/fakes/FakeSiCard/types/FakeSiCard5.js +49 -12
- package/fakes/FakeSiCard/types/FakeSiCard5.js.map +1 -1
- package/fakes/FakeSiCard/types/FakeSiCard5.test.js +55 -20
- package/fakes/FakeSiCard/types/FakeSiCard5.test.js.map +1 -1
- package/fakes/FakeSiCard/types/FakeSiCard6.js +49 -12
- package/fakes/FakeSiCard/types/FakeSiCard6.js.map +1 -1
- package/fakes/FakeSiCard/types/FakeSiCard6.test.js +60 -25
- package/fakes/FakeSiCard/types/FakeSiCard6.test.js.map +1 -1
- package/fakes/FakeSiCard/types/FakeSiCard8.js +11 -7
- package/fakes/FakeSiCard/types/FakeSiCard8.js.map +1 -1
- package/fakes/FakeSiCard/types/FakeSiCard9.js +11 -7
- package/fakes/FakeSiCard/types/FakeSiCard9.js.map +1 -1
- package/fakes/FakeSiCard/types/index.js +17 -7
- package/fakes/FakeSiCard/types/index.js.map +1 -1
- package/fakes/FakeSiDeviceDriver.js +47 -10
- package/fakes/FakeSiDeviceDriver.js.map +1 -1
- package/fakes/FakeSiMainStation.js +66 -29
- package/fakes/FakeSiMainStation.js.map +1 -1
- package/fakes/FakeSiMainStation.test.js +78 -43
- package/fakes/FakeSiMainStation.test.js.map +1 -1
- package/fakes/IFakeSiMainStation.js +39 -2
- package/fakes/IFakeSiMainStation.js.map +1 -1
- package/fakes/index.js +20 -2
- package/fakes/index.js.map +1 -1
- package/index.js +46 -10
- package/index.js.map +1 -1
- package/package.json +2 -3
- package/siProtocol.js +83 -36
- package/siProtocol.js.map +1 -1
- package/siProtocol.test.js +345 -308
- package/siProtocol.test.js.map +1 -1
- package/storage/SiArray.js +8 -4
- package/storage/SiArray.js.map +1 -1
- package/storage/SiArray.test.js +58 -56
- package/storage/SiArray.test.js.map +1 -1
- package/storage/SiBool.js +9 -5
- package/storage/SiBool.js.map +1 -1
- package/storage/SiBool.test.js +65 -63
- package/storage/SiBool.test.js.map +1 -1
- package/storage/SiDataType.js +14 -9
- package/storage/SiDataType.js.map +1 -1
- package/storage/SiDataType.test.js +25 -23
- package/storage/SiDataType.test.js.map +1 -1
- package/storage/SiDict.js +8 -4
- package/storage/SiDict.js.map +1 -1
- package/storage/SiDict.test.js +54 -52
- package/storage/SiDict.test.js.map +1 -1
- package/storage/SiEnum.js +44 -7
- package/storage/SiEnum.js.map +1 -1
- package/storage/SiEnum.test.js +61 -59
- package/storage/SiEnum.test.js.map +1 -1
- package/storage/SiFieldValue.js +8 -4
- package/storage/SiFieldValue.js.map +1 -1
- package/storage/SiFieldValue.test.js +27 -25
- package/storage/SiFieldValue.test.js.map +1 -1
- package/storage/SiInt.js +9 -5
- package/storage/SiInt.js.map +1 -1
- package/storage/SiInt.test.js +65 -63
- package/storage/SiInt.test.js.map +1 -1
- package/storage/SiModified.js +9 -5
- package/storage/SiModified.js.map +1 -1
- package/storage/SiModified.test.js +77 -75
- package/storage/SiModified.test.js.map +1 -1
- package/storage/SiStorage.js +9 -4
- package/storage/SiStorage.js.map +1 -1
- package/storage/SiStorage.test.js +67 -32
- package/storage/SiStorage.test.js.map +1 -1
- package/storage/index.js +28 -11
- package/storage/index.js.map +1 -1
- package/storage/index.test.js +128 -93
- package/storage/index.test.js.map +1 -1
- package/storage/interfaces.js +41 -3
- package/storage/interfaces.js.map +1 -1
- package/storage/siStringEncoding.js +5 -1
- package/storage/siStringEncoding.js.map +1 -1
- package/testUtils.js +28 -16
- package/testUtils.js.map +1 -1
- package/testUtils.test.js +100 -65
- package/testUtils.test.js.map +1 -1
- package/utils/NumberRange.js +6 -2
- package/utils/NumberRange.js.map +1 -1
- package/utils/NumberRange.test.js +56 -54
- package/utils/NumberRange.test.js.map +1 -1
- package/utils/NumberRangeRegistry.js +42 -5
- package/utils/NumberRangeRegistry.js.map +1 -1
- package/utils/NumberRangeRegistry.test.js +37 -35
- package/utils/NumberRangeRegistry.test.js.map +1 -1
- package/utils/bytes.js +22 -11
- package/utils/bytes.js.map +1 -1
- package/utils/bytes.test.js +133 -98
- package/utils/bytes.test.js.map +1 -1
- package/utils/errors.js +11 -4
- package/utils/errors.js.map +1 -1
- package/utils/errors.test.js +51 -16
- package/utils/errors.test.js.map +1 -1
- package/utils/events.js +41 -3
- package/utils/events.js.map +1 -1
- package/utils/events.test.js +56 -21
- package/utils/events.test.js.map +1 -1
- package/utils/general.js +11 -4
- package/utils/general.js.map +1 -1
- package/utils/general.test.js +112 -77
- package/utils/general.test.js.map +1 -1
- package/utils/index.js +24 -8
- package/utils/index.js.map +1 -1
- package/utils/mixins.js +5 -1
- package/utils/mixins.js.map +1 -1
- package/utils/mixins.test.js +48 -13
- package/utils/mixins.test.js.map +1 -1
- package/utils/typed.js +4 -1
- package/utils/typed.js.map +1 -1
package/siProtocol.test.js
CHANGED
|
@@ -1,10 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.getValidButIncompleteMessageBytes = void 0;
|
|
37
|
+
const globals_1 = require("@jest/globals");
|
|
38
|
+
const immutable_1 = require("immutable");
|
|
39
|
+
const constants_1 = require("./constants");
|
|
40
|
+
const utils = __importStar(require("./utils"));
|
|
41
|
+
const storage = __importStar(require("./storage"));
|
|
42
|
+
const testUtils = __importStar(require("./testUtils"));
|
|
43
|
+
const siProtocol = __importStar(require("./siProtocol"));
|
|
8
44
|
const json2date = (str) => {
|
|
9
45
|
const res = /^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})\.([0-9]{3})Z$/.exec(str);
|
|
10
46
|
if (!res) {
|
|
@@ -25,7 +61,7 @@ const date2json = (date) => {
|
|
|
25
61
|
const milliseconds = date.getMilliseconds();
|
|
26
62
|
return new Date(Date.UTC(year, month, day, hours, minutes, seconds, milliseconds)).toJSON();
|
|
27
63
|
};
|
|
28
|
-
|
|
64
|
+
const getValidButIncompleteMessageBytes = () => {
|
|
29
65
|
const cutOffCommands = [];
|
|
30
66
|
const appendCutOffCommands = (command) => {
|
|
31
67
|
Array.from({ length: command.length }, (_, i) => i).forEach((cutOffLength) => {
|
|
@@ -38,445 +74,446 @@ export const getValidButIncompleteMessageBytes = () => {
|
|
|
38
74
|
appendCutOffCommands(getRandomMessageBytes(2));
|
|
39
75
|
return cutOffCommands;
|
|
40
76
|
};
|
|
41
|
-
|
|
77
|
+
exports.getValidButIncompleteMessageBytes = getValidButIncompleteMessageBytes;
|
|
78
|
+
(0, globals_1.describe)('siProtocol', () => {
|
|
42
79
|
const asOf = new Date('2020-01-01T00:00:00.000Z');
|
|
43
|
-
test('arr2date works', () => {
|
|
44
|
-
expect(date2json(siProtocol.arr2date([0x00, 0x01, 0x01], asOf))).toBe('2000-01-01T00:00:00.000Z');
|
|
45
|
-
expect(date2json(siProtocol.arr2date([0x01, 0x02, 0x03], asOf))).toBe('2001-02-03T00:00:00.000Z');
|
|
46
|
-
expect(date2json(siProtocol.arr2date([0x01, 0x0c, 0x1f], asOf))).toBe('2001-12-31T00:00:00.000Z');
|
|
47
|
-
expect(date2json(siProtocol.arr2date([0x14, 0x0c, 0x1f], asOf))).toBe('2020-12-31T00:00:00.000Z');
|
|
48
|
-
expect(date2json(siProtocol.arr2date([0x15, 0x01, 0x01], asOf))).toBe('1921-01-01T00:00:00.000Z');
|
|
49
|
-
expect(date2json(siProtocol.arr2date([0x63, 0x0c, 0x1f], asOf))).toBe('1999-12-31T00:00:00.000Z');
|
|
50
|
-
expect(date2json(siProtocol.arr2date([0x00, 0x01, 0x01, 0x00, 0x00, 0x00], asOf))).toBe('2000-01-01T00:00:00.000Z');
|
|
51
|
-
expect(date2json(siProtocol.arr2date([0x14, 0x0c, 0x1f, 0x01, 0x00, 0x00], asOf))).toBe('2020-12-31T12:00:00.000Z');
|
|
52
|
-
expect(date2json(siProtocol.arr2date([0x15, 0x0c, 0x1f, 0x01, 0x00, 0x00], asOf))).toBe('1921-12-31T12:00:00.000Z');
|
|
53
|
-
expect(date2json(siProtocol.arr2date([0x63, 0x0c, 0x1f, 0x01, 0x00, 0x00], asOf))).toBe('1999-12-31T12:00:00.000Z');
|
|
54
|
-
expect(date2json(siProtocol.arr2date([0x00, 0x01, 0x01, 0x00, 0xa8, 0xbf], asOf))).toBe('2000-01-01T11:59:59.000Z');
|
|
55
|
-
expect(date2json(siProtocol.arr2date([0x63, 0x0c, 0x1f, 0x01, 0xa8, 0xbf], asOf))).toBe('1999-12-31T23:59:59.000Z');
|
|
56
|
-
expect(date2json(siProtocol.arr2date([0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00], asOf))).toBe('2000-01-01T00:00:00.000Z');
|
|
57
|
-
expect(date2json(siProtocol.arr2date([0x14, 0x0c, 0x1f, 0x01, 0x00, 0x00, 0x20], asOf))).toBe('2020-12-31T12:00:00.125Z');
|
|
58
|
-
expect(date2json(siProtocol.arr2date([0x15, 0x0c, 0x1f, 0x01, 0x00, 0x00, 0x60], asOf))).toBe('1921-12-31T12:00:00.375Z');
|
|
59
|
-
expect(date2json(siProtocol.arr2date([0x63, 0x0c, 0x1f, 0x01, 0x00, 0x00, 0x80], asOf))).toBe('1999-12-31T12:00:00.500Z');
|
|
60
|
-
expect(date2json(siProtocol.arr2date([0x00, 0x01, 0x01, 0x00, 0xa8, 0xbf, 0x40], asOf))).toBe('2000-01-01T11:59:59.250Z');
|
|
61
|
-
expect(date2json(siProtocol.arr2date([0x63, 0x0c, 0x1f, 0x01, 0xa8, 0xbf, 0xc0], asOf))).toBe('1999-12-31T23:59:59.750Z');
|
|
80
|
+
(0, globals_1.test)('arr2date works', () => {
|
|
81
|
+
(0, globals_1.expect)(date2json(siProtocol.arr2date([0x00, 0x01, 0x01], asOf))).toBe('2000-01-01T00:00:00.000Z');
|
|
82
|
+
(0, globals_1.expect)(date2json(siProtocol.arr2date([0x01, 0x02, 0x03], asOf))).toBe('2001-02-03T00:00:00.000Z');
|
|
83
|
+
(0, globals_1.expect)(date2json(siProtocol.arr2date([0x01, 0x0c, 0x1f], asOf))).toBe('2001-12-31T00:00:00.000Z');
|
|
84
|
+
(0, globals_1.expect)(date2json(siProtocol.arr2date([0x14, 0x0c, 0x1f], asOf))).toBe('2020-12-31T00:00:00.000Z');
|
|
85
|
+
(0, globals_1.expect)(date2json(siProtocol.arr2date([0x15, 0x01, 0x01], asOf))).toBe('1921-01-01T00:00:00.000Z');
|
|
86
|
+
(0, globals_1.expect)(date2json(siProtocol.arr2date([0x63, 0x0c, 0x1f], asOf))).toBe('1999-12-31T00:00:00.000Z');
|
|
87
|
+
(0, globals_1.expect)(date2json(siProtocol.arr2date([0x00, 0x01, 0x01, 0x00, 0x00, 0x00], asOf))).toBe('2000-01-01T00:00:00.000Z');
|
|
88
|
+
(0, globals_1.expect)(date2json(siProtocol.arr2date([0x14, 0x0c, 0x1f, 0x01, 0x00, 0x00], asOf))).toBe('2020-12-31T12:00:00.000Z');
|
|
89
|
+
(0, globals_1.expect)(date2json(siProtocol.arr2date([0x15, 0x0c, 0x1f, 0x01, 0x00, 0x00], asOf))).toBe('1921-12-31T12:00:00.000Z');
|
|
90
|
+
(0, globals_1.expect)(date2json(siProtocol.arr2date([0x63, 0x0c, 0x1f, 0x01, 0x00, 0x00], asOf))).toBe('1999-12-31T12:00:00.000Z');
|
|
91
|
+
(0, globals_1.expect)(date2json(siProtocol.arr2date([0x00, 0x01, 0x01, 0x00, 0xa8, 0xbf], asOf))).toBe('2000-01-01T11:59:59.000Z');
|
|
92
|
+
(0, globals_1.expect)(date2json(siProtocol.arr2date([0x63, 0x0c, 0x1f, 0x01, 0xa8, 0xbf], asOf))).toBe('1999-12-31T23:59:59.000Z');
|
|
93
|
+
(0, globals_1.expect)(date2json(siProtocol.arr2date([0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00], asOf))).toBe('2000-01-01T00:00:00.000Z');
|
|
94
|
+
(0, globals_1.expect)(date2json(siProtocol.arr2date([0x14, 0x0c, 0x1f, 0x01, 0x00, 0x00, 0x20], asOf))).toBe('2020-12-31T12:00:00.125Z');
|
|
95
|
+
(0, globals_1.expect)(date2json(siProtocol.arr2date([0x15, 0x0c, 0x1f, 0x01, 0x00, 0x00, 0x60], asOf))).toBe('1921-12-31T12:00:00.375Z');
|
|
96
|
+
(0, globals_1.expect)(date2json(siProtocol.arr2date([0x63, 0x0c, 0x1f, 0x01, 0x00, 0x00, 0x80], asOf))).toBe('1999-12-31T12:00:00.500Z');
|
|
97
|
+
(0, globals_1.expect)(date2json(siProtocol.arr2date([0x00, 0x01, 0x01, 0x00, 0xa8, 0xbf, 0x40], asOf))).toBe('2000-01-01T11:59:59.250Z');
|
|
98
|
+
(0, globals_1.expect)(date2json(siProtocol.arr2date([0x63, 0x0c, 0x1f, 0x01, 0xa8, 0xbf, 0xc0], asOf))).toBe('1999-12-31T23:59:59.750Z');
|
|
62
99
|
});
|
|
63
|
-
test('arr2date sanitizes', () => {
|
|
64
|
-
expect(() => siProtocol.arr2date([], asOf)).toThrow();
|
|
65
|
-
expect(() => siProtocol.arr2date([0x100], asOf)).toThrow();
|
|
66
|
-
expect(() => siProtocol.arr2date([0x123, 0x123], asOf)).toThrow();
|
|
67
|
-
expect(() => siProtocol.arr2date([1, 2, 3, 4], asOf)).toThrow();
|
|
68
|
-
expect(() => siProtocol.arr2date([1, 2, 3, 4, 5], asOf)).toThrow();
|
|
69
|
-
expect(() => siProtocol.arr2date([1, 2, 3, 4, 5, 6, 7, 8], asOf)).toThrow();
|
|
70
|
-
expect(siProtocol.arr2date([100, 1, 1], asOf)).toBe(undefined);
|
|
71
|
-
expect(siProtocol.arr2date([0xff, 1, 1], asOf)).toBe(undefined);
|
|
72
|
-
expect(siProtocol.arr2date([12, 0, 1], asOf)).toBe(undefined);
|
|
73
|
-
expect(siProtocol.arr2date([12, 13, 1], asOf)).toBe(undefined);
|
|
74
|
-
expect(siProtocol.arr2date([12, 0xff, 1], asOf)).toBe(undefined);
|
|
100
|
+
(0, globals_1.test)('arr2date sanitizes', () => {
|
|
101
|
+
(0, globals_1.expect)(() => siProtocol.arr2date([], asOf)).toThrow();
|
|
102
|
+
(0, globals_1.expect)(() => siProtocol.arr2date([0x100], asOf)).toThrow();
|
|
103
|
+
(0, globals_1.expect)(() => siProtocol.arr2date([0x123, 0x123], asOf)).toThrow();
|
|
104
|
+
(0, globals_1.expect)(() => siProtocol.arr2date([1, 2, 3, 4], asOf)).toThrow();
|
|
105
|
+
(0, globals_1.expect)(() => siProtocol.arr2date([1, 2, 3, 4, 5], asOf)).toThrow();
|
|
106
|
+
(0, globals_1.expect)(() => siProtocol.arr2date([1, 2, 3, 4, 5, 6, 7, 8], asOf)).toThrow();
|
|
107
|
+
(0, globals_1.expect)(siProtocol.arr2date([100, 1, 1], asOf)).toBe(undefined);
|
|
108
|
+
(0, globals_1.expect)(siProtocol.arr2date([0xff, 1, 1], asOf)).toBe(undefined);
|
|
109
|
+
(0, globals_1.expect)(siProtocol.arr2date([12, 0, 1], asOf)).toBe(undefined);
|
|
110
|
+
(0, globals_1.expect)(siProtocol.arr2date([12, 13, 1], asOf)).toBe(undefined);
|
|
111
|
+
(0, globals_1.expect)(siProtocol.arr2date([12, 0xff, 1], asOf)).toBe(undefined);
|
|
75
112
|
});
|
|
76
|
-
test('arr2date without asOf', () => {
|
|
77
|
-
expect(date2json(siProtocol.arr2date([0x00, 0x01, 0x01]))).toBe('2000-01-01T00:00:00.000Z');
|
|
113
|
+
(0, globals_1.test)('arr2date without asOf', () => {
|
|
114
|
+
(0, globals_1.expect)(date2json(siProtocol.arr2date([0x00, 0x01, 0x01]))).toBe('2000-01-01T00:00:00.000Z');
|
|
78
115
|
});
|
|
79
|
-
test('date2arr', () => {
|
|
80
|
-
expect(siProtocol.date2arr(json2date('2000-01-01T00:00:00.000Z'))).toEqual([0x00, 0x01, 0x01, 0x0c, 0x00, 0x00, 0x00]);
|
|
81
|
-
expect(siProtocol.date2arr(json2date('2000-01-01T12:00:00.000Z'))).toEqual([0x00, 0x01, 0x01, 0x0d, 0x00, 0x00, 0x00]);
|
|
82
|
-
expect(siProtocol.date2arr(json2date('2000-01-02T00:00:00.000Z'))).toEqual([0x00, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00]);
|
|
83
|
-
expect(siProtocol.date2arr(json2date('2000-01-02T12:00:00.000Z'))).toEqual([0x00, 0x01, 0x02, 0x01, 0x00, 0x00, 0x00]);
|
|
84
|
-
expect(siProtocol.date2arr(json2date('2000-01-03T00:00:00.000Z'))).toEqual([0x00, 0x01, 0x03, 0x02, 0x00, 0x00, 0x00]);
|
|
85
|
-
expect(siProtocol.date2arr(json2date('2000-01-03T12:00:00.000Z'))).toEqual([0x00, 0x01, 0x03, 0x03, 0x00, 0x00, 0x00]);
|
|
86
|
-
expect(siProtocol.date2arr(json2date('2000-01-04T00:00:00.000Z'))).toEqual([0x00, 0x01, 0x04, 0x04, 0x00, 0x00, 0x00]);
|
|
87
|
-
expect(siProtocol.date2arr(json2date('2000-01-04T12:00:00.000Z'))).toEqual([0x00, 0x01, 0x04, 0x05, 0x00, 0x00, 0x00]);
|
|
88
|
-
expect(siProtocol.date2arr(json2date('2000-01-05T00:00:00.000Z'))).toEqual([0x00, 0x01, 0x05, 0x06, 0x00, 0x00, 0x00]);
|
|
89
|
-
expect(siProtocol.date2arr(json2date('2000-01-05T12:00:00.000Z'))).toEqual([0x00, 0x01, 0x05, 0x07, 0x00, 0x00, 0x00]);
|
|
90
|
-
expect(siProtocol.date2arr(json2date('2000-01-06T00:00:00.000Z'))).toEqual([0x00, 0x01, 0x06, 0x08, 0x00, 0x00, 0x00]);
|
|
91
|
-
expect(siProtocol.date2arr(json2date('2000-01-06T12:00:00.000Z'))).toEqual([0x00, 0x01, 0x06, 0x09, 0x00, 0x00, 0x00]);
|
|
92
|
-
expect(siProtocol.date2arr(json2date('2000-01-07T00:00:00.000Z'))).toEqual([0x00, 0x01, 0x07, 0x0a, 0x00, 0x00, 0x00]);
|
|
93
|
-
expect(siProtocol.date2arr(json2date('2000-01-07T12:00:00.000Z'))).toEqual([0x00, 0x01, 0x07, 0x0b, 0x00, 0x00, 0x00]);
|
|
94
|
-
expect(siProtocol.date2arr(json2date('2099-12-31T12:00:00.500Z'))).toEqual([0x63, 0x0c, 0x1f, 0x09, 0x00, 0x00, 0x80]);
|
|
95
|
-
expect(siProtocol.date2arr(json2date('2000-01-01T11:59:59.250Z'))).toEqual([0x00, 0x01, 0x01, 0x0c, 0xa8, 0xbf, 0x40]);
|
|
96
|
-
expect(siProtocol.date2arr(json2date('1999-12-31T23:59:59.750Z'))).toEqual([0x63, 0x0c, 0x1f, 0x0b, 0xa8, 0xbf, 0xc0]);
|
|
116
|
+
(0, globals_1.test)('date2arr', () => {
|
|
117
|
+
(0, globals_1.expect)(siProtocol.date2arr(json2date('2000-01-01T00:00:00.000Z'))).toEqual([0x00, 0x01, 0x01, 0x0c, 0x00, 0x00, 0x00]);
|
|
118
|
+
(0, globals_1.expect)(siProtocol.date2arr(json2date('2000-01-01T12:00:00.000Z'))).toEqual([0x00, 0x01, 0x01, 0x0d, 0x00, 0x00, 0x00]);
|
|
119
|
+
(0, globals_1.expect)(siProtocol.date2arr(json2date('2000-01-02T00:00:00.000Z'))).toEqual([0x00, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00]);
|
|
120
|
+
(0, globals_1.expect)(siProtocol.date2arr(json2date('2000-01-02T12:00:00.000Z'))).toEqual([0x00, 0x01, 0x02, 0x01, 0x00, 0x00, 0x00]);
|
|
121
|
+
(0, globals_1.expect)(siProtocol.date2arr(json2date('2000-01-03T00:00:00.000Z'))).toEqual([0x00, 0x01, 0x03, 0x02, 0x00, 0x00, 0x00]);
|
|
122
|
+
(0, globals_1.expect)(siProtocol.date2arr(json2date('2000-01-03T12:00:00.000Z'))).toEqual([0x00, 0x01, 0x03, 0x03, 0x00, 0x00, 0x00]);
|
|
123
|
+
(0, globals_1.expect)(siProtocol.date2arr(json2date('2000-01-04T00:00:00.000Z'))).toEqual([0x00, 0x01, 0x04, 0x04, 0x00, 0x00, 0x00]);
|
|
124
|
+
(0, globals_1.expect)(siProtocol.date2arr(json2date('2000-01-04T12:00:00.000Z'))).toEqual([0x00, 0x01, 0x04, 0x05, 0x00, 0x00, 0x00]);
|
|
125
|
+
(0, globals_1.expect)(siProtocol.date2arr(json2date('2000-01-05T00:00:00.000Z'))).toEqual([0x00, 0x01, 0x05, 0x06, 0x00, 0x00, 0x00]);
|
|
126
|
+
(0, globals_1.expect)(siProtocol.date2arr(json2date('2000-01-05T12:00:00.000Z'))).toEqual([0x00, 0x01, 0x05, 0x07, 0x00, 0x00, 0x00]);
|
|
127
|
+
(0, globals_1.expect)(siProtocol.date2arr(json2date('2000-01-06T00:00:00.000Z'))).toEqual([0x00, 0x01, 0x06, 0x08, 0x00, 0x00, 0x00]);
|
|
128
|
+
(0, globals_1.expect)(siProtocol.date2arr(json2date('2000-01-06T12:00:00.000Z'))).toEqual([0x00, 0x01, 0x06, 0x09, 0x00, 0x00, 0x00]);
|
|
129
|
+
(0, globals_1.expect)(siProtocol.date2arr(json2date('2000-01-07T00:00:00.000Z'))).toEqual([0x00, 0x01, 0x07, 0x0a, 0x00, 0x00, 0x00]);
|
|
130
|
+
(0, globals_1.expect)(siProtocol.date2arr(json2date('2000-01-07T12:00:00.000Z'))).toEqual([0x00, 0x01, 0x07, 0x0b, 0x00, 0x00, 0x00]);
|
|
131
|
+
(0, globals_1.expect)(siProtocol.date2arr(json2date('2099-12-31T12:00:00.500Z'))).toEqual([0x63, 0x0c, 0x1f, 0x09, 0x00, 0x00, 0x80]);
|
|
132
|
+
(0, globals_1.expect)(siProtocol.date2arr(json2date('2000-01-01T11:59:59.250Z'))).toEqual([0x00, 0x01, 0x01, 0x0c, 0xa8, 0xbf, 0x40]);
|
|
133
|
+
(0, globals_1.expect)(siProtocol.date2arr(json2date('1999-12-31T23:59:59.750Z'))).toEqual([0x63, 0x0c, 0x1f, 0x0b, 0xa8, 0xbf, 0xc0]);
|
|
97
134
|
});
|
|
98
|
-
test('date2arr and arr2date do the reverse', () => {
|
|
135
|
+
(0, globals_1.test)('date2arr and arr2date do the reverse', () => {
|
|
99
136
|
const forthAndBack = (date) => siProtocol.arr2date(siProtocol.date2arr(date), asOf);
|
|
100
137
|
const forthAndBackAsJson = (str) => date2json(forthAndBack(json2date(str)));
|
|
101
|
-
expect(forthAndBackAsJson('2000-01-01T00:00:00.000Z')).toBe('2000-01-01T00:00:00.000Z');
|
|
102
|
-
expect(forthAndBackAsJson('2001-02-03T00:00:00.000Z')).toBe('2001-02-03T00:00:00.000Z');
|
|
103
|
-
expect(forthAndBackAsJson('2001-12-31T00:00:00.000Z')).toBe('2001-12-31T00:00:00.000Z');
|
|
104
|
-
expect(forthAndBackAsJson('2020-12-31T00:00:00.000Z')).toBe('2020-12-31T00:00:00.000Z');
|
|
105
|
-
expect(forthAndBackAsJson('1921-01-01T00:00:00.000Z')).toBe('1921-01-01T00:00:00.000Z');
|
|
106
|
-
expect(forthAndBackAsJson('1999-12-31T00:00:00.000Z')).toBe('1999-12-31T00:00:00.000Z');
|
|
107
|
-
expect(forthAndBackAsJson('2000-01-01T06:30:00.000Z')).toBe('2000-01-01T06:30:00.000Z');
|
|
108
|
-
expect(forthAndBackAsJson('2020-12-31T13:27:30.000Z')).toBe('2020-12-31T13:27:30.000Z');
|
|
109
|
-
expect(forthAndBackAsJson('1921-12-31T12:00:00.000Z')).toBe('1921-12-31T12:00:00.000Z');
|
|
110
|
-
expect(forthAndBackAsJson('1999-12-31T12:00:00.000Z')).toBe('1999-12-31T12:00:00.000Z');
|
|
111
|
-
expect(forthAndBackAsJson('2000-01-01T11:59:59.000Z')).toBe('2000-01-01T11:59:59.000Z');
|
|
112
|
-
expect(forthAndBackAsJson('1999-12-31T23:59:59.000Z')).toBe('1999-12-31T23:59:59.000Z');
|
|
113
|
-
expect(forthAndBackAsJson('2000-01-01T00:00:00.000Z')).toBe('2000-01-01T00:00:00.000Z');
|
|
114
|
-
expect(forthAndBackAsJson('2020-12-31T12:00:00.125Z')).toBe('2020-12-31T12:00:00.125Z');
|
|
115
|
-
expect(forthAndBackAsJson('1921-12-31T12:00:00.375Z')).toBe('1921-12-31T12:00:00.375Z');
|
|
116
|
-
expect(forthAndBackAsJson('1999-12-31T12:00:00.500Z')).toBe('1999-12-31T12:00:00.500Z');
|
|
117
|
-
expect(forthAndBackAsJson('2000-01-01T11:59:59.250Z')).toBe('2000-01-01T11:59:59.250Z');
|
|
118
|
-
expect(forthAndBackAsJson('1999-12-31T23:59:59.750Z')).toBe('1999-12-31T23:59:59.750Z');
|
|
138
|
+
(0, globals_1.expect)(forthAndBackAsJson('2000-01-01T00:00:00.000Z')).toBe('2000-01-01T00:00:00.000Z');
|
|
139
|
+
(0, globals_1.expect)(forthAndBackAsJson('2001-02-03T00:00:00.000Z')).toBe('2001-02-03T00:00:00.000Z');
|
|
140
|
+
(0, globals_1.expect)(forthAndBackAsJson('2001-12-31T00:00:00.000Z')).toBe('2001-12-31T00:00:00.000Z');
|
|
141
|
+
(0, globals_1.expect)(forthAndBackAsJson('2020-12-31T00:00:00.000Z')).toBe('2020-12-31T00:00:00.000Z');
|
|
142
|
+
(0, globals_1.expect)(forthAndBackAsJson('1921-01-01T00:00:00.000Z')).toBe('1921-01-01T00:00:00.000Z');
|
|
143
|
+
(0, globals_1.expect)(forthAndBackAsJson('1999-12-31T00:00:00.000Z')).toBe('1999-12-31T00:00:00.000Z');
|
|
144
|
+
(0, globals_1.expect)(forthAndBackAsJson('2000-01-01T06:30:00.000Z')).toBe('2000-01-01T06:30:00.000Z');
|
|
145
|
+
(0, globals_1.expect)(forthAndBackAsJson('2020-12-31T13:27:30.000Z')).toBe('2020-12-31T13:27:30.000Z');
|
|
146
|
+
(0, globals_1.expect)(forthAndBackAsJson('1921-12-31T12:00:00.000Z')).toBe('1921-12-31T12:00:00.000Z');
|
|
147
|
+
(0, globals_1.expect)(forthAndBackAsJson('1999-12-31T12:00:00.000Z')).toBe('1999-12-31T12:00:00.000Z');
|
|
148
|
+
(0, globals_1.expect)(forthAndBackAsJson('2000-01-01T11:59:59.000Z')).toBe('2000-01-01T11:59:59.000Z');
|
|
149
|
+
(0, globals_1.expect)(forthAndBackAsJson('1999-12-31T23:59:59.000Z')).toBe('1999-12-31T23:59:59.000Z');
|
|
150
|
+
(0, globals_1.expect)(forthAndBackAsJson('2000-01-01T00:00:00.000Z')).toBe('2000-01-01T00:00:00.000Z');
|
|
151
|
+
(0, globals_1.expect)(forthAndBackAsJson('2020-12-31T12:00:00.125Z')).toBe('2020-12-31T12:00:00.125Z');
|
|
152
|
+
(0, globals_1.expect)(forthAndBackAsJson('1921-12-31T12:00:00.375Z')).toBe('1921-12-31T12:00:00.375Z');
|
|
153
|
+
(0, globals_1.expect)(forthAndBackAsJson('1999-12-31T12:00:00.500Z')).toBe('1999-12-31T12:00:00.500Z');
|
|
154
|
+
(0, globals_1.expect)(forthAndBackAsJson('2000-01-01T11:59:59.250Z')).toBe('2000-01-01T11:59:59.250Z');
|
|
155
|
+
(0, globals_1.expect)(forthAndBackAsJson('1999-12-31T23:59:59.750Z')).toBe('1999-12-31T23:59:59.750Z');
|
|
119
156
|
});
|
|
120
|
-
test('arr2cardNumber works', () => {
|
|
121
|
-
expect(siProtocol.arr2cardNumber([0x00, 0x00, 0x00])).toBe(0x000000);
|
|
122
|
-
expect(siProtocol.arr2cardNumber([0x12, 0x34, 0x00])).toBe(0x003412);
|
|
123
|
-
expect(siProtocol.arr2cardNumber([0x12, 0x34, 0x01])).toBe(0x003412 + 1 * 100000);
|
|
124
|
-
expect(siProtocol.arr2cardNumber([0x12, 0x34, 0x02])).toBe(0x003412 + 2 * 100000);
|
|
125
|
-
expect(siProtocol.arr2cardNumber([0x12, 0x34, 0x03])).toBe(0x003412 + 3 * 100000);
|
|
126
|
-
expect(siProtocol.arr2cardNumber([0x12, 0x34, 0x04])).toBe(0x003412 + 4 * 100000);
|
|
157
|
+
(0, globals_1.test)('arr2cardNumber works', () => {
|
|
158
|
+
(0, globals_1.expect)(siProtocol.arr2cardNumber([0x00, 0x00, 0x00])).toBe(0x000000);
|
|
159
|
+
(0, globals_1.expect)(siProtocol.arr2cardNumber([0x12, 0x34, 0x00])).toBe(0x003412);
|
|
160
|
+
(0, globals_1.expect)(siProtocol.arr2cardNumber([0x12, 0x34, 0x01])).toBe(0x003412 + 1 * 100000);
|
|
161
|
+
(0, globals_1.expect)(siProtocol.arr2cardNumber([0x12, 0x34, 0x02])).toBe(0x003412 + 2 * 100000);
|
|
162
|
+
(0, globals_1.expect)(siProtocol.arr2cardNumber([0x12, 0x34, 0x03])).toBe(0x003412 + 3 * 100000);
|
|
163
|
+
(0, globals_1.expect)(siProtocol.arr2cardNumber([0x12, 0x34, 0x04])).toBe(0x003412 + 4 * 100000);
|
|
127
164
|
// the following should actually never appear, as 0x053412 = 341010, which would be represented differently
|
|
128
|
-
expect(siProtocol.arr2cardNumber([0x12, 0x34, 0x05])).toBe(0x053412);
|
|
129
|
-
expect(siProtocol.arr2cardNumber([0x12, 0x34, 0x08])).toBe(0x083412);
|
|
130
|
-
expect(siProtocol.arr2cardNumber([0x12, 0x34, 0x56])).toBe(0x563412);
|
|
131
|
-
expect(siProtocol.arr2cardNumber([0x00, 0x00, 0x00, 0x00])).toBe(0x00000000);
|
|
132
|
-
expect(siProtocol.arr2cardNumber([0x00, 0x00, 0x00, 0x01])).toBe(0x01000000);
|
|
133
|
-
expect(siProtocol.arr2cardNumber([0x12, 0x34, 0x56, 0x78])).toBe(0x78563412);
|
|
134
|
-
expect(siProtocol.arr2cardNumber([0x12, 0x34, 0x56, undefined])).toBe(undefined);
|
|
135
|
-
expect(siProtocol.arr2cardNumber([0x12, 0x34, undefined, 0x78])).toBe(undefined);
|
|
136
|
-
expect(siProtocol.arr2cardNumber([0x12, undefined, 0x56, 0x78])).toBe(undefined);
|
|
137
|
-
expect(siProtocol.arr2cardNumber([undefined, 0x34, 0x56, 0x78])).toBe(undefined);
|
|
165
|
+
(0, globals_1.expect)(siProtocol.arr2cardNumber([0x12, 0x34, 0x05])).toBe(0x053412);
|
|
166
|
+
(0, globals_1.expect)(siProtocol.arr2cardNumber([0x12, 0x34, 0x08])).toBe(0x083412);
|
|
167
|
+
(0, globals_1.expect)(siProtocol.arr2cardNumber([0x12, 0x34, 0x56])).toBe(0x563412);
|
|
168
|
+
(0, globals_1.expect)(siProtocol.arr2cardNumber([0x00, 0x00, 0x00, 0x00])).toBe(0x00000000);
|
|
169
|
+
(0, globals_1.expect)(siProtocol.arr2cardNumber([0x00, 0x00, 0x00, 0x01])).toBe(0x01000000);
|
|
170
|
+
(0, globals_1.expect)(siProtocol.arr2cardNumber([0x12, 0x34, 0x56, 0x78])).toBe(0x78563412);
|
|
171
|
+
(0, globals_1.expect)(siProtocol.arr2cardNumber([0x12, 0x34, 0x56, undefined])).toBe(undefined);
|
|
172
|
+
(0, globals_1.expect)(siProtocol.arr2cardNumber([0x12, 0x34, undefined, 0x78])).toBe(undefined);
|
|
173
|
+
(0, globals_1.expect)(siProtocol.arr2cardNumber([0x12, undefined, 0x56, 0x78])).toBe(undefined);
|
|
174
|
+
(0, globals_1.expect)(siProtocol.arr2cardNumber([undefined, 0x34, 0x56, 0x78])).toBe(undefined);
|
|
138
175
|
});
|
|
139
|
-
test('arr2cardNumber sanitizes', () => {
|
|
140
|
-
expect(() => siProtocol.arr2cardNumber([])).toThrow();
|
|
141
|
-
expect(() => siProtocol.arr2cardNumber([1])).toThrow();
|
|
142
|
-
expect(() => siProtocol.arr2cardNumber([1, 2])).toThrow();
|
|
143
|
-
expect(() => siProtocol.arr2cardNumber([1, 2, 3, 4, 5])).toThrow();
|
|
144
|
-
expect(() => siProtocol.arr2cardNumber([1, 2, 3, 4, 5, 6, 7, 8])).toThrow();
|
|
176
|
+
(0, globals_1.test)('arr2cardNumber sanitizes', () => {
|
|
177
|
+
(0, globals_1.expect)(() => siProtocol.arr2cardNumber([])).toThrow();
|
|
178
|
+
(0, globals_1.expect)(() => siProtocol.arr2cardNumber([1])).toThrow();
|
|
179
|
+
(0, globals_1.expect)(() => siProtocol.arr2cardNumber([1, 2])).toThrow();
|
|
180
|
+
(0, globals_1.expect)(() => siProtocol.arr2cardNumber([1, 2, 3, 4, 5])).toThrow();
|
|
181
|
+
(0, globals_1.expect)(() => siProtocol.arr2cardNumber([1, 2, 3, 4, 5, 6, 7, 8])).toThrow();
|
|
145
182
|
});
|
|
146
|
-
test('cardNumber2arr works', () => {
|
|
147
|
-
expect(siProtocol.cardNumber2arr(0x000000)).toEqual([0x00, 0x00, 0x00, 0x00]);
|
|
148
|
-
expect(siProtocol.cardNumber2arr(0x003412)).toEqual([0x12, 0x34, 0x00, 0x00]);
|
|
149
|
-
expect(siProtocol.cardNumber2arr(0x003412 + 1 * 100000)).toEqual([0x12, 0x34, 0x01, 0x00]);
|
|
150
|
-
expect(siProtocol.cardNumber2arr(0x003412 + 2 * 100000)).toEqual([0x12, 0x34, 0x02, 0x00]);
|
|
151
|
-
expect(siProtocol.cardNumber2arr(0x003412 + 3 * 100000)).toEqual([0x12, 0x34, 0x03, 0x00]);
|
|
152
|
-
expect(siProtocol.cardNumber2arr(0x003412 + 4 * 100000)).toEqual([0x12, 0x34, 0x04, 0x00]);
|
|
153
|
-
expect(siProtocol.cardNumber2arr(0x083412)).toEqual([0x12, 0x34, 0x08, 0x00]);
|
|
154
|
-
expect(siProtocol.cardNumber2arr(0x563412)).toEqual([0x12, 0x34, 0x56, 0x00]);
|
|
155
|
-
expect(siProtocol.cardNumber2arr(0x00000000)).toEqual([0x00, 0x00, 0x00, 0x00]);
|
|
156
|
-
expect(siProtocol.cardNumber2arr(0x01000000)).toEqual([0x00, 0x00, 0x00, 0x01]);
|
|
157
|
-
expect(siProtocol.cardNumber2arr(0x78563412)).toEqual([0x12, 0x34, 0x56, 0x78]);
|
|
158
|
-
expect(siProtocol.cardNumber2arr(undefined)).toEqual([undefined, undefined, undefined, undefined]);
|
|
183
|
+
(0, globals_1.test)('cardNumber2arr works', () => {
|
|
184
|
+
(0, globals_1.expect)(siProtocol.cardNumber2arr(0x000000)).toEqual([0x00, 0x00, 0x00, 0x00]);
|
|
185
|
+
(0, globals_1.expect)(siProtocol.cardNumber2arr(0x003412)).toEqual([0x12, 0x34, 0x00, 0x00]);
|
|
186
|
+
(0, globals_1.expect)(siProtocol.cardNumber2arr(0x003412 + 1 * 100000)).toEqual([0x12, 0x34, 0x01, 0x00]);
|
|
187
|
+
(0, globals_1.expect)(siProtocol.cardNumber2arr(0x003412 + 2 * 100000)).toEqual([0x12, 0x34, 0x02, 0x00]);
|
|
188
|
+
(0, globals_1.expect)(siProtocol.cardNumber2arr(0x003412 + 3 * 100000)).toEqual([0x12, 0x34, 0x03, 0x00]);
|
|
189
|
+
(0, globals_1.expect)(siProtocol.cardNumber2arr(0x003412 + 4 * 100000)).toEqual([0x12, 0x34, 0x04, 0x00]);
|
|
190
|
+
(0, globals_1.expect)(siProtocol.cardNumber2arr(0x083412)).toEqual([0x12, 0x34, 0x08, 0x00]);
|
|
191
|
+
(0, globals_1.expect)(siProtocol.cardNumber2arr(0x563412)).toEqual([0x12, 0x34, 0x56, 0x00]);
|
|
192
|
+
(0, globals_1.expect)(siProtocol.cardNumber2arr(0x00000000)).toEqual([0x00, 0x00, 0x00, 0x00]);
|
|
193
|
+
(0, globals_1.expect)(siProtocol.cardNumber2arr(0x01000000)).toEqual([0x00, 0x00, 0x00, 0x01]);
|
|
194
|
+
(0, globals_1.expect)(siProtocol.cardNumber2arr(0x78563412)).toEqual([0x12, 0x34, 0x56, 0x78]);
|
|
195
|
+
(0, globals_1.expect)(siProtocol.cardNumber2arr(undefined)).toEqual([undefined, undefined, undefined, undefined]);
|
|
159
196
|
});
|
|
160
|
-
test('consistent cardNumber <=> arr conversion', () => {
|
|
197
|
+
(0, globals_1.test)('consistent cardNumber <=> arr conversion', () => {
|
|
161
198
|
const cardNumbers = [1000, 10000, 65535, 100000, 165535, 200000, 265535, 300000, 365535, 400000, 465535, 500000, 599999, 999999, 1000000, 1999999, 2000000, 2999999];
|
|
162
199
|
cardNumbers.forEach((cardNumber) => {
|
|
163
200
|
const arr = siProtocol.cardNumber2arr(cardNumber);
|
|
164
201
|
const restoredCardNumber = siProtocol.arr2cardNumber(arr);
|
|
165
|
-
expect(restoredCardNumber).toEqual(cardNumber);
|
|
202
|
+
(0, globals_1.expect)(restoredCardNumber).toEqual(cardNumber);
|
|
166
203
|
});
|
|
167
204
|
});
|
|
168
|
-
test('prettyMessage', () => {
|
|
169
|
-
expect(siProtocol.prettyMessage({ command: proto.cmd.GET_MS, parameters: [] }).length > 3).toBe(true);
|
|
170
|
-
expect(siProtocol.prettyMessage({ mode: proto.ACK }).length > 3).toBe(true);
|
|
205
|
+
(0, globals_1.test)('prettyMessage', () => {
|
|
206
|
+
(0, globals_1.expect)(siProtocol.prettyMessage({ command: constants_1.proto.cmd.GET_MS, parameters: [] }).length > 3).toBe(true);
|
|
207
|
+
(0, globals_1.expect)(siProtocol.prettyMessage({ mode: constants_1.proto.ACK }).length > 3).toBe(true);
|
|
171
208
|
});
|
|
172
|
-
test('CRC16', () => {
|
|
173
|
-
expect(siProtocol.CRC16([])).toEqual([0x00, 0x00]);
|
|
174
|
-
expect(siProtocol.CRC16([0x01])).toEqual([0x01, 0x00]);
|
|
175
|
-
expect(siProtocol.CRC16([0x12])).toEqual([0x12, 0x00]);
|
|
176
|
-
expect(siProtocol.CRC16([0xff])).toEqual([0xff, 0x00]);
|
|
177
|
-
expect(siProtocol.CRC16([0x01, 0x02])).toEqual([0x01, 0x02]);
|
|
178
|
-
expect(siProtocol.CRC16([0x12, 0x34])).toEqual([0x12, 0x34]);
|
|
179
|
-
expect(siProtocol.CRC16([0x12, 0x34, 0x56])).toEqual([0xba, 0xbb]);
|
|
180
|
-
expect(siProtocol.CRC16([0x12, 0x32, 0x56])).toEqual([0xba, 0xaf]);
|
|
181
|
-
expect(siProtocol.CRC16([0x12, 0x34, 0x56, 0x78])).toEqual([0x1e, 0x83]);
|
|
182
|
-
expect(siProtocol.CRC16([0x12, 0x32, 0x56, 0x78])).toEqual([0x1e, 0xfb]);
|
|
209
|
+
(0, globals_1.test)('CRC16', () => {
|
|
210
|
+
(0, globals_1.expect)(siProtocol.CRC16([])).toEqual([0x00, 0x00]);
|
|
211
|
+
(0, globals_1.expect)(siProtocol.CRC16([0x01])).toEqual([0x01, 0x00]);
|
|
212
|
+
(0, globals_1.expect)(siProtocol.CRC16([0x12])).toEqual([0x12, 0x00]);
|
|
213
|
+
(0, globals_1.expect)(siProtocol.CRC16([0xff])).toEqual([0xff, 0x00]);
|
|
214
|
+
(0, globals_1.expect)(siProtocol.CRC16([0x01, 0x02])).toEqual([0x01, 0x02]);
|
|
215
|
+
(0, globals_1.expect)(siProtocol.CRC16([0x12, 0x34])).toEqual([0x12, 0x34]);
|
|
216
|
+
(0, globals_1.expect)(siProtocol.CRC16([0x12, 0x34, 0x56])).toEqual([0xba, 0xbb]);
|
|
217
|
+
(0, globals_1.expect)(siProtocol.CRC16([0x12, 0x32, 0x56])).toEqual([0xba, 0xaf]);
|
|
218
|
+
(0, globals_1.expect)(siProtocol.CRC16([0x12, 0x34, 0x56, 0x78])).toEqual([0x1e, 0x83]);
|
|
219
|
+
(0, globals_1.expect)(siProtocol.CRC16([0x12, 0x32, 0x56, 0x78])).toEqual([0x1e, 0xfb]);
|
|
183
220
|
});
|
|
184
|
-
test('parse WAKEUP', () => {
|
|
185
|
-
expect(siProtocol.parse([proto.WAKEUP])).toEqual({
|
|
186
|
-
message: { mode: proto.WAKEUP },
|
|
221
|
+
(0, globals_1.test)('parse WAKEUP', () => {
|
|
222
|
+
(0, globals_1.expect)(siProtocol.parse([constants_1.proto.WAKEUP])).toEqual({
|
|
223
|
+
message: { mode: constants_1.proto.WAKEUP },
|
|
187
224
|
remainder: []
|
|
188
225
|
});
|
|
189
226
|
const randomByte = testUtils.getRandomByte();
|
|
190
|
-
expect(siProtocol.parse([proto.WAKEUP, randomByte])).toEqual({
|
|
191
|
-
message: { mode: proto.WAKEUP },
|
|
227
|
+
(0, globals_1.expect)(siProtocol.parse([constants_1.proto.WAKEUP, randomByte])).toEqual({
|
|
228
|
+
message: { mode: constants_1.proto.WAKEUP },
|
|
192
229
|
remainder: [randomByte]
|
|
193
230
|
});
|
|
194
231
|
});
|
|
195
|
-
test('parse ACK', () => {
|
|
196
|
-
expect(siProtocol.parse([proto.ACK])).toEqual({
|
|
197
|
-
message: { mode: proto.ACK },
|
|
232
|
+
(0, globals_1.test)('parse ACK', () => {
|
|
233
|
+
(0, globals_1.expect)(siProtocol.parse([constants_1.proto.ACK])).toEqual({
|
|
234
|
+
message: { mode: constants_1.proto.ACK },
|
|
198
235
|
remainder: []
|
|
199
236
|
});
|
|
200
237
|
const randomByte = testUtils.getRandomByte();
|
|
201
|
-
expect(siProtocol.parse([proto.ACK, randomByte])).toEqual({
|
|
202
|
-
message: { mode: proto.ACK },
|
|
238
|
+
(0, globals_1.expect)(siProtocol.parse([constants_1.proto.ACK, randomByte])).toEqual({
|
|
239
|
+
message: { mode: constants_1.proto.ACK },
|
|
203
240
|
remainder: [randomByte]
|
|
204
241
|
});
|
|
205
242
|
});
|
|
206
|
-
test('parse NAK', () => {
|
|
207
|
-
expect(siProtocol.parse([proto.NAK])).toEqual({
|
|
208
|
-
message: { mode: proto.NAK },
|
|
243
|
+
(0, globals_1.test)('parse NAK', () => {
|
|
244
|
+
(0, globals_1.expect)(siProtocol.parse([constants_1.proto.NAK])).toEqual({
|
|
245
|
+
message: { mode: constants_1.proto.NAK },
|
|
209
246
|
remainder: []
|
|
210
247
|
});
|
|
211
248
|
const randomByte = testUtils.getRandomByte();
|
|
212
|
-
expect(siProtocol.parse([proto.NAK, randomByte])).toEqual({
|
|
213
|
-
message: { mode: proto.NAK },
|
|
249
|
+
(0, globals_1.expect)(siProtocol.parse([constants_1.proto.NAK, randomByte])).toEqual({
|
|
250
|
+
message: { mode: constants_1.proto.NAK },
|
|
214
251
|
remainder: [randomByte]
|
|
215
252
|
});
|
|
216
253
|
});
|
|
217
|
-
test('parse with invalid start byte', () => {
|
|
218
|
-
const invalidStartByte = testUtils.getRandomByteExcept([proto.STX, proto.WAKEUP, proto.NAK]);
|
|
254
|
+
(0, globals_1.test)('parse with invalid start byte', () => {
|
|
255
|
+
const invalidStartByte = testUtils.getRandomByteExcept([constants_1.proto.STX, constants_1.proto.WAKEUP, constants_1.proto.NAK]);
|
|
219
256
|
console.debug(`Chosen invalid start byte: ${utils.prettyHex([invalidStartByte])}`);
|
|
220
|
-
expect(siProtocol.parse([invalidStartByte])).toEqual({ message: null, remainder: [] });
|
|
257
|
+
(0, globals_1.expect)(siProtocol.parse([invalidStartByte])).toEqual({ message: null, remainder: [] });
|
|
221
258
|
const randomByte = testUtils.getRandomByte();
|
|
222
|
-
expect(siProtocol.parse([invalidStartByte, randomByte])).toEqual({
|
|
259
|
+
(0, globals_1.expect)(siProtocol.parse([invalidStartByte, randomByte])).toEqual({
|
|
223
260
|
message: null,
|
|
224
261
|
remainder: [randomByte]
|
|
225
262
|
});
|
|
226
263
|
});
|
|
227
|
-
test('parse command without remainder', () => {
|
|
264
|
+
(0, globals_1.test)('parse command without remainder', () => {
|
|
228
265
|
const parseForMessage = (message) => siProtocol.parse(siProtocol.render(message)).message;
|
|
229
|
-
expect(parseForMessage({ command: 0x00, parameters: [] })).toEqual({
|
|
266
|
+
(0, globals_1.expect)(parseForMessage({ command: 0x00, parameters: [] })).toEqual({
|
|
230
267
|
command: 0x00,
|
|
231
268
|
parameters: []
|
|
232
269
|
});
|
|
233
|
-
expect(parseForMessage({ command: 0xff, parameters: [0xee] })).toEqual({
|
|
270
|
+
(0, globals_1.expect)(parseForMessage({ command: 0xff, parameters: [0xee] })).toEqual({
|
|
234
271
|
command: 0xff,
|
|
235
272
|
parameters: [0xee]
|
|
236
273
|
});
|
|
237
274
|
});
|
|
238
|
-
test('parse command with remainder', () => {
|
|
275
|
+
(0, globals_1.test)('parse command with remainder', () => {
|
|
239
276
|
const parseForMessageWithRemainder = (message) => siProtocol.parse([...siProtocol.render(message), 0xdd]);
|
|
240
|
-
expect(parseForMessageWithRemainder({ command: 0x00, parameters: [] })).toEqual({
|
|
277
|
+
(0, globals_1.expect)(parseForMessageWithRemainder({ command: 0x00, parameters: [] })).toEqual({
|
|
241
278
|
message: { command: 0x00, parameters: [] },
|
|
242
279
|
remainder: [0xdd]
|
|
243
280
|
});
|
|
244
|
-
expect(parseForMessageWithRemainder({ command: 0xff, parameters: [0xee] })).toEqual({
|
|
281
|
+
(0, globals_1.expect)(parseForMessageWithRemainder({ command: 0xff, parameters: [0xee] })).toEqual({
|
|
245
282
|
message: { command: 0xff, parameters: [0xee] },
|
|
246
283
|
remainder: [0xdd]
|
|
247
284
|
});
|
|
248
285
|
});
|
|
249
|
-
test('parse incomplete but valid command', () => {
|
|
250
|
-
getValidButIncompleteMessageBytes().forEach((cutOffCommand) => {
|
|
251
|
-
expect(siProtocol.parse(cutOffCommand)).toEqual({ message: null, remainder: cutOffCommand });
|
|
286
|
+
(0, globals_1.test)('parse incomplete but valid command', () => {
|
|
287
|
+
(0, exports.getValidButIncompleteMessageBytes)().forEach((cutOffCommand) => {
|
|
288
|
+
(0, globals_1.expect)(siProtocol.parse(cutOffCommand)).toEqual({ message: null, remainder: cutOffCommand });
|
|
252
289
|
});
|
|
253
290
|
});
|
|
254
|
-
test('parse command with invalid ETX', () => {
|
|
255
|
-
const invalidETX = testUtils.getRandomByteExcept([proto.ETX]);
|
|
291
|
+
(0, globals_1.test)('parse command with invalid ETX', () => {
|
|
292
|
+
const invalidETX = testUtils.getRandomByteExcept([constants_1.proto.ETX]);
|
|
256
293
|
console.debug(`Chosen invalid ETX: ${utils.prettyHex([invalidETX])}`);
|
|
257
|
-
expect(siProtocol.parse([proto.STX, 0x00, 0x00, 0x00, 0x00, invalidETX])).toEqual({
|
|
294
|
+
(0, globals_1.expect)(siProtocol.parse([constants_1.proto.STX, 0x00, 0x00, 0x00, 0x00, invalidETX])).toEqual({
|
|
258
295
|
message: null,
|
|
259
296
|
remainder: [0x00, 0x00, 0x00, 0x00, invalidETX]
|
|
260
297
|
});
|
|
261
|
-
expect(siProtocol.parse([proto.STX, 0xff, 0x01, 0xee, 0x00, 0x01, invalidETX])).toEqual({
|
|
298
|
+
(0, globals_1.expect)(siProtocol.parse([constants_1.proto.STX, 0xff, 0x01, 0xee, 0x00, 0x01, invalidETX])).toEqual({
|
|
262
299
|
message: null,
|
|
263
300
|
remainder: [0xff, 0x01, 0xee, 0x00, 0x01, invalidETX]
|
|
264
301
|
});
|
|
265
|
-
expect(siProtocol.parse([proto.STX, 0x00, 0x00, 0x00, 0x01, invalidETX, 0xdd])).toEqual({
|
|
302
|
+
(0, globals_1.expect)(siProtocol.parse([constants_1.proto.STX, 0x00, 0x00, 0x00, 0x01, invalidETX, 0xdd])).toEqual({
|
|
266
303
|
message: null,
|
|
267
304
|
remainder: [0x00, 0x00, 0x00, 0x01, invalidETX, 0xdd]
|
|
268
305
|
});
|
|
269
|
-
expect(siProtocol.parse([proto.STX, 0xff, 0x01, 0xee, 0x00, 0x01, invalidETX, 0xdd])).toEqual({
|
|
306
|
+
(0, globals_1.expect)(siProtocol.parse([constants_1.proto.STX, 0xff, 0x01, 0xee, 0x00, 0x01, invalidETX, 0xdd])).toEqual({
|
|
270
307
|
message: null,
|
|
271
308
|
remainder: [0xff, 0x01, 0xee, 0x00, 0x01, invalidETX, 0xdd]
|
|
272
309
|
});
|
|
273
310
|
});
|
|
274
|
-
test('parse command with invalid CRC', () => {
|
|
275
|
-
expect(siProtocol.parse([proto.STX, 0x00, 0x00, 0x00, 0x01, proto.ETX])).toEqual({
|
|
311
|
+
(0, globals_1.test)('parse command with invalid CRC', () => {
|
|
312
|
+
(0, globals_1.expect)(siProtocol.parse([constants_1.proto.STX, 0x00, 0x00, 0x00, 0x01, constants_1.proto.ETX])).toEqual({
|
|
276
313
|
message: null,
|
|
277
314
|
remainder: []
|
|
278
315
|
});
|
|
279
|
-
expect(siProtocol.parse([proto.STX, 0xff, 0x01, 0xee, 0x00, 0x01, proto.ETX])).toEqual({
|
|
316
|
+
(0, globals_1.expect)(siProtocol.parse([constants_1.proto.STX, 0xff, 0x01, 0xee, 0x00, 0x01, constants_1.proto.ETX])).toEqual({
|
|
280
317
|
message: null,
|
|
281
318
|
remainder: []
|
|
282
319
|
});
|
|
283
|
-
expect(siProtocol.parse([proto.STX, 0x00, 0x00, 0x00, 0x01, proto.ETX, 0xdd])).toEqual({
|
|
320
|
+
(0, globals_1.expect)(siProtocol.parse([constants_1.proto.STX, 0x00, 0x00, 0x00, 0x01, constants_1.proto.ETX, 0xdd])).toEqual({
|
|
284
321
|
message: null,
|
|
285
322
|
remainder: [0xdd]
|
|
286
323
|
});
|
|
287
|
-
expect(siProtocol.parse([proto.STX, 0xff, 0x01, 0xee, 0x00, 0x01, proto.ETX, 0xdd])).toEqual({
|
|
324
|
+
(0, globals_1.expect)(siProtocol.parse([constants_1.proto.STX, 0xff, 0x01, 0xee, 0x00, 0x01, constants_1.proto.ETX, 0xdd])).toEqual({
|
|
288
325
|
message: null,
|
|
289
326
|
remainder: [0xdd]
|
|
290
327
|
});
|
|
291
328
|
});
|
|
292
|
-
test('parseAll without remainder', () => {
|
|
329
|
+
(0, globals_1.test)('parseAll without remainder', () => {
|
|
293
330
|
const stream0 = [];
|
|
294
|
-
expect(siProtocol.parseAll(stream0)).toEqual({
|
|
331
|
+
(0, globals_1.expect)(siProtocol.parseAll(stream0)).toEqual({
|
|
295
332
|
messages: [],
|
|
296
333
|
remainder: []
|
|
297
334
|
});
|
|
298
335
|
const stream1 = siProtocol.render({ command: 0x00, parameters: [] });
|
|
299
|
-
expect(siProtocol.parseAll(stream1)).toEqual({
|
|
336
|
+
(0, globals_1.expect)(siProtocol.parseAll(stream1)).toEqual({
|
|
300
337
|
messages: [{ command: 0x00, parameters: [] }],
|
|
301
338
|
remainder: []
|
|
302
339
|
});
|
|
303
|
-
const stream2 = [...siProtocol.render({ command: 0x00, parameters: [] }), proto.WAKEUP, ...siProtocol.render({ command: 0xff, parameters: [0xee] })];
|
|
304
|
-
expect(siProtocol.parseAll(stream2)).toEqual({
|
|
305
|
-
messages: [{ command: 0x00, parameters: [] }, { mode: proto.WAKEUP }, { command: 0xff, parameters: [0xee] }],
|
|
340
|
+
const stream2 = [...siProtocol.render({ command: 0x00, parameters: [] }), constants_1.proto.WAKEUP, ...siProtocol.render({ command: 0xff, parameters: [0xee] })];
|
|
341
|
+
(0, globals_1.expect)(siProtocol.parseAll(stream2)).toEqual({
|
|
342
|
+
messages: [{ command: 0x00, parameters: [] }, { mode: constants_1.proto.WAKEUP }, { command: 0xff, parameters: [0xee] }],
|
|
306
343
|
remainder: []
|
|
307
344
|
});
|
|
308
345
|
});
|
|
309
|
-
test('parseAll with valid remainder', () => {
|
|
310
|
-
getValidButIncompleteMessageBytes().forEach((cutOffCommand) => {
|
|
346
|
+
(0, globals_1.test)('parseAll with valid remainder', () => {
|
|
347
|
+
(0, exports.getValidButIncompleteMessageBytes)().forEach((cutOffCommand) => {
|
|
311
348
|
const stream0 = [...cutOffCommand];
|
|
312
|
-
expect(siProtocol.parseAll(stream0)).toEqual({
|
|
349
|
+
(0, globals_1.expect)(siProtocol.parseAll(stream0)).toEqual({
|
|
313
350
|
messages: [],
|
|
314
351
|
remainder: cutOffCommand
|
|
315
352
|
});
|
|
316
|
-
const stream1 = [...siProtocol.render({ command: 0x00, parameters: [] }), proto.NAK, ...cutOffCommand];
|
|
317
|
-
expect(siProtocol.parseAll(stream1)).toEqual({
|
|
318
|
-
messages: [{ command: 0x00, parameters: [] }, { mode: proto.NAK }],
|
|
353
|
+
const stream1 = [...siProtocol.render({ command: 0x00, parameters: [] }), constants_1.proto.NAK, ...cutOffCommand];
|
|
354
|
+
(0, globals_1.expect)(siProtocol.parseAll(stream1)).toEqual({
|
|
355
|
+
messages: [{ command: 0x00, parameters: [] }, { mode: constants_1.proto.NAK }],
|
|
319
356
|
remainder: cutOffCommand
|
|
320
357
|
});
|
|
321
|
-
const stream2 = [proto.WAKEUP, ...siProtocol.render({ command: 0x00, parameters: [] }), ...siProtocol.render({ command: 0xff, parameters: [0xee] }), ...cutOffCommand];
|
|
322
|
-
expect(siProtocol.parseAll(stream2)).toEqual({
|
|
323
|
-
messages: [{ mode: proto.WAKEUP }, { command: 0x00, parameters: [] }, { command: 0xff, parameters: [0xee] }],
|
|
358
|
+
const stream2 = [constants_1.proto.WAKEUP, ...siProtocol.render({ command: 0x00, parameters: [] }), ...siProtocol.render({ command: 0xff, parameters: [0xee] }), ...cutOffCommand];
|
|
359
|
+
(0, globals_1.expect)(siProtocol.parseAll(stream2)).toEqual({
|
|
360
|
+
messages: [{ mode: constants_1.proto.WAKEUP }, { command: 0x00, parameters: [] }, { command: 0xff, parameters: [0xee] }],
|
|
324
361
|
remainder: cutOffCommand
|
|
325
362
|
});
|
|
326
363
|
});
|
|
327
364
|
});
|
|
328
|
-
test('render ACK', () => {
|
|
329
|
-
expect(siProtocol.render({ mode: proto.ACK })).toEqual([proto.ACK]);
|
|
365
|
+
(0, globals_1.test)('render ACK', () => {
|
|
366
|
+
(0, globals_1.expect)(siProtocol.render({ mode: constants_1.proto.ACK })).toEqual([constants_1.proto.ACK]);
|
|
330
367
|
});
|
|
331
|
-
test('render NAK', () => {
|
|
332
|
-
expect(siProtocol.render({ mode: proto.NAK })).toEqual([proto.NAK]);
|
|
368
|
+
(0, globals_1.test)('render NAK', () => {
|
|
369
|
+
(0, globals_1.expect)(siProtocol.render({ mode: constants_1.proto.NAK })).toEqual([constants_1.proto.NAK]);
|
|
333
370
|
});
|
|
334
|
-
test('render WAKEUP', () => {
|
|
335
|
-
expect(siProtocol.render({ mode: proto.WAKEUP })).toEqual([proto.WAKEUP]);
|
|
371
|
+
(0, globals_1.test)('render WAKEUP', () => {
|
|
372
|
+
(0, globals_1.expect)(siProtocol.render({ mode: constants_1.proto.WAKEUP })).toEqual([constants_1.proto.WAKEUP]);
|
|
336
373
|
});
|
|
337
|
-
test('render command', () => {
|
|
338
|
-
expect(siProtocol.render({ command: 0x00, parameters: [] })).toEqual([proto.STX, 0x00, 0x00, 0x00, 0x00, proto.ETX]);
|
|
339
|
-
expect(siProtocol.render({ command: 0xff, parameters: [0xee] })).toEqual([proto.STX, 0xff, 0x01, 0xee, 0xec, 0x0a, proto.ETX]);
|
|
340
|
-
expect(siProtocol.render({ mode: undefined, command: 0x00, parameters: [] })).toEqual([proto.STX, 0x00, 0x00, 0x00, 0x00, proto.ETX]);
|
|
341
|
-
expect(siProtocol.render({ mode: undefined, command: 0xff, parameters: [0xee] })).toEqual([proto.STX, 0xff, 0x01, 0xee, 0xec, 0x0a, proto.ETX]);
|
|
374
|
+
(0, globals_1.test)('render command', () => {
|
|
375
|
+
(0, globals_1.expect)(siProtocol.render({ command: 0x00, parameters: [] })).toEqual([constants_1.proto.STX, 0x00, 0x00, 0x00, 0x00, constants_1.proto.ETX]);
|
|
376
|
+
(0, globals_1.expect)(siProtocol.render({ command: 0xff, parameters: [0xee] })).toEqual([constants_1.proto.STX, 0xff, 0x01, 0xee, 0xec, 0x0a, constants_1.proto.ETX]);
|
|
377
|
+
(0, globals_1.expect)(siProtocol.render({ mode: undefined, command: 0x00, parameters: [] })).toEqual([constants_1.proto.STX, 0x00, 0x00, 0x00, 0x00, constants_1.proto.ETX]);
|
|
378
|
+
(0, globals_1.expect)(siProtocol.render({ mode: undefined, command: 0xff, parameters: [0xee] })).toEqual([constants_1.proto.STX, 0xff, 0x01, 0xee, 0xec, 0x0a, constants_1.proto.ETX]);
|
|
342
379
|
});
|
|
343
|
-
test('render invalid mode', () => {
|
|
344
|
-
const invalidMode = testUtils.getRandomByteExcept([proto.WAKEUP, proto.NAK, proto.ACK]);
|
|
345
|
-
expect(() => siProtocol.render({ mode: invalidMode })).toThrow();
|
|
380
|
+
(0, globals_1.test)('render invalid mode', () => {
|
|
381
|
+
const invalidMode = testUtils.getRandomByteExcept([constants_1.proto.WAKEUP, constants_1.proto.NAK, constants_1.proto.ACK]);
|
|
382
|
+
(0, globals_1.expect)(() => siProtocol.render({ mode: invalidMode })).toThrow();
|
|
346
383
|
});
|
|
347
|
-
test('SiDate SiStorage integration', () => {
|
|
384
|
+
(0, globals_1.test)('SiDate SiStorage integration', () => {
|
|
348
385
|
const weirdStorage = storage.defineStorage(0x09, {
|
|
349
386
|
weirdDate: new siProtocol.SiDate(3, (i) => i),
|
|
350
387
|
crazyDate: new siProtocol.SiDate(6, (i) => 0x03 + i)
|
|
351
388
|
});
|
|
352
389
|
const myWeirdStorage = weirdStorage(utils.unPrettyHex('0F 03 07 00 00 00 00 00 00'));
|
|
353
|
-
expect(myWeirdStorage.get('weirdDate').value).toEqual(new Date(2015, 2, 7));
|
|
390
|
+
(0, globals_1.expect)(myWeirdStorage.get('weirdDate').value).toEqual(new Date(2015, 2, 7));
|
|
354
391
|
myWeirdStorage.set('weirdDate', new Date(2017, 12, 30));
|
|
355
|
-
expect(myWeirdStorage.data.toJS()).toEqual(utils.unPrettyHex('12 01 1E 00 00 00 00 00 00'));
|
|
356
|
-
expect(myWeirdStorage.get('weirdDate').value).toEqual(new Date(2017, 12, 30));
|
|
357
|
-
expect(myWeirdStorage.get('crazyDate')).toEqual(undefined);
|
|
392
|
+
(0, globals_1.expect)(myWeirdStorage.data.toJS()).toEqual(utils.unPrettyHex('12 01 1E 00 00 00 00 00 00'));
|
|
393
|
+
(0, globals_1.expect)(myWeirdStorage.get('weirdDate').value).toEqual(new Date(2017, 12, 30));
|
|
394
|
+
(0, globals_1.expect)(myWeirdStorage.get('crazyDate')).toEqual(undefined);
|
|
358
395
|
myWeirdStorage.set('crazyDate', new Date(2003, 1, 30, 3, 7, 5));
|
|
359
|
-
expect(myWeirdStorage.data.toJS()).toEqual(utils.unPrettyHex('12 01 1E 03 03 02 00 2B D9'));
|
|
360
|
-
expect(myWeirdStorage.get('crazyDate').value).toEqual(new Date(2003, 1, 30, 3, 7, 5));
|
|
396
|
+
(0, globals_1.expect)(myWeirdStorage.data.toJS()).toEqual(utils.unPrettyHex('12 01 1E 03 03 02 00 2B D9'));
|
|
397
|
+
(0, globals_1.expect)(myWeirdStorage.get('crazyDate').value).toEqual(new Date(2003, 1, 30, 3, 7, 5));
|
|
361
398
|
const unknownWeirdStorage = weirdStorage();
|
|
362
399
|
const ModifyUndefinedException = storage.ModifyUndefinedException;
|
|
363
|
-
expect(unknownWeirdStorage.get('weirdDate')).toBe(undefined);
|
|
364
|
-
expect(() => unknownWeirdStorage.set('weirdDate', new Date(2017, 12, 30))).toThrow(ModifyUndefinedException);
|
|
365
|
-
expect(unknownWeirdStorage.get('crazyDate')).toBe(undefined);
|
|
366
|
-
expect(() => unknownWeirdStorage.set('crazyDate', new Date(2003, 1, 30, 3, 7, 5))).toThrow(ModifyUndefinedException);
|
|
400
|
+
(0, globals_1.expect)(unknownWeirdStorage.get('weirdDate')).toBe(undefined);
|
|
401
|
+
(0, globals_1.expect)(() => unknownWeirdStorage.set('weirdDate', new Date(2017, 12, 30))).toThrow(ModifyUndefinedException);
|
|
402
|
+
(0, globals_1.expect)(unknownWeirdStorage.get('crazyDate')).toBe(undefined);
|
|
403
|
+
(0, globals_1.expect)(() => unknownWeirdStorage.set('crazyDate', new Date(2003, 1, 30, 3, 7, 5))).toThrow(ModifyUndefinedException);
|
|
367
404
|
});
|
|
368
|
-
describe('SiDate', () => {
|
|
405
|
+
(0, globals_1.describe)('SiDate', () => {
|
|
369
406
|
const mySiDate = new siProtocol.SiDate(3, (i) => i);
|
|
370
407
|
const fieldValueOf = (value) => new storage.SiFieldValue(mySiDate, value);
|
|
371
|
-
test('typeSpecificIsValueValid', () => {
|
|
372
|
-
expect(mySiDate.typeSpecificIsValueValid(new Date())).toBe(true);
|
|
373
|
-
});
|
|
374
|
-
test('valueToString', () => {
|
|
375
|
-
expect(mySiDate.valueToString(json2date('2000-01-01T00:00:00.000Z'))).toBe('2000-01-01T00:00:00.000Z');
|
|
376
|
-
expect(mySiDate.valueToString(json2date('2020-12-31T13:27:30.000Z'))).toBe('2020-12-31T13:27:30.000Z');
|
|
377
|
-
});
|
|
378
|
-
test('valueFromString', () => {
|
|
379
|
-
expect(mySiDate.valueFromString('2000-01-01T00:00:00.000Z')).toEqual(json2date('2000-01-01T00:00:00.000Z'));
|
|
380
|
-
expect(mySiDate.valueFromString('2020-12-31T13:27:30.000Z')).toEqual(json2date('2020-12-31T13:27:30.000Z'));
|
|
381
|
-
expect(mySiDate.valueFromString('2020-12-31T13:27:30.000') instanceof storage.ValueFromStringError).toBe(true);
|
|
382
|
-
expect(mySiDate.valueFromString('2020-12-31T13:27:30Z') instanceof storage.ValueFromStringError).toBe(true);
|
|
383
|
-
expect(mySiDate.valueFromString('2020-12-31Z') instanceof storage.ValueFromStringError).toBe(true);
|
|
384
|
-
expect(mySiDate.valueFromString('2020-12-31') instanceof storage.ValueFromStringError).toBe(true);
|
|
385
|
-
expect(mySiDate.valueFromString('test') instanceof storage.ValueFromStringError).toBe(true);
|
|
386
|
-
});
|
|
387
|
-
test('extractFromData gives field value', () => {
|
|
388
|
-
const data = List([0x00, 0x01, 0x01]);
|
|
408
|
+
(0, globals_1.test)('typeSpecificIsValueValid', () => {
|
|
409
|
+
(0, globals_1.expect)(mySiDate.typeSpecificIsValueValid(new Date())).toBe(true);
|
|
410
|
+
});
|
|
411
|
+
(0, globals_1.test)('valueToString', () => {
|
|
412
|
+
(0, globals_1.expect)(mySiDate.valueToString(json2date('2000-01-01T00:00:00.000Z'))).toBe('2000-01-01T00:00:00.000Z');
|
|
413
|
+
(0, globals_1.expect)(mySiDate.valueToString(json2date('2020-12-31T13:27:30.000Z'))).toBe('2020-12-31T13:27:30.000Z');
|
|
414
|
+
});
|
|
415
|
+
(0, globals_1.test)('valueFromString', () => {
|
|
416
|
+
(0, globals_1.expect)(mySiDate.valueFromString('2000-01-01T00:00:00.000Z')).toEqual(json2date('2000-01-01T00:00:00.000Z'));
|
|
417
|
+
(0, globals_1.expect)(mySiDate.valueFromString('2020-12-31T13:27:30.000Z')).toEqual(json2date('2020-12-31T13:27:30.000Z'));
|
|
418
|
+
(0, globals_1.expect)(mySiDate.valueFromString('2020-12-31T13:27:30.000') instanceof storage.ValueFromStringError).toBe(true);
|
|
419
|
+
(0, globals_1.expect)(mySiDate.valueFromString('2020-12-31T13:27:30Z') instanceof storage.ValueFromStringError).toBe(true);
|
|
420
|
+
(0, globals_1.expect)(mySiDate.valueFromString('2020-12-31Z') instanceof storage.ValueFromStringError).toBe(true);
|
|
421
|
+
(0, globals_1.expect)(mySiDate.valueFromString('2020-12-31') instanceof storage.ValueFromStringError).toBe(true);
|
|
422
|
+
(0, globals_1.expect)(mySiDate.valueFromString('test') instanceof storage.ValueFromStringError).toBe(true);
|
|
423
|
+
});
|
|
424
|
+
(0, globals_1.test)('extractFromData gives field value', () => {
|
|
425
|
+
const data = (0, immutable_1.List)([0x00, 0x01, 0x01]);
|
|
389
426
|
const fieldValue = mySiDate.extractFromData(data);
|
|
390
|
-
expect(fieldValue instanceof storage.SiFieldValue).toBe(true);
|
|
391
|
-
expect(fieldValue.field).toBe(mySiDate);
|
|
392
|
-
expect(fieldValue.value).toEqual(json2date('2000-01-01T00:00:00.000Z'));
|
|
393
|
-
});
|
|
394
|
-
test('extractFromData', () => {
|
|
395
|
-
const getExtractedFieldValue = (bytes) => mySiDate.extractFromData(List(bytes));
|
|
396
|
-
expect(getExtractedFieldValue([0x00, 0x01, 0x01]).value instanceof Date).toBe(true);
|
|
397
|
-
expect(getExtractedFieldValue([0x00, 0x01, undefined])).toBe(undefined);
|
|
398
|
-
expect(getExtractedFieldValue([0x00, undefined, 0x01])).toBe(undefined);
|
|
399
|
-
expect(getExtractedFieldValue([undefined, 0x00, 0x01])).toBe(undefined);
|
|
400
|
-
expect(getExtractedFieldValue([0x00])).toBe(undefined);
|
|
401
|
-
expect(getExtractedFieldValue([])).toBe(undefined);
|
|
402
|
-
});
|
|
403
|
-
test('updateData', () => {
|
|
404
|
-
const initialData = List([0x00, 0x00, 0x00]);
|
|
427
|
+
(0, globals_1.expect)(fieldValue instanceof storage.SiFieldValue).toBe(true);
|
|
428
|
+
(0, globals_1.expect)(fieldValue.field).toBe(mySiDate);
|
|
429
|
+
(0, globals_1.expect)(fieldValue.value).toEqual(json2date('2000-01-01T00:00:00.000Z'));
|
|
430
|
+
});
|
|
431
|
+
(0, globals_1.test)('extractFromData', () => {
|
|
432
|
+
const getExtractedFieldValue = (bytes) => mySiDate.extractFromData((0, immutable_1.List)(bytes));
|
|
433
|
+
(0, globals_1.expect)(getExtractedFieldValue([0x00, 0x01, 0x01]).value instanceof Date).toBe(true);
|
|
434
|
+
(0, globals_1.expect)(getExtractedFieldValue([0x00, 0x01, undefined])).toBe(undefined);
|
|
435
|
+
(0, globals_1.expect)(getExtractedFieldValue([0x00, undefined, 0x01])).toBe(undefined);
|
|
436
|
+
(0, globals_1.expect)(getExtractedFieldValue([undefined, 0x00, 0x01])).toBe(undefined);
|
|
437
|
+
(0, globals_1.expect)(getExtractedFieldValue([0x00])).toBe(undefined);
|
|
438
|
+
(0, globals_1.expect)(getExtractedFieldValue([])).toBe(undefined);
|
|
439
|
+
});
|
|
440
|
+
(0, globals_1.test)('updateData', () => {
|
|
441
|
+
const initialData = (0, immutable_1.List)([0x00, 0x00, 0x00]);
|
|
405
442
|
const updateInitialData = (newValue) => mySiDate.updateData(initialData, newValue).toJS();
|
|
406
|
-
expect(updateInitialData(json2date('2000-01-01T00:00:00.000Z'))).toEqual([0x00, 0x01, 0x01]);
|
|
407
|
-
expect(updateInitialData(fieldValueOf(json2date('2000-01-01T00:00:00.000Z')))).toEqual([0x00, 0x01, 0x01]);
|
|
443
|
+
(0, globals_1.expect)(updateInitialData(json2date('2000-01-01T00:00:00.000Z'))).toEqual([0x00, 0x01, 0x01]);
|
|
444
|
+
(0, globals_1.expect)(updateInitialData(fieldValueOf(json2date('2000-01-01T00:00:00.000Z')))).toEqual([0x00, 0x01, 0x01]);
|
|
408
445
|
});
|
|
409
|
-
test('updateData modify undefined', () => {
|
|
410
|
-
const updateData = (data, newValue) => mySiDate.updateData(List(data), newValue).toJS();
|
|
411
|
-
expect(() => updateData([], json2date('2000-01-01T00:00:00.000Z'))).toThrow(storage.ModifyUndefinedException);
|
|
412
|
-
expect(() => updateData([], fieldValueOf(json2date('2000-01-01T00:00:00.000Z')))).toThrow(storage.ModifyUndefinedException);
|
|
413
|
-
expect(() => updateData([0x00, 0x00, undefined], json2date('2000-01-01T00:00:00.000Z'))).toThrow(storage.ModifyUndefinedException);
|
|
414
|
-
expect(() => updateData([0x00, undefined, 0x00], json2date('2000-01-01T00:00:00.000Z'))).toThrow(storage.ModifyUndefinedException);
|
|
415
|
-
expect(() => updateData([undefined, 0x00, 0x00], json2date('2000-01-01T00:00:00.000Z'))).toThrow(storage.ModifyUndefinedException);
|
|
446
|
+
(0, globals_1.test)('updateData modify undefined', () => {
|
|
447
|
+
const updateData = (data, newValue) => mySiDate.updateData((0, immutable_1.List)(data), newValue).toJS();
|
|
448
|
+
(0, globals_1.expect)(() => updateData([], json2date('2000-01-01T00:00:00.000Z'))).toThrow(storage.ModifyUndefinedException);
|
|
449
|
+
(0, globals_1.expect)(() => updateData([], fieldValueOf(json2date('2000-01-01T00:00:00.000Z')))).toThrow(storage.ModifyUndefinedException);
|
|
450
|
+
(0, globals_1.expect)(() => updateData([0x00, 0x00, undefined], json2date('2000-01-01T00:00:00.000Z'))).toThrow(storage.ModifyUndefinedException);
|
|
451
|
+
(0, globals_1.expect)(() => updateData([0x00, undefined, 0x00], json2date('2000-01-01T00:00:00.000Z'))).toThrow(storage.ModifyUndefinedException);
|
|
452
|
+
(0, globals_1.expect)(() => updateData([undefined, 0x00, 0x00], json2date('2000-01-01T00:00:00.000Z'))).toThrow(storage.ModifyUndefinedException);
|
|
416
453
|
});
|
|
417
454
|
});
|
|
418
|
-
describe('SiTime', () => {
|
|
455
|
+
(0, globals_1.describe)('SiTime', () => {
|
|
419
456
|
const mySiTime = new siProtocol.SiTime([[0x01], [0x00]]);
|
|
420
457
|
const myInexistentSiTime = new siProtocol.SiTime(undefined);
|
|
421
458
|
const fieldValueOf = (value) => new storage.SiFieldValue(mySiTime, value);
|
|
422
|
-
test('typeSpecificIsValueValid', () => {
|
|
423
|
-
expect(mySiTime.typeSpecificIsValueValid({ time: 0 })).toBe(true);
|
|
424
|
-
expect(mySiTime.typeSpecificIsValueValid({ time: 43199 })).toBe(true);
|
|
425
|
-
expect(mySiTime.typeSpecificIsValueValid({ time: 86400 })).toBe(false);
|
|
426
|
-
expect(mySiTime.typeSpecificIsValueValid(null)).toBe(true);
|
|
427
|
-
});
|
|
428
|
-
test('valueToString', () => {
|
|
429
|
-
expect(mySiTime.valueToString({ time: 0 })).toBe('00:00:00');
|
|
430
|
-
expect(mySiTime.valueToString({ time: 43199 })).toBe('11:59:59');
|
|
431
|
-
expect(mySiTime.valueToString(null)).toBe('NO_TIME');
|
|
432
|
-
});
|
|
433
|
-
test('valueFromString', () => {
|
|
434
|
-
expect(mySiTime.valueFromString('00:00:00')).toEqual({ time: 0 });
|
|
435
|
-
expect(mySiTime.valueFromString('11:59:59')).toEqual({ time: 43199 });
|
|
436
|
-
expect(mySiTime.valueFromString('NO_TIME')).toBe(null);
|
|
437
|
-
expect(mySiTime.valueFromString('06:12') instanceof storage.ValueFromStringError).toBe(true);
|
|
438
|
-
expect(mySiTime.valueFromString('test') instanceof storage.ValueFromStringError).toBe(true);
|
|
439
|
-
});
|
|
440
|
-
test('extractFromData gives field value', () => {
|
|
441
|
-
const data = List([0x01, 0x01]);
|
|
459
|
+
(0, globals_1.test)('typeSpecificIsValueValid', () => {
|
|
460
|
+
(0, globals_1.expect)(mySiTime.typeSpecificIsValueValid({ time: 0 })).toBe(true);
|
|
461
|
+
(0, globals_1.expect)(mySiTime.typeSpecificIsValueValid({ time: 43199 })).toBe(true);
|
|
462
|
+
(0, globals_1.expect)(mySiTime.typeSpecificIsValueValid({ time: 86400 })).toBe(false);
|
|
463
|
+
(0, globals_1.expect)(mySiTime.typeSpecificIsValueValid(null)).toBe(true);
|
|
464
|
+
});
|
|
465
|
+
(0, globals_1.test)('valueToString', () => {
|
|
466
|
+
(0, globals_1.expect)(mySiTime.valueToString({ time: 0 })).toBe('00:00:00');
|
|
467
|
+
(0, globals_1.expect)(mySiTime.valueToString({ time: 43199 })).toBe('11:59:59');
|
|
468
|
+
(0, globals_1.expect)(mySiTime.valueToString(null)).toBe('NO_TIME');
|
|
469
|
+
});
|
|
470
|
+
(0, globals_1.test)('valueFromString', () => {
|
|
471
|
+
(0, globals_1.expect)(mySiTime.valueFromString('00:00:00')).toEqual({ time: 0 });
|
|
472
|
+
(0, globals_1.expect)(mySiTime.valueFromString('11:59:59')).toEqual({ time: 43199 });
|
|
473
|
+
(0, globals_1.expect)(mySiTime.valueFromString('NO_TIME')).toBe(null);
|
|
474
|
+
(0, globals_1.expect)(mySiTime.valueFromString('06:12') instanceof storage.ValueFromStringError).toBe(true);
|
|
475
|
+
(0, globals_1.expect)(mySiTime.valueFromString('test') instanceof storage.ValueFromStringError).toBe(true);
|
|
476
|
+
});
|
|
477
|
+
(0, globals_1.test)('extractFromData gives field value', () => {
|
|
478
|
+
const data = (0, immutable_1.List)([0x01, 0x01]);
|
|
442
479
|
const fieldValue = mySiTime.extractFromData(data);
|
|
443
|
-
expect(fieldValue instanceof storage.SiFieldValue).toBe(true);
|
|
444
|
-
expect(fieldValue.field).toBe(mySiTime);
|
|
445
|
-
expect(JSON.stringify(fieldValue.value)).toBe(JSON.stringify({ time: 257, weekcounter: undefined, weekday: undefined }));
|
|
446
|
-
});
|
|
447
|
-
test('extractFromData', () => {
|
|
448
|
-
const getExtractedFieldValue = (bytes) => mySiTime.extractFromData(List(bytes));
|
|
449
|
-
expect(JSON.stringify(getExtractedFieldValue([0x00, 0x01]).value)).toBe(JSON.stringify({ time: 1, weekcounter: undefined, weekday: undefined }));
|
|
450
|
-
expect(getExtractedFieldValue([0xee, 0xee]).value).toBe(null);
|
|
451
|
-
expect(getExtractedFieldValue([0x00, undefined])).toBe(undefined);
|
|
452
|
-
expect(getExtractedFieldValue([undefined, 0x01])).toBe(undefined);
|
|
453
|
-
expect(getExtractedFieldValue([0x00])).toBe(undefined);
|
|
454
|
-
expect(getExtractedFieldValue([])).toBe(undefined);
|
|
455
|
-
});
|
|
456
|
-
test('extractFromData for inexistent', () => {
|
|
457
|
-
const getExtractedFieldValue = (bytes) => myInexistentSiTime.extractFromData(List(bytes));
|
|
458
|
-
expect(getExtractedFieldValue([0x00, 0x01]).value).toBe(null);
|
|
459
|
-
});
|
|
460
|
-
test('updateData', () => {
|
|
461
|
-
const initialData = List([0x00, 0x00]);
|
|
480
|
+
(0, globals_1.expect)(fieldValue instanceof storage.SiFieldValue).toBe(true);
|
|
481
|
+
(0, globals_1.expect)(fieldValue.field).toBe(mySiTime);
|
|
482
|
+
(0, globals_1.expect)(JSON.stringify(fieldValue.value)).toBe(JSON.stringify({ time: 257, weekcounter: undefined, weekday: undefined }));
|
|
483
|
+
});
|
|
484
|
+
(0, globals_1.test)('extractFromData', () => {
|
|
485
|
+
const getExtractedFieldValue = (bytes) => mySiTime.extractFromData((0, immutable_1.List)(bytes));
|
|
486
|
+
(0, globals_1.expect)(JSON.stringify(getExtractedFieldValue([0x00, 0x01]).value)).toBe(JSON.stringify({ time: 1, weekcounter: undefined, weekday: undefined }));
|
|
487
|
+
(0, globals_1.expect)(getExtractedFieldValue([0xee, 0xee]).value).toBe(null);
|
|
488
|
+
(0, globals_1.expect)(getExtractedFieldValue([0x00, undefined])).toBe(undefined);
|
|
489
|
+
(0, globals_1.expect)(getExtractedFieldValue([undefined, 0x01])).toBe(undefined);
|
|
490
|
+
(0, globals_1.expect)(getExtractedFieldValue([0x00])).toBe(undefined);
|
|
491
|
+
(0, globals_1.expect)(getExtractedFieldValue([])).toBe(undefined);
|
|
492
|
+
});
|
|
493
|
+
(0, globals_1.test)('extractFromData for inexistent', () => {
|
|
494
|
+
const getExtractedFieldValue = (bytes) => myInexistentSiTime.extractFromData((0, immutable_1.List)(bytes));
|
|
495
|
+
(0, globals_1.expect)(getExtractedFieldValue([0x00, 0x01]).value).toBe(null);
|
|
496
|
+
});
|
|
497
|
+
(0, globals_1.test)('updateData', () => {
|
|
498
|
+
const initialData = (0, immutable_1.List)([0x00, 0x00]);
|
|
462
499
|
const updateInitialData = (newValue) => mySiTime.updateData(initialData, newValue).toJS();
|
|
463
|
-
expect(updateInitialData({ time: 257 })).toEqual([0x01, 0x01]);
|
|
464
|
-
expect(updateInitialData(fieldValueOf({ time: 257 }))).toEqual([0x01, 0x01]);
|
|
465
|
-
expect(updateInitialData(null)).toEqual([0xee, 0xee]);
|
|
466
|
-
expect(updateInitialData(fieldValueOf(null))).toEqual([0xee, 0xee]);
|
|
500
|
+
(0, globals_1.expect)(updateInitialData({ time: 257 })).toEqual([0x01, 0x01]);
|
|
501
|
+
(0, globals_1.expect)(updateInitialData(fieldValueOf({ time: 257 }))).toEqual([0x01, 0x01]);
|
|
502
|
+
(0, globals_1.expect)(updateInitialData(null)).toEqual([0xee, 0xee]);
|
|
503
|
+
(0, globals_1.expect)(updateInitialData(fieldValueOf(null))).toEqual([0xee, 0xee]);
|
|
467
504
|
});
|
|
468
|
-
test('updateData for inexistent', () => {
|
|
469
|
-
const initialData = List([0x00, 0x00]);
|
|
505
|
+
(0, globals_1.test)('updateData for inexistent', () => {
|
|
506
|
+
const initialData = (0, immutable_1.List)([0x00, 0x00]);
|
|
470
507
|
const updateInitialData = (newValue) => myInexistentSiTime.updateData(initialData, newValue).toJS();
|
|
471
|
-
expect(updateInitialData({ time: 257 })).toEqual([0x00, 0x00]);
|
|
472
|
-
expect(updateInitialData(fieldValueOf({ time: 257 }))).toEqual([0x00, 0x00]);
|
|
473
|
-
});
|
|
474
|
-
test('updateData modify undefined', () => {
|
|
475
|
-
const updateData = (data, newValue) => mySiTime.updateData(List(data), newValue).toJS();
|
|
476
|
-
expect(() => updateData([], { time: 257 })).toThrow(storage.ModifyUndefinedException);
|
|
477
|
-
expect(() => updateData([], fieldValueOf({ time: 257 }))).toThrow(storage.ModifyUndefinedException);
|
|
478
|
-
expect(() => updateData([0x00, undefined], { time: 257 })).toThrow(storage.ModifyUndefinedException);
|
|
479
|
-
expect(() => updateData([undefined, 0x01], { time: 257 })).toThrow(storage.ModifyUndefinedException);
|
|
508
|
+
(0, globals_1.expect)(updateInitialData({ time: 257 })).toEqual([0x00, 0x00]);
|
|
509
|
+
(0, globals_1.expect)(updateInitialData(fieldValueOf({ time: 257 }))).toEqual([0x00, 0x00]);
|
|
510
|
+
});
|
|
511
|
+
(0, globals_1.test)('updateData modify undefined', () => {
|
|
512
|
+
const updateData = (data, newValue) => mySiTime.updateData((0, immutable_1.List)(data), newValue).toJS();
|
|
513
|
+
(0, globals_1.expect)(() => updateData([], { time: 257 })).toThrow(storage.ModifyUndefinedException);
|
|
514
|
+
(0, globals_1.expect)(() => updateData([], fieldValueOf({ time: 257 }))).toThrow(storage.ModifyUndefinedException);
|
|
515
|
+
(0, globals_1.expect)(() => updateData([0x00, undefined], { time: 257 })).toThrow(storage.ModifyUndefinedException);
|
|
516
|
+
(0, globals_1.expect)(() => updateData([undefined, 0x01], { time: 257 })).toThrow(storage.ModifyUndefinedException);
|
|
480
517
|
});
|
|
481
518
|
});
|
|
482
519
|
});
|