@machinemetrics/io-adapter-lib 2.32.0
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/.circleci/config.yml +141 -0
- package/.eslintrc.json +36 -0
- package/.gitattributes +12 -0
- package/CHANGELOG.md +544 -0
- package/README.md +2 -0
- package/index.js +17 -0
- package/lib/config/adapterConfig.js +535 -0
- package/lib/config/common/allowDenyList.js +58 -0
- package/lib/config/common/jsonPath.js +44 -0
- package/lib/config/common/labjackU3T4Common.js +227 -0
- package/lib/config/common/validations.js +142 -0
- package/lib/config/configError.js +32 -0
- package/lib/config/device/adam-6052Config.js +103 -0
- package/lib/config/device/brotherHTTPConfig.js +215 -0
- package/lib/config/device/ethernetIPConfig.js +191 -0
- package/lib/config/device/ifmIotConfig.js +245 -0
- package/lib/config/device/jsonHttpConfig.js +76 -0
- package/lib/config/device/labjackT4Config.js +39 -0
- package/lib/config/device/labjackT7Config.js +192 -0
- package/lib/config/device/labjackU3Config.js +32 -0
- package/lib/config/device/modbusTcpConfig.js +336 -0
- package/lib/config/device/mqttBaseConfig.js +70 -0
- package/lib/config/device/mqttConfig.js +113 -0
- package/lib/config/device/mqttLincolnConfig.js +62 -0
- package/lib/config/device/mtconnectAdapterConfig.js +42 -0
- package/lib/config/device/mtconnectBaseConfig.js +136 -0
- package/lib/config/device/mtconnectConfig.js +52 -0
- package/lib/config/device/mtconnectHaasConfig.js +15 -0
- package/lib/config/device/nullConfig.js +81 -0
- package/lib/config/device/opcuaConfig.js +205 -0
- package/lib/config/device/pcccConfig.js +88 -0
- package/lib/config/engineConfigV1.js +382 -0
- package/lib/config/engineConfigV2.js +106 -0
- package/lib/config/generator/counterGenConfig.js +15 -0
- package/lib/config/generator/cronGenConfig.js +33 -0
- package/lib/config/generator/dateTimeGenConfig.js +33 -0
- package/lib/config/index.js +339 -0
- package/lib/config/transformConfigUtil.js +296 -0
- package/lib/engine/dataOutput.js +357 -0
- package/lib/engine/deviceOutput.js +186 -0
- package/lib/engine/engineV1.js +480 -0
- package/lib/engine/engineV2.js +719 -0
- package/lib/engine/index.js +34 -0
- package/lib/engine/transformBuilderV1.js +111 -0
- package/lib/engine/transformBuilderV2.js +74 -0
- package/lib/expressionService.js +330 -0
- package/lib/math.js +142 -0
- package/lib/transform/accumulate.js +98 -0
- package/lib/transform/average.js +56 -0
- package/lib/transform/debounce.js +152 -0
- package/lib/transform/downsample.js +69 -0
- package/lib/transform/edge.js +34 -0
- package/lib/transform/expression.js +91 -0
- package/lib/transform/fallingEdge.js +70 -0
- package/lib/transform/fromBuffer.js +89 -0
- package/lib/transform/hash.js +41 -0
- package/lib/transform/ignoreValue.js +118 -0
- package/lib/transform/index.js +93 -0
- package/lib/transform/invert.js +25 -0
- package/lib/transform/latch.js +99 -0
- package/lib/transform/latchValue.js +115 -0
- package/lib/transform/logicAnd.js +67 -0
- package/lib/transform/logicOr.js +67 -0
- package/lib/transform/map.js +115 -0
- package/lib/transform/max.js +57 -0
- package/lib/transform/maxLength.js +39 -0
- package/lib/transform/min.js +57 -0
- package/lib/transform/minDelta.js +40 -0
- package/lib/transform/offDelay.js +89 -0
- package/lib/transform/onDelay.js +89 -0
- package/lib/transform/patternEscape.js +24 -0
- package/lib/transform/patternMatch.js +194 -0
- package/lib/transform/patternReplace.js +170 -0
- package/lib/transform/patternTest.js +85 -0
- package/lib/transform/rateOfChange.js +56 -0
- package/lib/transform/reject.js +115 -0
- package/lib/transform/resample.js +96 -0
- package/lib/transform/risingEdge.js +90 -0
- package/lib/transform/risingEdgeCounter.js +179 -0
- package/lib/transform/sampleInterval.js +12 -0
- package/lib/transform/source.js +116 -0
- package/lib/transform/state.js +201 -0
- package/lib/transform/threshold.js +52 -0
- package/lib/transform/toBuffer.js +159 -0
- package/lib/transform/toggle.js +118 -0
- package/lib/transform/transformState.js +193 -0
- package/lib/transform/trim.js +27 -0
- package/lib/transform/util/chainSource.js +96 -0
- package/lib/transform/util/ringBuffer.js +34 -0
- package/lib/transform/valueChange.js +34 -0
- package/lib/transform/valueDecrease.js +38 -0
- package/lib/transform/valueIncrease.js +38 -0
- package/lib/transform/valueIncreaseDiff.js +66 -0
- package/lib/transform/whenUnavailable.js +73 -0
- package/lib/transform/windowCount.js +86 -0
- package/lib/util/fileUtil.js +44 -0
- package/package.json +38 -0
- package/test/.eslintrc.json +15 -0
- package/test/chainedTransform.test.js +88 -0
- package/test/conditions.test.js +118 -0
- package/test/config/ab-pccc.test.js +41 -0
- package/test/config/adam-6052.test.js +16 -0
- package/test/config/adapter.test.js +109 -0
- package/test/config/brother-http.test.js +19 -0
- package/test/config/ethernet-ip.test.js +19 -0
- package/test/config/ifm-iot.test.js +20 -0
- package/test/config/json-http.test.js +47 -0
- package/test/config/labjack-t4.test.js +78 -0
- package/test/config/labjack-t7.test.js +18 -0
- package/test/config/labjack-u3.test.js +17 -0
- package/test/config/modbusTcp.test.js +87 -0
- package/test/config/mqtt.test.js +19 -0
- package/test/config/mqttLincoln.test.js +29 -0
- package/test/config/mtconnect.test.js +63 -0
- package/test/config/mtconnectAdapter.test.js +124 -0
- package/test/config/mtconnectHaas.test.js +15 -0
- package/test/config/null.test.js +16 -0
- package/test/config/opcua.test.js +97 -0
- package/test/config-tests.js +102 -0
- package/test/configFiles/conditions.yml +37 -0
- package/test/configFiles/data-items-legacy.yml +24 -0
- package/test/configFiles/data-items-shorthand.yml +14 -0
- package/test/configFiles/data-items.yml +12 -0
- package/test/configFiles/device/ab-pccc-default.yml +3 -0
- package/test/configFiles/device/ab-pccc-full.yml +13 -0
- package/test/configFiles/device/adam-6052-default.yml +2 -0
- package/test/configFiles/device/brother-http-default.yml +3 -0
- package/test/configFiles/device/ethernet-ip-default.yml +2 -0
- package/test/configFiles/device/ifm-iot-default.yml +2 -0
- package/test/configFiles/device/json-http-bad-prop.yml +13 -0
- package/test/configFiles/device/json-http-bad-prop2.yml +13 -0
- package/test/configFiles/device/json-http-default.yml +3 -0
- package/test/configFiles/device/json-http-std.yml +13 -0
- package/test/configFiles/device/labjack-t4-condition-exprs.yaml +46 -0
- package/test/configFiles/device/labjack-t4-default.yml +3 -0
- package/test/configFiles/device/labjack-t4-pins-alt.yaml +41 -0
- package/test/configFiles/device/labjack-t4-pins.yaml +40 -0
- package/test/configFiles/device/labjack-t4-v1.yaml +29 -0
- package/test/configFiles/device/labjack-t7-default.yml +2 -0
- package/test/configFiles/device/labjack-u3-default.yml +2 -0
- package/test/configFiles/device/modbus-partial.yml +4 -0
- package/test/configFiles/device/modbus-std-extended.yaml +23 -0
- package/test/configFiles/device/modbus-std.yaml +34 -0
- package/test/configFiles/device/modbus-tcp-default.yml +3 -0
- package/test/configFiles/device/mqtt-default.yml +2 -0
- package/test/configFiles/device/mqtt-lincoln-default.yml +3 -0
- package/test/configFiles/device/mqtt-lincoln-full.yml +7 -0
- package/test/configFiles/device/mtconnect-adapter-default.yml +3 -0
- package/test/configFiles/device/mtconnect-adapter-keys.yaml +18 -0
- package/test/configFiles/device/mtconnect-complex-keys.yaml +17 -0
- package/test/configFiles/device/mtconnect-default.yml +3 -0
- package/test/configFiles/device/mtconnect-duplicate-allow-keys.yaml +10 -0
- package/test/configFiles/device/mtconnect-duplicate-declare-keys.yaml +8 -0
- package/test/configFiles/device/mtconnect-duplicate-deny-keys.yaml +10 -0
- package/test/configFiles/device/mtconnect-haas-default.yml +3 -0
- package/test/configFiles/device/mtconnect-std.yaml +18 -0
- package/test/configFiles/device/null-default.yml +1 -0
- package/test/configFiles/device/opcua-bad-tag.yml +18 -0
- package/test/configFiles/device/opcua-bad-tag2.yml +18 -0
- package/test/configFiles/device/opcua-default.yml +3 -0
- package/test/configFiles/device/opcua-std.yml +18 -0
- package/test/configFiles/dump-test.yml +11 -0
- package/test/configFiles/expressionCond.yml +46 -0
- package/test/configFiles/min-config-t4.yaml +4 -0
- package/test/configFiles/min-config-u3.yaml +3 -0
- package/test/configFiles/missing-device.yaml +2 -0
- package/test/configFiles/parse-error1.yml +9 -0
- package/test/configFiles/parse-error2.yml +9 -0
- package/test/configFiles/repro/buffer-convert-repro.yml +15 -0
- package/test/configFiles/repro/chained-delay-timing-repro.yml +13 -0
- package/test/configFiles/repro/count-init-repro.yml +45 -0
- package/test/configFiles/repro/cycle-break-repro.yml +44 -0
- package/test/configFiles/repro/debounce-repro.yml +46 -0
- package/test/configFiles/repro/diff-count-repro.yml +34 -0
- package/test/configFiles/repro/engine-hang-repro.yml +9 -0
- package/test/configFiles/repro/latch-apm-repro.yml +26 -0
- package/test/configFiles/repro/lockout-count-repro.yml +33 -0
- package/test/configFiles/repro/program-extract-repro.yml +38 -0
- package/test/configFiles/repro/state-latch-repro.yml +47 -0
- package/test/configFiles/repro/ternary-repro.yml +26 -0
- package/test/configFiles/transform/debounce.yml +12 -0
- package/test/configFiles/transform/expression.yml +34 -0
- package/test/configFiles/transform/ignoreValue.yml +31 -0
- package/test/configFiles/transform/latch.yml +11 -0
- package/test/configFiles/transform/latchValue.yml +31 -0
- package/test/configFiles/transform/logicAnd.yml +14 -0
- package/test/configFiles/transform/logicOr.yml +14 -0
- package/test/configFiles/transform/map.yml +19 -0
- package/test/configFiles/transform/maxLength.yml +13 -0
- package/test/configFiles/transform/offDelay.yml +12 -0
- package/test/configFiles/transform/pattern-escape.yml +10 -0
- package/test/configFiles/transform/pattern-match.yml +57 -0
- package/test/configFiles/transform/pattern-replace.yml +34 -0
- package/test/configFiles/transform/pattern-test.yml +25 -0
- package/test/configFiles/transform/reject.yml +24 -0
- package/test/configFiles/transform/risingEdgeCounter.yml +36 -0
- package/test/configFiles/transform/source.yml +20 -0
- package/test/configFiles/transform/state.yml +56 -0
- package/test/configFiles/transform/toggle.yml +19 -0
- package/test/configFiles/transform/whenUnavailable.yml +19 -0
- package/test/dataFiles/noisy-pulse.txt +11330 -0
- package/test/dataItems.test.js +140 -0
- package/test/engine-v1-tests.js +418 -0
- package/test/engine-v2-tests.js +284 -0
- package/test/expression-tests.js +171 -0
- package/test/expressionService.test.js +154 -0
- package/test/expressionServiceCondition.test.js +130 -0
- package/test/repro/buffer-convert-repro.test.js +38 -0
- package/test/repro/chained-delay-timing-repro.test.js +34 -0
- package/test/repro/count-init-repro.test.js +46 -0
- package/test/repro/cylce-break-repro.test.js +57 -0
- package/test/repro/debounce-repro.test.js +65 -0
- package/test/repro/diff-count-repro.test.js +79 -0
- package/test/repro/engine-hang-repro.test.js +38 -0
- package/test/repro/latch-apm-repro.test.js +119 -0
- package/test/repro/lockout-count-repro.test.js +84 -0
- package/test/repro/program-extract-repro.test.js +40 -0
- package/test/repro/state-latch-repro.test.js +63 -0
- package/test/repro/ternary-repro.test.js +43 -0
- package/test/transform/accumulte.test.js +18 -0
- package/test/transform/average.test.js +22 -0
- package/test/transform/debounce.test.js +70 -0
- package/test/transform/downsample.test.js +30 -0
- package/test/transform/edge.test.js +27 -0
- package/test/transform/expression.test.js +189 -0
- package/test/transform/fallingEdge.test.js +59 -0
- package/test/transform/fromBuffer.test.js +60 -0
- package/test/transform/hash.test.js +34 -0
- package/test/transform/ignoreValue.test.js +123 -0
- package/test/transform/invert.test.js +26 -0
- package/test/transform/latch.test.js +33 -0
- package/test/transform/latchValue.test.js +126 -0
- package/test/transform/logicAnd.test.js +80 -0
- package/test/transform/logicOr.test.js +80 -0
- package/test/transform/map.test.js +42 -0
- package/test/transform/max.test.js +30 -0
- package/test/transform/maxLength.test.js +32 -0
- package/test/transform/min.test.js +30 -0
- package/test/transform/minDelta.test.js +14 -0
- package/test/transform/offDelay.test.js +123 -0
- package/test/transform/onDelay.test.js +105 -0
- package/test/transform/patternEscape.test.js +18 -0
- package/test/transform/patternMatch.test.js +177 -0
- package/test/transform/patternReplace.test.js +95 -0
- package/test/transform/patternTest.test.js +105 -0
- package/test/transform/rateOfChange.test.js +34 -0
- package/test/transform/reject.test.js +56 -0
- package/test/transform/resample.test.js +193 -0
- package/test/transform/risingEdge.test.js +60 -0
- package/test/transform/risingEdgeCounter.test.js +227 -0
- package/test/transform/sampleInterval.test.js +22 -0
- package/test/transform/source.test.js +137 -0
- package/test/transform/state.test.js +248 -0
- package/test/transform/threshold.test.js +78 -0
- package/test/transform/toBuffer.test.js +60 -0
- package/test/transform/toggle.test.js +92 -0
- package/test/transform/trim.test.js +30 -0
- package/test/transform/valueChange.test.js +14 -0
- package/test/transform/valueDecrease.test.js +32 -0
- package/test/transform/valueIncrease.test.js +32 -0
- package/test/transform/valueIncreaseDiff.test.js +32 -0
- package/test/transform/whenUnavailable.test.js +93 -0
- package/test/transform/windowCount.test.js +26 -0
- package/test/util/testUtils.js +405 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const expect = require('chai').expect;
|
|
4
|
+
const EventEmitter = require('eventemitter3');
|
|
5
|
+
const EngineV2 = require('../../lib/engine/engineV2');
|
|
6
|
+
const Builder = require('../../lib/engine/transformBuilderV2');
|
|
7
|
+
const testUtils = require('../util/testUtils');
|
|
8
|
+
|
|
9
|
+
describe('source full engine config file tests', async function () {
|
|
10
|
+
let config;
|
|
11
|
+
before(async () => {
|
|
12
|
+
config = await testUtils.loadConfig('transform/source.yml');
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
const makeSourceEngine = (varName) => {
|
|
16
|
+
const engine = new EngineV2(config);
|
|
17
|
+
const builder = new Builder(config);
|
|
18
|
+
builder.build(engine);
|
|
19
|
+
|
|
20
|
+
const source = testUtils.valueSource();
|
|
21
|
+
testUtils.attachEngineTransformValidator(engine, engine.variablePool[varName], source);
|
|
22
|
+
|
|
23
|
+
return { source, engine };
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
it('emits updates for all vars correctly', async function () {
|
|
27
|
+
const engine = new EngineV2(config);
|
|
28
|
+
const builder = new Builder(config);
|
|
29
|
+
builder.build(engine);
|
|
30
|
+
|
|
31
|
+
const source = new ValueSource();
|
|
32
|
+
engine.addValueSource(source);
|
|
33
|
+
|
|
34
|
+
let callMask = 0;
|
|
35
|
+
engine.on('update', (name, value, time) => {
|
|
36
|
+
if (time === 100 && name === 'var1') {
|
|
37
|
+
expect(value).to.eq(15);
|
|
38
|
+
callMask |= 0x1;
|
|
39
|
+
}
|
|
40
|
+
if (time === 100 && name === 'var2') {
|
|
41
|
+
expect(value).to.eq(25);
|
|
42
|
+
callMask |= 0x2;
|
|
43
|
+
}
|
|
44
|
+
if (time === 100 && (name === 'var3' || name === 'var4')) {
|
|
45
|
+
expect.fail(`Did not expect to emit ${name} update (100)`);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (time === 110 && (name === 'var1' || name === 'var2')) {
|
|
49
|
+
expect.fail(`Did not expect to emit ${name} update (110)`);
|
|
50
|
+
}
|
|
51
|
+
if (time === 110 && name === 'var3') {
|
|
52
|
+
expect(value).to.eq(22);
|
|
53
|
+
callMask |= 0x04;
|
|
54
|
+
}
|
|
55
|
+
if (time === 110 && name === 'var4') {
|
|
56
|
+
expect(value).to.eq(22);
|
|
57
|
+
callMask |= 0x08;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
source.sendValue('xact', 15, 100);
|
|
62
|
+
source.sendValue('yact', 7, 110);
|
|
63
|
+
expect(callMask).to.eq(0xF);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('emits unavailable for all vars correctly', async function () {
|
|
67
|
+
const engine = new EngineV2(config);
|
|
68
|
+
const builder = new Builder(config);
|
|
69
|
+
builder.build(engine);
|
|
70
|
+
|
|
71
|
+
const source = new ValueSource();
|
|
72
|
+
engine.addValueSource(source);
|
|
73
|
+
|
|
74
|
+
let callMask = 0;
|
|
75
|
+
engine.on('update', (name, value, time) => {
|
|
76
|
+
if (time !== 105) {
|
|
77
|
+
expect.fail(`Did not expect to emit ${name} update`);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
engine.on('unavailable', (name, time) => {
|
|
82
|
+
if (time === 100 && (name === 'var1' || name === 'var2')) {
|
|
83
|
+
expect.fail(`Did not expect to emit ${name} unavailable (100)`);
|
|
84
|
+
}
|
|
85
|
+
if (time === 100 && name === 'var3') {
|
|
86
|
+
callMask |= 0x1;
|
|
87
|
+
}
|
|
88
|
+
if (time === 100 && name === 'var4') {
|
|
89
|
+
callMask |= 0x2;
|
|
90
|
+
}
|
|
91
|
+
if (time === 105 && (name === 'var1' || name === 'var2')) {
|
|
92
|
+
expect.fail(`Did not expect to emit ${name} unavailable (105)`);
|
|
93
|
+
}
|
|
94
|
+
if (time === 105 && name === 'var3') {
|
|
95
|
+
callMask |= 0x40;
|
|
96
|
+
}
|
|
97
|
+
if (time === 105 && name === 'var4') {
|
|
98
|
+
callMask |= 0x80;
|
|
99
|
+
}
|
|
100
|
+
if (time === 110 && name === 'var1') {
|
|
101
|
+
callMask |= 0x4;
|
|
102
|
+
}
|
|
103
|
+
if (time === 110 && name === 'var2') {
|
|
104
|
+
callMask |= 0x8;
|
|
105
|
+
}
|
|
106
|
+
if (time === 110 && name === 'var3') {
|
|
107
|
+
callMask |= 0x10;
|
|
108
|
+
}
|
|
109
|
+
if (time === 110 && name === 'var4') {
|
|
110
|
+
callMask |= 0x20;
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
source.sendValue('yact', 'UNAVAILABLE', 100);
|
|
115
|
+
source.sendValue('xact', 5, 105);
|
|
116
|
+
source.sendValue('xact', 'UNAVAILABLE', 110);
|
|
117
|
+
expect(callMask).to.eq(0xFF);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('handles source with string compare', async function () {
|
|
121
|
+
const { source, engine } = makeSourceEngine('var5');
|
|
122
|
+
|
|
123
|
+
source.sendValues('execution', [
|
|
124
|
+
['AUTOMATIC', 0],
|
|
125
|
+
]);
|
|
126
|
+
|
|
127
|
+
engine.validateFilter([
|
|
128
|
+
[true, 0],
|
|
129
|
+
]);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
class ValueSource extends EventEmitter {
|
|
134
|
+
sendValue(name, value, time) {
|
|
135
|
+
this.emit('update', name, value, time);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const expect = require('chai').expect;
|
|
4
|
+
const Builder = require('../../lib/engine/transformBuilderV2');
|
|
5
|
+
const EngineV2 = require('../../lib/engine/engineV2');
|
|
6
|
+
const testUtils = require('../util/testUtils');
|
|
7
|
+
|
|
8
|
+
describe('expression transform tests', function () {
|
|
9
|
+
let config;
|
|
10
|
+
before(async () => {
|
|
11
|
+
config = await testUtils.loadConfig('transform/state.yml');
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('state test 1', function () {
|
|
15
|
+
const engine = new EngineV2(config);
|
|
16
|
+
const builder = new Builder(config);
|
|
17
|
+
builder.build(engine);
|
|
18
|
+
|
|
19
|
+
const source = testUtils.valueSource();
|
|
20
|
+
testUtils.attachEngineTransformValidator(engine, engine.variablePool.test1, source);
|
|
21
|
+
|
|
22
|
+
source.sendValue('exec', 'ACTIVE', 0);
|
|
23
|
+
source.sendValue('in-fault', false, 2);
|
|
24
|
+
source.sendValue('in-fault', false, 4);
|
|
25
|
+
source.sendValue('in-fault', true, 6);
|
|
26
|
+
source.sendValue('exec', 'READY', 8);
|
|
27
|
+
source.sendValue('in-fault', false, 10);
|
|
28
|
+
|
|
29
|
+
engine.validateFilter([
|
|
30
|
+
['ACTIVE', 0],
|
|
31
|
+
['ACTIVE', 2],
|
|
32
|
+
['ACTIVE', 4],
|
|
33
|
+
['STOPPED', 6],
|
|
34
|
+
['READY', 8],
|
|
35
|
+
['READY', 10],
|
|
36
|
+
]);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('state test 1 (order swap)', function () {
|
|
40
|
+
const engine = new EngineV2(config);
|
|
41
|
+
const builder = new Builder(config);
|
|
42
|
+
builder.build(engine);
|
|
43
|
+
|
|
44
|
+
const source = testUtils.valueSource();
|
|
45
|
+
testUtils.attachEngineTransformValidator(engine, engine.variablePool.test1, source);
|
|
46
|
+
|
|
47
|
+
source.sendValue('in-fault', false, 0);
|
|
48
|
+
source.sendValue('exec', 'ACTIVE', 2);
|
|
49
|
+
source.sendValue('in-fault', false, 4);
|
|
50
|
+
source.sendValue('in-fault', true, 6);
|
|
51
|
+
|
|
52
|
+
engine.validateFilter([
|
|
53
|
+
['ACTIVE', 2],
|
|
54
|
+
['ACTIVE', 4],
|
|
55
|
+
['STOPPED', 6],
|
|
56
|
+
]);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('state test 2', function () {
|
|
60
|
+
const engine = new EngineV2(config);
|
|
61
|
+
const builder = new Builder(config);
|
|
62
|
+
builder.build(engine);
|
|
63
|
+
|
|
64
|
+
const source = testUtils.valueSource();
|
|
65
|
+
testUtils.attachEngineTransformValidator(engine, engine.variablePool.test2, source);
|
|
66
|
+
|
|
67
|
+
source.sendValue('exec', 'ACTIVE', 0);
|
|
68
|
+
source.sendValue('in-fault', false, 2);
|
|
69
|
+
source.sendValue('in-fault', false, 4);
|
|
70
|
+
source.sendValue('in-fault', true, 6);
|
|
71
|
+
source.sendValue('exec', 'READY', 8);
|
|
72
|
+
source.sendValue('in-fault', false, 10);
|
|
73
|
+
|
|
74
|
+
engine.validateFilter([
|
|
75
|
+
['ACTIVE', 0],
|
|
76
|
+
['ACTIVE', 2],
|
|
77
|
+
['ACTIVE', 4],
|
|
78
|
+
['STOPPED', 6],
|
|
79
|
+
['READY', 8],
|
|
80
|
+
['READY', 10],
|
|
81
|
+
]);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('state test 3', function () {
|
|
85
|
+
const engine = new EngineV2(config);
|
|
86
|
+
const builder = new Builder(config);
|
|
87
|
+
builder.build(engine);
|
|
88
|
+
|
|
89
|
+
const source = testUtils.valueSource();
|
|
90
|
+
testUtils.attachEngineTransformValidator(engine, engine.variablePool.test3, source);
|
|
91
|
+
|
|
92
|
+
source.sendValue('is-running', true, 2);
|
|
93
|
+
source.sendValue('irrelevant', true, 3);
|
|
94
|
+
source.sendValue('is-running', false, 4);
|
|
95
|
+
|
|
96
|
+
engine.validateFilter([
|
|
97
|
+
['ACTIVE', 2],
|
|
98
|
+
['READY', 4],
|
|
99
|
+
]);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('state test 4', function () {
|
|
103
|
+
const engine = new EngineV2(config);
|
|
104
|
+
const builder = new Builder(config);
|
|
105
|
+
builder.build(engine);
|
|
106
|
+
|
|
107
|
+
const source = testUtils.valueSource();
|
|
108
|
+
testUtils.attachEngineTransformValidator(engine, engine.variablePool.test4, source);
|
|
109
|
+
|
|
110
|
+
source.sendValue('exec', 'ACTIVE', 0);
|
|
111
|
+
source.sendValue('in-fault', false, 2);
|
|
112
|
+
source.sendValue('in-fault', false, 4);
|
|
113
|
+
source.sendValue('in-fault', true, 6);
|
|
114
|
+
source.sendValue('exec', 'READY', 8);
|
|
115
|
+
source.sendValue('in-fault', false, 10);
|
|
116
|
+
|
|
117
|
+
const msg1 = 'This is a long active message';
|
|
118
|
+
const msg2 = 'This is a long stop message';
|
|
119
|
+
const msg3 = 'This is a default message';
|
|
120
|
+
|
|
121
|
+
engine.validateFilter([
|
|
122
|
+
[msg3, 0],
|
|
123
|
+
[msg1, 2],
|
|
124
|
+
[msg1, 4],
|
|
125
|
+
[msg2, 6],
|
|
126
|
+
[msg3, 8],
|
|
127
|
+
[msg3, 10],
|
|
128
|
+
]);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('state test 5', function () {
|
|
132
|
+
const engine = new EngineV2(config);
|
|
133
|
+
const builder = new Builder(config);
|
|
134
|
+
builder.build(engine);
|
|
135
|
+
|
|
136
|
+
const source = testUtils.valueSource();
|
|
137
|
+
testUtils.attachEngineTransformValidator(engine, engine.variablePool.test5, source);
|
|
138
|
+
|
|
139
|
+
source.sendValue('exec', 'ACTIVE', 0);
|
|
140
|
+
source.sendValue('in-fault', false, 2);
|
|
141
|
+
source.sendValue('in-fault', false, 4);
|
|
142
|
+
source.sendValue('in-fault', true, 6);
|
|
143
|
+
source.sendValue('exec', 'READY', 8);
|
|
144
|
+
source.sendValue('in-fault', false, 10);
|
|
145
|
+
|
|
146
|
+
engine.validateFilter([
|
|
147
|
+
['READY', 0],
|
|
148
|
+
['ACTIVE', 2],
|
|
149
|
+
['ACTIVE', 4],
|
|
150
|
+
['STOPPED', 6],
|
|
151
|
+
['READY', 8],
|
|
152
|
+
['READY', 10],
|
|
153
|
+
]);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('state test 6', function () {
|
|
157
|
+
const engine = new EngineV2(config);
|
|
158
|
+
const builder = new Builder(config);
|
|
159
|
+
builder.build(engine);
|
|
160
|
+
|
|
161
|
+
const source = testUtils.valueSource();
|
|
162
|
+
testUtils.attachEngineTransformValidator(engine, engine.variablePool.test6, source);
|
|
163
|
+
|
|
164
|
+
source.sendValue('exec', 'ACTIVE', 0);
|
|
165
|
+
source.sendValue('in-fault', false, 2);
|
|
166
|
+
source.sendValue('in-fault', false, 4);
|
|
167
|
+
source.sendValue('in-fault', true, 6);
|
|
168
|
+
source.sendValue('exec', 'READY', 8);
|
|
169
|
+
source.sendValue('in-fault', false, 10);
|
|
170
|
+
|
|
171
|
+
engine.validateFilter([
|
|
172
|
+
['READY', 0],
|
|
173
|
+
['ACTIVE', 2],
|
|
174
|
+
['ACTIVE', 4],
|
|
175
|
+
['STOPPED', 6],
|
|
176
|
+
['READY', 8],
|
|
177
|
+
['READY', 10],
|
|
178
|
+
]);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it('state test 7', function () {
|
|
182
|
+
const engine = new EngineV2(config);
|
|
183
|
+
const builder = new Builder(config);
|
|
184
|
+
builder.build(engine);
|
|
185
|
+
|
|
186
|
+
const source = testUtils.valueSource();
|
|
187
|
+
testUtils.attachEngineTransformValidator(engine, engine.variablePool.test7, source);
|
|
188
|
+
|
|
189
|
+
source.sendValue('exec', 'ACTIVE', 0);
|
|
190
|
+
source.sendValue('in-fault', false, 2);
|
|
191
|
+
source.sendValue('in-fault', false, 4);
|
|
192
|
+
source.sendValue('in-fault', true, 6);
|
|
193
|
+
source.sendValue('exec', 'READY', 8);
|
|
194
|
+
source.sendValue('in-fault', false, 10);
|
|
195
|
+
|
|
196
|
+
engine.validateFilter([
|
|
197
|
+
['READY', 2],
|
|
198
|
+
['READY', 4],
|
|
199
|
+
['READY', 6],
|
|
200
|
+
['READY', 10],
|
|
201
|
+
]);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it('state test 8', function () {
|
|
205
|
+
const engine = new EngineV2(config);
|
|
206
|
+
const builder = new Builder(config);
|
|
207
|
+
builder.build(engine);
|
|
208
|
+
|
|
209
|
+
const source = testUtils.valueSource();
|
|
210
|
+
testUtils.attachEngineTransformValidator(engine, engine.variablePool.test8, source);
|
|
211
|
+
|
|
212
|
+
expect(engine.variablePool.test8.available).to.eq(false);
|
|
213
|
+
source.sendValue('is-running', true, 2);
|
|
214
|
+
expect(engine.variablePool.test8.available).to.eq(true);
|
|
215
|
+
source.sendValue('irrelevant', true, 3);
|
|
216
|
+
expect(engine.variablePool.test8.available).to.eq(true);
|
|
217
|
+
source.sendValue('is-running', false, 4);
|
|
218
|
+
expect(engine.variablePool.test8.available).to.eq(false);
|
|
219
|
+
|
|
220
|
+
engine.validateFilter([
|
|
221
|
+
['ACTIVE', 2],
|
|
222
|
+
]);
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it('state test 9', function () {
|
|
226
|
+
const engine = new EngineV2(config);
|
|
227
|
+
const builder = new Builder(config);
|
|
228
|
+
builder.build(engine);
|
|
229
|
+
|
|
230
|
+
const source = testUtils.valueSource();
|
|
231
|
+
testUtils.attachEngineTransformValidator(engine, engine.variablePool.test9, source);
|
|
232
|
+
|
|
233
|
+
source.sendValue('exec', 30, 0);
|
|
234
|
+
source.sendValue('in-fault', false, 2);
|
|
235
|
+
source.sendValue('in-fault', false, 4);
|
|
236
|
+
source.sendValue('in-fault', true, 6);
|
|
237
|
+
source.sendValue('exec', 40, 8);
|
|
238
|
+
source.sendValue('in-fault', false, 10);
|
|
239
|
+
|
|
240
|
+
engine.validateFilter([
|
|
241
|
+
[40, 2],
|
|
242
|
+
[40, 4],
|
|
243
|
+
[50, 6],
|
|
244
|
+
[60, 8],
|
|
245
|
+
[50, 10],
|
|
246
|
+
]);
|
|
247
|
+
});
|
|
248
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Threshold = require('../../lib/transform').threshold;
|
|
4
|
+
const testUtils = require('../util/testUtils');
|
|
5
|
+
|
|
6
|
+
describe('threshold transform tests', function () {
|
|
7
|
+
it('thresholds regular', function () {
|
|
8
|
+
const filter = new Threshold({ args: { threshold: 3 } });
|
|
9
|
+
testUtils.attachTransformValidator(filter);
|
|
10
|
+
|
|
11
|
+
filter.test([
|
|
12
|
+
[1.0, 0], [1.5, 1], [1.2, 2], [2.5, 3], [3.5, 4], [5.0, 5], [2.1, 6], [3.0, 7], [3.1, 8], [-5, 9],
|
|
13
|
+
]);
|
|
14
|
+
filter.valdDigital('____^^_^^_', 1);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('thresholds irregular', function () {
|
|
18
|
+
const filter = new Threshold({ args: { threshold: 3 } });
|
|
19
|
+
testUtils.attachTransformValidator(filter);
|
|
20
|
+
|
|
21
|
+
filter.test([
|
|
22
|
+
[1.5, 1], [1.6, 4], [1.5, 5], [4.9, 10], [5.0, 11], [4.9, 15], [1.5, 16],
|
|
23
|
+
]);
|
|
24
|
+
filter.validate([
|
|
25
|
+
[false, 1], [false, 4], [false, 5], [true, 10], [true, 11], [true, 15], [false, 16],
|
|
26
|
+
]);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('thresholds below', function () {
|
|
30
|
+
const filter = new Threshold({ args: { threshold: 3, direction: 'below' } });
|
|
31
|
+
testUtils.attachTransformValidator(filter);
|
|
32
|
+
|
|
33
|
+
filter.test([
|
|
34
|
+
[1.0, 0], [1.5, 1], [1.2, 2], [2.5, 3], [3.5, 4], [5.0, 5], [2.1, 6], [3.0, 7], [3.1, 8], [-5, 9],
|
|
35
|
+
]);
|
|
36
|
+
filter.valdDigital('^^^^__^^_^', 1);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('thresholds strings 1', function () {
|
|
40
|
+
const filter = new Threshold({ args: { threshold: 3 } });
|
|
41
|
+
testUtils.attachTransformValidator(filter);
|
|
42
|
+
|
|
43
|
+
filter.test([
|
|
44
|
+
['1.0', 0], ['1.5', 1], ['1.2', 2], ['2.5', 3], ['3.5', 4], ['5.0', 5], ['2.1', 6], ['3.0', 7], ['3.1', 8], ['-5', 9],
|
|
45
|
+
]);
|
|
46
|
+
filter.valdDigital('____^^_^^_', 1);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('thresholds strings 2', function () {
|
|
50
|
+
const filter = new Threshold({ args: { threshold: 1 } });
|
|
51
|
+
testUtils.attachTransformValidator(filter);
|
|
52
|
+
|
|
53
|
+
filter.test([
|
|
54
|
+
['true', 0], ['false', 1], ['false', 2], ['true', 3],
|
|
55
|
+
]);
|
|
56
|
+
filter.valdDigital('^__^', 1);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('thresholds boolean', function () {
|
|
60
|
+
const filter = new Threshold({ args: { threshold: 1 } });
|
|
61
|
+
testUtils.attachTransformValidator(filter);
|
|
62
|
+
|
|
63
|
+
filter.test([
|
|
64
|
+
[true, 0], [false, 1], [false, 2], [true, 3],
|
|
65
|
+
]);
|
|
66
|
+
filter.valdDigital('^__^', 1);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('thresholds trash', function () {
|
|
70
|
+
const filter = new Threshold({ args: { threshold: 1 } });
|
|
71
|
+
testUtils.attachTransformValidator(filter);
|
|
72
|
+
|
|
73
|
+
filter.test([
|
|
74
|
+
['trash', 0], [NaN, 1], ['90XX', 2],
|
|
75
|
+
]);
|
|
76
|
+
filter.valdDigital('___', 1);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Buffer = require('buffer/').Buffer;
|
|
4
|
+
const ToBuffer = require('../../lib/transform').toBuffer;
|
|
5
|
+
const testUtils = require('../util/testUtils');
|
|
6
|
+
|
|
7
|
+
describe('to-buffer transform tests', async function () {
|
|
8
|
+
const setupFilter = (spec) => {
|
|
9
|
+
return new ToBuffer(spec);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
it('parses different formats', async function () {
|
|
13
|
+
const filters = [
|
|
14
|
+
setupFilter('int32le'),
|
|
15
|
+
setupFilter('int32 LE'),
|
|
16
|
+
setupFilter('type=int32 LE'),
|
|
17
|
+
setupFilter('int32, order=LE'),
|
|
18
|
+
setupFilter('int32 order=LE'),
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
const expectedBuf = Buffer.from([255, 201, 154, 59]);
|
|
22
|
+
|
|
23
|
+
await Promise.all(filters.map(f => testUtils.testValue(f, 999999999, expectedBuf)));
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('converts values to buffers of different types', async function () {
|
|
27
|
+
await testUtils.testValue(setupFilter('int32 le'), Buffer.from([255, 201, 154, 59]), Buffer.from([255, 201, 154, 59]));
|
|
28
|
+
|
|
29
|
+
await testUtils.testValue(setupFilter('int8'), -1, Buffer.from([255]));
|
|
30
|
+
await testUtils.testValue(setupFilter('uint8'), 255, Buffer.from([255]));
|
|
31
|
+
await testUtils.testValue(setupFilter('int16 le'), -13825, Buffer.from([255, 201]));
|
|
32
|
+
await testUtils.testValue(setupFilter('uint16 le'), 51711, Buffer.from([255, 201]));
|
|
33
|
+
await testUtils.testValue(setupFilter('int32 le'), 999999999, Buffer.from([255, 201, 154, 59]));
|
|
34
|
+
await testUtils.testValue(setupFilter('uint32 le'), 999999999, Buffer.from([255, 201, 154, 59]));
|
|
35
|
+
await testUtils.testValue(setupFilter('int64 le'), BigInt(999999999), Buffer.from([255, 201, 154, 59, 0, 0, 0, 0]));
|
|
36
|
+
await testUtils.testValue(setupFilter('uint64 le'), BigInt(999999999), Buffer.from([255, 201, 154, 59, 0, 0, 0, 0]));
|
|
37
|
+
await testUtils.testValue(setupFilter('int16 be'), -55, Buffer.from([255, 201]));
|
|
38
|
+
await testUtils.testValue(setupFilter('uint16 be'), 65481, Buffer.from([255, 201]));
|
|
39
|
+
await testUtils.testValue(setupFilter('int32 be'), -3564997, Buffer.from([255, 201, 154, 59]));
|
|
40
|
+
await testUtils.testValue(setupFilter('uint32 be'), 4291402299, Buffer.from([255, 201, 154, 59]));
|
|
41
|
+
await testUtils.testValue(setupFilter('int64 be'), BigInt(-15311545525338112), Buffer.from([255, 201, 154, 59, 0, 0, 0, 0]));
|
|
42
|
+
await testUtils.testValue(setupFilter('uint64 be'), BigInt(18431432528184213504), Buffer.from([255, 201, 154, 59, 0, 0, 0, 0]));
|
|
43
|
+
|
|
44
|
+
await testUtils.testValue(setupFilter('float be'), -42, Buffer.from([0xc2, 0x28, 0, 0]));
|
|
45
|
+
await testUtils.testValue(setupFilter('float le'), -42, Buffer.from([0, 0, 0x28, 0xc2]));
|
|
46
|
+
await testUtils.testValue(setupFilter('double be'), -12345, Buffer.from([0xc0, 0xc8, 0x1c, 0x80, 0, 0, 0, 0]));
|
|
47
|
+
await testUtils.testValue(setupFilter('double le'), -12345, Buffer.from([0, 0, 0, 0, 0x80, 0x1c, 0xc8, 0xc0]));
|
|
48
|
+
|
|
49
|
+
await testUtils.testValue(setupFilter('string'), 'quick brown fox', Buffer.from([
|
|
50
|
+
0x71, 0x75, 0x69, 0x63, 0x6b, 0x20, 0x62, 0x72, 0x6f, 0x77, 0x6e, 0x20, 0x66, 0x6f, 0x78
|
|
51
|
+
]));
|
|
52
|
+
|
|
53
|
+
await testUtils.testValue(setupFilter('int32 le'), '999999999', Buffer.from([255, 201, 154, 59]));
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('converts arrays of values to buffers', async function () {
|
|
57
|
+
await testUtils.testValue(setupFilter('int32 le'), [999999999, 0], Buffer.from([255, 201, 154, 59, 0, 0, 0, 0]));
|
|
58
|
+
await testUtils.testValue(setupFilter('int32 le'), [Buffer.from([12, 13]), 999999999], Buffer.from([12, 13, 255, 201, 154, 59]));
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Toggle = require('../../lib/transform').toggle;
|
|
4
|
+
const EngineV2 = require('../../lib/engine/engineV2');
|
|
5
|
+
const Builder = require('../../lib/engine/transformBuilderV2');
|
|
6
|
+
const testUtils = require('../util/testUtils');
|
|
7
|
+
|
|
8
|
+
describe('toggle transform tests', function () {
|
|
9
|
+
it('toggle regular', function () {
|
|
10
|
+
const filter = new Toggle(testUtils.standardBuilderArgs(null, 'test1'));
|
|
11
|
+
testUtils.attachTransformValidator(filter);
|
|
12
|
+
|
|
13
|
+
filter.testDigital('__^^__^^^^____^____', 1);
|
|
14
|
+
filter.valdDigital('__^^^^________^^^^^', 1);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('toggle regular default high', function () {
|
|
18
|
+
const filter = new Toggle(testUtils.standardBuilderArgs(null, 'test1', { init: true }));
|
|
19
|
+
testUtils.attachTransformValidator(filter);
|
|
20
|
+
|
|
21
|
+
filter.testDigital('__^^__^^^^____^____', 1);
|
|
22
|
+
filter.valdDigital('^^____^^^^^^^^_____', 1);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe('rising-edge-counter full engine config file tests', function () {
|
|
27
|
+
let config;
|
|
28
|
+
before(async () => {
|
|
29
|
+
config = await testUtils.loadConfig('transform/toggle.yml');
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('no reset expression', function () {
|
|
33
|
+
const engine = new EngineV2(config);
|
|
34
|
+
const builder = new Builder(config);
|
|
35
|
+
builder.build(engine);
|
|
36
|
+
|
|
37
|
+
const source = testUtils.valueSource();
|
|
38
|
+
testUtils.attachEngineTransformValidator(engine, engine.variablePool.var1, source);
|
|
39
|
+
|
|
40
|
+
source.sendValues('active', [[false, 0], [true, 2], [false, 4], [true, 6]]);
|
|
41
|
+
source.sendValues('active', [[false, 8], [true, 10], [false, 12], [true, 14]]);
|
|
42
|
+
|
|
43
|
+
engine.validateFilter([
|
|
44
|
+
[false, 0], [true, 2], [true, 4], [false, 6],
|
|
45
|
+
[false, 8], [true, 10], [true, 12], [false, 14],
|
|
46
|
+
]);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('default expression', function () {
|
|
50
|
+
const engine = new EngineV2(config);
|
|
51
|
+
const builder = new Builder(config);
|
|
52
|
+
builder.build(engine);
|
|
53
|
+
|
|
54
|
+
const source = testUtils.valueSource();
|
|
55
|
+
testUtils.attachEngineTransformValidator(engine, engine.variablePool.var2, source);
|
|
56
|
+
|
|
57
|
+
source.sendValues('active', [[false, 0], [true, 2], [false, 4], [true, 6]]);
|
|
58
|
+
source.sendValues('active', [[false, 8], [true, 10], [false, 12], [true, 14]]);
|
|
59
|
+
|
|
60
|
+
engine.validateFilter([
|
|
61
|
+
[true, 0], [false, 2], [false, 4], [true, 6],
|
|
62
|
+
[true, 8], [false, 10], [false, 12], [true, 14],
|
|
63
|
+
]);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('reset expression referencing data source', function () {
|
|
67
|
+
const engine = new EngineV2(config);
|
|
68
|
+
const builder = new Builder(config);
|
|
69
|
+
builder.build(engine);
|
|
70
|
+
|
|
71
|
+
const source = testUtils.valueSource();
|
|
72
|
+
testUtils.attachEngineTransformValidator(engine, engine.variablePool.var3, source);
|
|
73
|
+
|
|
74
|
+
source.sendValues('active', [[false, 0], [true, 2], [false, 4], [false, 6]]);
|
|
75
|
+
source.sendValue('program', 5, 7);
|
|
76
|
+
source.sendValues('active', [[false, 8], [true, 10], [false, 12], [true, 14]]);
|
|
77
|
+
source.sendValue('program', 10, 15);
|
|
78
|
+
source.sendValues('active', [[false, 16], [true, 18], [false, 20], [true, 22]]);
|
|
79
|
+
source.sendValue('program', 5, 23);
|
|
80
|
+
source.sendValues('active', [[false, 24], [true, 26], [false, 28], [true, 30]]);
|
|
81
|
+
|
|
82
|
+
engine.validateFilter([
|
|
83
|
+
[false, 0], [true, 2], [true, 4], [true, 6],
|
|
84
|
+
[true, 7],
|
|
85
|
+
[true, 8], [false, 10], [false, 12], [true, 14],
|
|
86
|
+
[false, 15],
|
|
87
|
+
[false, 16], [false, 18], [false, 20], [false, 22],
|
|
88
|
+
[false, 23],
|
|
89
|
+
[false, 24], [true, 26], [true, 28], [false, 30],
|
|
90
|
+
]);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Trim = require('../../lib/transform').trim;
|
|
4
|
+
const testUtils = require('../util/testUtils');
|
|
5
|
+
|
|
6
|
+
describe('trim transform tests', function () {
|
|
7
|
+
it('trim irregular', function () {
|
|
8
|
+
const filter = new Trim();
|
|
9
|
+
testUtils.attachTransformValidator(filter);
|
|
10
|
+
|
|
11
|
+
filter.test([
|
|
12
|
+
['simple test', 0],
|
|
13
|
+
[' another test', 2],
|
|
14
|
+
['trailing test ', 4],
|
|
15
|
+
[' lead and trail ', 6],
|
|
16
|
+
['\nnewline test\r\n', 8],
|
|
17
|
+
[' control codes', 10],
|
|
18
|
+
[123, 12],
|
|
19
|
+
]);
|
|
20
|
+
filter.validate([
|
|
21
|
+
['simple test', 0],
|
|
22
|
+
['another test', 2],
|
|
23
|
+
['trailing test', 4],
|
|
24
|
+
['lead and trail', 6],
|
|
25
|
+
['newline test', 8],
|
|
26
|
+
['control codes', 10],
|
|
27
|
+
[123, 12],
|
|
28
|
+
]);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const ValueChange = require('../../lib/transform').valueChange;
|
|
4
|
+
const testUtils = require('../util/testUtils');
|
|
5
|
+
|
|
6
|
+
describe('value-change transform tests', function () {
|
|
7
|
+
it('value-change regular digital', function () {
|
|
8
|
+
const filter = new ValueChange();
|
|
9
|
+
testUtils.attachTransformValidator(filter);
|
|
10
|
+
|
|
11
|
+
filter.testDigital('__^^__^^^^____^_^^^^^_', 1);
|
|
12
|
+
filter.valdDigital('|_|_|_|___|___|||____|', 1);
|
|
13
|
+
});
|
|
14
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const ValueDecrease = require('../../lib/transform').valueDecrease;
|
|
4
|
+
const testUtils = require('../util/testUtils');
|
|
5
|
+
|
|
6
|
+
describe('value-decrease transform tests', function () {
|
|
7
|
+
it('value-decreases irregular digital', function () {
|
|
8
|
+
const filter = new ValueDecrease();
|
|
9
|
+
testUtils.attachTransformValidator(filter);
|
|
10
|
+
|
|
11
|
+
filter.test([
|
|
12
|
+
[1, 2], [1, 4], [2, 6], [4, 10], [0, 14], [1, 15], [3, 16], [1, 21],
|
|
13
|
+
]);
|
|
14
|
+
filter.validate([
|
|
15
|
+
[true, 2], [false, 2], [false, 4], [false, 6], [false, 10], [true, 14], [false, 14],
|
|
16
|
+
[false, 15], [false, 16], [true, 21], [false, 21],
|
|
17
|
+
]);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('value-decreases string', function () {
|
|
21
|
+
const filter = new ValueDecrease();
|
|
22
|
+
testUtils.attachTransformValidator(filter);
|
|
23
|
+
|
|
24
|
+
filter.test([
|
|
25
|
+
['1', 2], ['1', 4], ['2', 6], ['10', 10], ['0', 14], ['1', 15], ['3', 16], ['1', 21],
|
|
26
|
+
]);
|
|
27
|
+
filter.validate([
|
|
28
|
+
[true, 2], [false, 2], [false, 4], [false, 6], [false, 10], [true, 14], [false, 14],
|
|
29
|
+
[false, 15], [false, 16], [true, 21], [false, 21],
|
|
30
|
+
]);
|
|
31
|
+
});
|
|
32
|
+
});
|