@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,60 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Buffer = require('buffer/').Buffer;
|
|
4
|
+
const FromBuffer = require('../../lib/transform').fromBuffer;
|
|
5
|
+
const testUtils = require('../util/testUtils');
|
|
6
|
+
|
|
7
|
+
describe('from-buffer transform tests', async function () {
|
|
8
|
+
const setupFilter = (spec) => {
|
|
9
|
+
return new FromBuffer(spec);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
it('parses different formats', async function () {
|
|
13
|
+
const filters = [
|
|
14
|
+
setupFilter('4 int32le'),
|
|
15
|
+
setupFilter('4 int32 LE'),
|
|
16
|
+
setupFilter('4 type=int32 LE'),
|
|
17
|
+
setupFilter('4 int32, order=LE'),
|
|
18
|
+
setupFilter('offset=4 int32 order=LE'),
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
const buf = Buffer.from([43, 153, 23, 0, 255, 201, 154, 59, 0, 0, 0, 0]);
|
|
22
|
+
|
|
23
|
+
await Promise.all(filters.map(f => testUtils.testValue(f, buf, 999999999)));
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('reads data of different types', async function () {
|
|
27
|
+
const buf = Buffer.from([43, 153, 23, 0, 255, 201, 154, 59, 0, 0, 0, 0]);
|
|
28
|
+
|
|
29
|
+
await testUtils.testValue(setupFilter('4 int8'), buf, -1);
|
|
30
|
+
await testUtils.testValue(setupFilter('4 uint8'), buf, 255);
|
|
31
|
+
await testUtils.testValue(setupFilter('4 int16 le'), buf, -13825);
|
|
32
|
+
await testUtils.testValue(setupFilter('4 uint16 le'), buf, 51711);
|
|
33
|
+
await testUtils.testValue(setupFilter('4 int32 le'), buf, 999999999);
|
|
34
|
+
await testUtils.testValue(setupFilter('4 uint32 le'), buf, 999999999);
|
|
35
|
+
await testUtils.testValue(setupFilter('4 int64 le'), buf, BigInt(999999999)); // eslint-disable-line
|
|
36
|
+
await testUtils.testValue(setupFilter('4 uint64 le'), buf, BigInt(999999999)); // eslint-disable-line
|
|
37
|
+
await testUtils.testValue(setupFilter('4 int16 be'), buf, -55);
|
|
38
|
+
await testUtils.testValue(setupFilter('4 uint16 be'), buf, 65481);
|
|
39
|
+
await testUtils.testValue(setupFilter('4 int32 be'), buf, -3564997);
|
|
40
|
+
await testUtils.testValue(setupFilter('4 uint32 be'), buf, 4291402299);
|
|
41
|
+
await testUtils.testValue(setupFilter('4 int64 be'), buf, BigInt(-15311545525338112)); // eslint-disable-line
|
|
42
|
+
await testUtils.testValue(setupFilter('4 uint64 be'), buf, BigInt(18431432528184213504)); // eslint-disable-line
|
|
43
|
+
|
|
44
|
+
const buf2 = Buffer.from([0xc2, 0x28, 0, 0, 0xc0, 0xc8, 0x1c, 0x80, 0, 0, 0, 0]);
|
|
45
|
+
const buf3 = Buffer.from([0, 0, 0x28, 0xc2, 0, 0, 0, 0, 0x80, 0x1c, 0xc8, 0xc0]);
|
|
46
|
+
|
|
47
|
+
await testUtils.testValue(setupFilter('0 float be'), buf2, -42);
|
|
48
|
+
await testUtils.testValue(setupFilter('0 float le'), buf3, -42);
|
|
49
|
+
await testUtils.testValue(setupFilter('4 double be'), buf2, -12345);
|
|
50
|
+
await testUtils.testValue(setupFilter('4 double le'), buf3, -12345);
|
|
51
|
+
|
|
52
|
+
const buf4 = Buffer.from([
|
|
53
|
+
0x71, 0x75, 0x69, 0x63, 0x6b, 0x20, 0x62, 0x72, 0x6f, 0x77, 0x6e, 0x20, 0x66, 0x6f, 0x78
|
|
54
|
+
]);
|
|
55
|
+
|
|
56
|
+
await testUtils.testValue(setupFilter('0 string 15'), buf4, 'quick brown fox');
|
|
57
|
+
await testUtils.testValue(setupFilter('0 string length=15'), buf4, 'quick brown fox');
|
|
58
|
+
await testUtils.testValue(setupFilter('0 string 5'), buf4, 'quick');
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Hash = require('../../lib/transform').hash;
|
|
4
|
+
const testUtils = require('../util/testUtils');
|
|
5
|
+
|
|
6
|
+
describe('hash transform tests', function () {
|
|
7
|
+
it('hash md5', function () {
|
|
8
|
+
const filter = new Hash('md5');
|
|
9
|
+
testUtils.attachTransformValidator(filter);
|
|
10
|
+
|
|
11
|
+
filter.test([
|
|
12
|
+
['bulbasaur', 2], ['charmander', 4.5], ['squirtle', 11],
|
|
13
|
+
]);
|
|
14
|
+
filter.validate([
|
|
15
|
+
['164e304daed9e2142a6d84681e3ba669', 2],
|
|
16
|
+
['f0eb43ee186dc087bda60ba3441a0b30', 4.5],
|
|
17
|
+
['7577f859913b3b22763a174e2848e65a', 11],
|
|
18
|
+
]);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('hash sha1', function () {
|
|
22
|
+
const filter = new Hash('sha1');
|
|
23
|
+
testUtils.attachTransformValidator(filter);
|
|
24
|
+
|
|
25
|
+
filter.test([
|
|
26
|
+
['bulbasaur', 2], ['charmander', 4.5], ['squirtle', 11],
|
|
27
|
+
]);
|
|
28
|
+
filter.validate([
|
|
29
|
+
['7d24951a1ca265d9032b543992baca78c7e15fa1', 2],
|
|
30
|
+
['838971bc69ae6a984a2547d998b6657cfba808b8', 4.5],
|
|
31
|
+
['0d2ddb9232576370351b3e298847770c54f2f381', 11],
|
|
32
|
+
]);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Builder = require('../../lib/engine/transformBuilderV2');
|
|
4
|
+
const EngineV2 = require('../../lib/engine/engineV2');
|
|
5
|
+
const testUtils = require('../util/testUtils');
|
|
6
|
+
|
|
7
|
+
describe('ignore-value config file tests', async function () {
|
|
8
|
+
let config;
|
|
9
|
+
before(async () => {
|
|
10
|
+
config = await testUtils.loadConfig('transform/ignoreValue.yml');
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const makeSourceEngine = (varName) => {
|
|
14
|
+
const engine = new EngineV2(config);
|
|
15
|
+
const builder = new Builder(config);
|
|
16
|
+
builder.build(engine);
|
|
17
|
+
|
|
18
|
+
const source = testUtils.valueSource();
|
|
19
|
+
testUtils.attachEngineTransformValidator(engine, engine.variablePool[varName], source);
|
|
20
|
+
|
|
21
|
+
return { source, engine };
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
it('ignores constant value', async function () {
|
|
25
|
+
const { source, engine } = makeSourceEngine('test1');
|
|
26
|
+
|
|
27
|
+
source.sendValues('program', [
|
|
28
|
+
['O1001', 0],
|
|
29
|
+
['warmup', 2],
|
|
30
|
+
['O9999', 4],
|
|
31
|
+
]);
|
|
32
|
+
|
|
33
|
+
engine.validateFilter([
|
|
34
|
+
['O1001', 0],
|
|
35
|
+
['O1001', 2],
|
|
36
|
+
['O9999', 4],
|
|
37
|
+
]);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('ignores empty string', async function () {
|
|
41
|
+
const { source, engine } = makeSourceEngine('test2');
|
|
42
|
+
|
|
43
|
+
source.sendValues('program', [
|
|
44
|
+
['O1001', 0],
|
|
45
|
+
['', 2],
|
|
46
|
+
['O9999', 4],
|
|
47
|
+
]);
|
|
48
|
+
|
|
49
|
+
engine.validateFilter([
|
|
50
|
+
['O1001', 0],
|
|
51
|
+
['O1001', 2],
|
|
52
|
+
['O9999', 4],
|
|
53
|
+
]);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('ignores pattern', async function () {
|
|
57
|
+
const { source, engine } = makeSourceEngine('test3');
|
|
58
|
+
|
|
59
|
+
source.sendValues('program', [
|
|
60
|
+
['O1001', 0],
|
|
61
|
+
['warmup', 2],
|
|
62
|
+
['O9999', 4],
|
|
63
|
+
['warmup12', 6],
|
|
64
|
+
]);
|
|
65
|
+
|
|
66
|
+
engine.validateFilter([
|
|
67
|
+
['O1001', 0],
|
|
68
|
+
['O1001', 2],
|
|
69
|
+
['O9999', 4],
|
|
70
|
+
['O9999', 6],
|
|
71
|
+
]);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('ignores expression', async function () {
|
|
75
|
+
const { source, engine } = makeSourceEngine('test4');
|
|
76
|
+
|
|
77
|
+
source.sendValues('program', [
|
|
78
|
+
['O1001', 0],
|
|
79
|
+
['warmup', 2],
|
|
80
|
+
['O9999', 4],
|
|
81
|
+
]);
|
|
82
|
+
|
|
83
|
+
engine.validateFilter([
|
|
84
|
+
['O1001', 0],
|
|
85
|
+
['O1001', 2],
|
|
86
|
+
['O9999', 4],
|
|
87
|
+
]);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('ignores expression', async function () {
|
|
91
|
+
const { source, engine } = makeSourceEngine('test5');
|
|
92
|
+
|
|
93
|
+
source.sendValue('pmode', 1, 0);
|
|
94
|
+
source.sendValue('program', 'O1001', 0);
|
|
95
|
+
source.sendValue('pmode', 5, 2);
|
|
96
|
+
source.sendValue('program', 'warmup', 2);
|
|
97
|
+
source.sendValue('pmode', 1, 4);
|
|
98
|
+
source.sendValue('program', 'O9999', 6);
|
|
99
|
+
|
|
100
|
+
engine.validateFilter([
|
|
101
|
+
['O1001', 0],
|
|
102
|
+
['O1001', 2],
|
|
103
|
+
['warmup', 4],
|
|
104
|
+
['O9999', 6],
|
|
105
|
+
]);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('ignores constant value with default', async function () {
|
|
109
|
+
const { source, engine } = makeSourceEngine('test6');
|
|
110
|
+
|
|
111
|
+
source.sendValues('program', [
|
|
112
|
+
['warmup', 0],
|
|
113
|
+
['warmup', 2],
|
|
114
|
+
['O9999', 4],
|
|
115
|
+
]);
|
|
116
|
+
|
|
117
|
+
engine.validateFilter([
|
|
118
|
+
[null, 0],
|
|
119
|
+
[null, 2],
|
|
120
|
+
['O9999', 4],
|
|
121
|
+
]);
|
|
122
|
+
});
|
|
123
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Invert = require('../../lib/transform').invert;
|
|
4
|
+
const testUtils = require('../util/testUtils');
|
|
5
|
+
|
|
6
|
+
describe('invert transform tests', function () {
|
|
7
|
+
it('invert regular', function () {
|
|
8
|
+
const filter = new Invert();
|
|
9
|
+
testUtils.attachTransformValidator(filter);
|
|
10
|
+
|
|
11
|
+
filter.testDigital('__^^_^___^^^', 1);
|
|
12
|
+
filter.valdDigital('^^__^_^^^___', 1);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('invert irregular', function () {
|
|
16
|
+
const filter = new Invert();
|
|
17
|
+
testUtils.attachTransformValidator(filter);
|
|
18
|
+
|
|
19
|
+
filter.test([
|
|
20
|
+
[true, 2], [true, 4.5], [false, 11], [true, 12],
|
|
21
|
+
]);
|
|
22
|
+
filter.validate([
|
|
23
|
+
[false, 2], [false, 4.5], [true, 11], [false, 12],
|
|
24
|
+
]);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const EngineV2 = require('../../lib/engine/engineV2');
|
|
4
|
+
const Builder = require('../../lib/engine/transformBuilderV2');
|
|
5
|
+
const testUtils = require('../util/testUtils');
|
|
6
|
+
|
|
7
|
+
describe('latch full engine config file tests', function () {
|
|
8
|
+
let config;
|
|
9
|
+
before(async () => {
|
|
10
|
+
config = await testUtils.loadConfig('transform/latch.yml');
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('basic latch test', function () {
|
|
14
|
+
const engine = new EngineV2(config);
|
|
15
|
+
const builder = new Builder(config);
|
|
16
|
+
builder.build(engine);
|
|
17
|
+
|
|
18
|
+
const source = testUtils.valueSource();
|
|
19
|
+
testUtils.attachEngineTransformValidator(engine, engine.variablePool.var1, source);
|
|
20
|
+
|
|
21
|
+
source.sendValues('counter', [[1, 0], [2, 1], [3, 2]]);
|
|
22
|
+
source.sendValue('execution', 'ACTIVE', 3);
|
|
23
|
+
source.sendValues('counter', [[4, 4], [5, 5], [6, 6]]);
|
|
24
|
+
source.sendValue('execution', 'READY', 7);
|
|
25
|
+
source.sendValues('counter', [[7, 8], [8, 9], [9, 10]]);
|
|
26
|
+
source.sendValue('execution', 'ACTIVE', 11);
|
|
27
|
+
source.sendValues('counter', [[10, 12]]);
|
|
28
|
+
|
|
29
|
+
engine.validateFilter([
|
|
30
|
+
[3, 3], [4, 4], [5, 5], [6, 6], [6, 7], [6, 8], [6, 9], [6, 10], [9, 11], [10, 12]
|
|
31
|
+
]);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Builder = require('../../lib/engine/transformBuilderV2');
|
|
4
|
+
const EngineV2 = require('../../lib/engine/engineV2');
|
|
5
|
+
const testUtils = require('../util/testUtils');
|
|
6
|
+
|
|
7
|
+
describe('latch-value config file tests', async function () {
|
|
8
|
+
let config;
|
|
9
|
+
before(async () => {
|
|
10
|
+
config = await testUtils.loadConfig('transform/latchValue.yml');
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const makeSourceEngine = (varName) => {
|
|
14
|
+
const engine = new EngineV2(config);
|
|
15
|
+
const builder = new Builder(config);
|
|
16
|
+
builder.build(engine);
|
|
17
|
+
|
|
18
|
+
const source = testUtils.valueSource();
|
|
19
|
+
testUtils.attachEngineTransformValidator(engine, engine.variablePool[varName], source);
|
|
20
|
+
|
|
21
|
+
return { source, engine };
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const sendTestData = (source) => {
|
|
25
|
+
source.sendValue('pmode', 1, 0);
|
|
26
|
+
source.sendValue('program', 'O1001', 0);
|
|
27
|
+
source.sendValue('program', 'O1009', 2);
|
|
28
|
+
source.sendValue('pmode', 5, 3);
|
|
29
|
+
source.sendValue('program', 'O9999', 4);
|
|
30
|
+
source.sendValue('pmode', 1, 4);
|
|
31
|
+
source.sendValue('program', 'O1234', 6);
|
|
32
|
+
source.sendValue('pmode', 5, 7);
|
|
33
|
+
source.sendValue('program', 'O1234', 8);
|
|
34
|
+
source.sendValue('pmode', 1, 9);
|
|
35
|
+
source.sendValue('program', 'O9999', 10);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
it('latches first value', async function () {
|
|
39
|
+
const { source, engine } = makeSourceEngine('test1');
|
|
40
|
+
|
|
41
|
+
source.sendValues('program', [
|
|
42
|
+
['O1001', 0],
|
|
43
|
+
['warmup', 2],
|
|
44
|
+
['O9999', 4],
|
|
45
|
+
]);
|
|
46
|
+
|
|
47
|
+
engine.validateFilter([
|
|
48
|
+
['O1001', 0],
|
|
49
|
+
['O1001', 2],
|
|
50
|
+
['O1001', 4],
|
|
51
|
+
]);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('resets latch', async function () {
|
|
55
|
+
const { source, engine } = makeSourceEngine('test2');
|
|
56
|
+
|
|
57
|
+
sendTestData(source);
|
|
58
|
+
|
|
59
|
+
engine.validateFilter([
|
|
60
|
+
['O1001', 0],
|
|
61
|
+
['O1001', 2],
|
|
62
|
+
['O1009', 3],
|
|
63
|
+
['O9999', 4],
|
|
64
|
+
['O9999', 6],
|
|
65
|
+
['O1234', 7],
|
|
66
|
+
['O1234', 8],
|
|
67
|
+
['O1234', 9],
|
|
68
|
+
['O1234', 10],
|
|
69
|
+
]);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('resets latch on change', async function () {
|
|
73
|
+
const { source, engine } = makeSourceEngine('test3');
|
|
74
|
+
|
|
75
|
+
sendTestData(source);
|
|
76
|
+
|
|
77
|
+
engine.validateFilter([
|
|
78
|
+
['O1001', 0],
|
|
79
|
+
['O1001', 2],
|
|
80
|
+
['O1009', 3],
|
|
81
|
+
['O9999', 4],
|
|
82
|
+
['O1234', 6],
|
|
83
|
+
['O1234', 7],
|
|
84
|
+
['O1234', 8],
|
|
85
|
+
['O1234', 9],
|
|
86
|
+
['O9999', 10],
|
|
87
|
+
]);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('resets latch with reset value', async function () {
|
|
91
|
+
const { source, engine } = makeSourceEngine('test4');
|
|
92
|
+
|
|
93
|
+
sendTestData(source);
|
|
94
|
+
|
|
95
|
+
engine.validateFilter([
|
|
96
|
+
['O1001', 0],
|
|
97
|
+
['O1001', 2],
|
|
98
|
+
['O0000', 3],
|
|
99
|
+
['O0000', 4],
|
|
100
|
+
['O9999', 4],
|
|
101
|
+
['O9999', 6],
|
|
102
|
+
['O0000', 7],
|
|
103
|
+
['O0000', 8],
|
|
104
|
+
['O1234', 9],
|
|
105
|
+
['O1234', 10],
|
|
106
|
+
]);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('resets latch with reset value and latch on change', async function () {
|
|
110
|
+
const { source, engine } = makeSourceEngine('test5');
|
|
111
|
+
|
|
112
|
+
sendTestData(source);
|
|
113
|
+
|
|
114
|
+
engine.validateFilter([
|
|
115
|
+
['O1001', 0],
|
|
116
|
+
['O1001', 2],
|
|
117
|
+
['O0000', 3],
|
|
118
|
+
['O0000', 4],
|
|
119
|
+
['O1234', 6],
|
|
120
|
+
['O0000', 7],
|
|
121
|
+
['O0000', 8],
|
|
122
|
+
['O0000', 9],
|
|
123
|
+
['O9999', 10],
|
|
124
|
+
]);
|
|
125
|
+
});
|
|
126
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const EventEmitter = require('eventemitter3');
|
|
4
|
+
const LogicAnd = require('../../lib/transform').logicAnd;
|
|
5
|
+
const EngineV2 = require('../../lib/engine/engineV2');
|
|
6
|
+
const testUtils = require('../util/testUtils');
|
|
7
|
+
const math = require('../../lib/math');
|
|
8
|
+
|
|
9
|
+
describe('logic-and transform tests', function () {
|
|
10
|
+
let config;
|
|
11
|
+
before(async () => {
|
|
12
|
+
config = await testUtils.loadConfig('transform/logicAnd.yml');
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('logic-and regular 1', function () {
|
|
16
|
+
const engine = new EngineV2(config);
|
|
17
|
+
const source = new ValueSource();
|
|
18
|
+
engine.addValueSource(source);
|
|
19
|
+
|
|
20
|
+
const filter = new LogicAnd({
|
|
21
|
+
engine,
|
|
22
|
+
path: 'variables.var2.1.and',
|
|
23
|
+
args: { compiledExpression: math.compile('true') },
|
|
24
|
+
});
|
|
25
|
+
testUtils.attachTransformValidator(filter);
|
|
26
|
+
|
|
27
|
+
filter.testDigital('__^^__^^^^____^_^^^^^_', 1);
|
|
28
|
+
filter.valdDigital('__^^__^^^^____^_^^^^^_', 1);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('logic-and regular 2', function () {
|
|
32
|
+
const engine = new EngineV2(config);
|
|
33
|
+
const source = new ValueSource();
|
|
34
|
+
engine.addValueSource(source);
|
|
35
|
+
|
|
36
|
+
source.sendValue('counter', 0, 0);
|
|
37
|
+
|
|
38
|
+
const filter = new LogicAnd({
|
|
39
|
+
engine,
|
|
40
|
+
path: 'variables.var1.1.and',
|
|
41
|
+
args: { compiledExpression: math.compile('counter % 2 == 0') },
|
|
42
|
+
});
|
|
43
|
+
testUtils.attachTransformValidator(filter);
|
|
44
|
+
|
|
45
|
+
filter.testDigital('__^^__^^^^____^_^^^^^_', 1, {
|
|
46
|
+
itemPreProcess: (value, time) => { engine.getState('counter').value = time; },
|
|
47
|
+
});
|
|
48
|
+
filter.valdDigital('__^___^_^_____^_^_^_^_', 1);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('logic-and irregular', function () {
|
|
52
|
+
const engine = new EngineV2(config);
|
|
53
|
+
const source = new ValueSource();
|
|
54
|
+
engine.addValueSource(source);
|
|
55
|
+
|
|
56
|
+
source.sendValue('counter', 0, 0);
|
|
57
|
+
|
|
58
|
+
const filter = new LogicAnd({
|
|
59
|
+
engine,
|
|
60
|
+
path: 'variables.var1.1.and',
|
|
61
|
+
args: { compiledExpression: math.compile('counter > 10') },
|
|
62
|
+
});
|
|
63
|
+
testUtils.attachTransformValidator(filter);
|
|
64
|
+
|
|
65
|
+
filter.test([
|
|
66
|
+
[true, 1], [false, 2], [true, 5], [false, 8], [true, 10], [false, 11], [true, 12], [false, 15], [true, 18],
|
|
67
|
+
], {
|
|
68
|
+
itemPreProcess: (value, time) => { engine.getState('counter').value = time; },
|
|
69
|
+
});
|
|
70
|
+
filter.validate([
|
|
71
|
+
[false, 1], [false, 2], [false, 5], [false, 8], [false, 10], [false, 11], [true, 12], [false, 15], [true, 18],
|
|
72
|
+
]);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
class ValueSource extends EventEmitter {
|
|
77
|
+
sendValue(name, value, time) {
|
|
78
|
+
this.emit('update', name, value, time);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const EventEmitter = require('eventemitter3');
|
|
4
|
+
const LogicOr = require('../../lib/transform').logicOr;
|
|
5
|
+
const EngineV2 = require('../../lib/engine/engineV2');
|
|
6
|
+
const testUtils = require('../util/testUtils');
|
|
7
|
+
const math = require('../../lib/math');
|
|
8
|
+
|
|
9
|
+
describe('logic-or transform tests', function () {
|
|
10
|
+
let config;
|
|
11
|
+
before(async () => {
|
|
12
|
+
config = await testUtils.loadConfig('transform/logicOr.yml');
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('logic-or regular 1', function () {
|
|
16
|
+
const engine = new EngineV2(config);
|
|
17
|
+
const source = new ValueSource();
|
|
18
|
+
engine.addValueSource(source);
|
|
19
|
+
|
|
20
|
+
const filter = new LogicOr({
|
|
21
|
+
engine,
|
|
22
|
+
path: 'variables.var2.1.or',
|
|
23
|
+
args: { compiledExpression: math.compile('false') },
|
|
24
|
+
});
|
|
25
|
+
testUtils.attachTransformValidator(filter);
|
|
26
|
+
|
|
27
|
+
filter.testDigital('__^^__^^^^____^_^^^^^_', 1);
|
|
28
|
+
filter.valdDigital('__^^__^^^^____^_^^^^^_', 1);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('logic-or regular 2', function () {
|
|
32
|
+
const engine = new EngineV2(config);
|
|
33
|
+
const source = new ValueSource();
|
|
34
|
+
engine.addValueSource(source);
|
|
35
|
+
|
|
36
|
+
source.sendValue('counter', 0, 0);
|
|
37
|
+
|
|
38
|
+
const filter = new LogicOr({
|
|
39
|
+
engine,
|
|
40
|
+
path: 'variables.var1.1.or',
|
|
41
|
+
args: { compiledExpression: math.compile('counter % 2 == 0') },
|
|
42
|
+
});
|
|
43
|
+
testUtils.attachTransformValidator(filter);
|
|
44
|
+
|
|
45
|
+
filter.testDigital('__^^__^^^^____^_^^^^^_', 1, {
|
|
46
|
+
itemPreProcess: (value, time) => { engine.getState('counter').value = time; },
|
|
47
|
+
});
|
|
48
|
+
filter.valdDigital('^_^^^_^^^^^_^_^_^^^^^_', 1);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('logic-or irregular', function () {
|
|
52
|
+
const engine = new EngineV2(config);
|
|
53
|
+
const source = new ValueSource();
|
|
54
|
+
engine.addValueSource(source);
|
|
55
|
+
|
|
56
|
+
source.sendValue('counter', 0, 0);
|
|
57
|
+
|
|
58
|
+
const filter = new LogicOr({
|
|
59
|
+
engine,
|
|
60
|
+
path: 'variables.var1.1.or',
|
|
61
|
+
args: { compiledExpression: math.compile('counter > 10') },
|
|
62
|
+
});
|
|
63
|
+
testUtils.attachTransformValidator(filter);
|
|
64
|
+
|
|
65
|
+
filter.test([
|
|
66
|
+
[true, 1], [false, 2], [true, 5], [false, 8], [true, 10], [false, 11], [true, 12], [false, 15], [true, 18],
|
|
67
|
+
], {
|
|
68
|
+
itemPreProcess: (value, time) => { engine.getState('counter').value = time; },
|
|
69
|
+
});
|
|
70
|
+
filter.validate([
|
|
71
|
+
[true, 1], [false, 2], [true, 5], [false, 8], [true, 10], [true, 11], [true, 12], [true, 15], [true, 18],
|
|
72
|
+
]);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
class ValueSource extends EventEmitter {
|
|
77
|
+
sendValue(name, value, time) {
|
|
78
|
+
this.emit('update', name, value, time);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const EngineV2 = require('../../lib/engine/engineV2');
|
|
4
|
+
const Builder = require('../../lib/engine/transformBuilderV2');
|
|
5
|
+
const testUtils = require('../util/testUtils');
|
|
6
|
+
|
|
7
|
+
describe('map full engine config file tests', function () {
|
|
8
|
+
let config;
|
|
9
|
+
before(async () => {
|
|
10
|
+
config = await testUtils.loadConfig('transform/map.yml');
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('no reset expression', function () {
|
|
14
|
+
const engine = new EngineV2(config);
|
|
15
|
+
const builder = new Builder(config);
|
|
16
|
+
builder.build(engine);
|
|
17
|
+
|
|
18
|
+
const source = testUtils.valueSource();
|
|
19
|
+
testUtils.attachEngineTransformValidator(engine, engine.variablePool.var1, source);
|
|
20
|
+
|
|
21
|
+
source.sendValues('counter', [[[1, 2, 3], 0], [[2, 3, 4], 2], [[3, 3, 4], 4], [[4, 3, 5], 6]]);
|
|
22
|
+
|
|
23
|
+
engine.validateFilter([
|
|
24
|
+
[[0, 0, 0], 0], [[1, 1, 1], 2], [[2, 1, 1], 4], [[3, 1, 2], 6],
|
|
25
|
+
]);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('subkey map', function () {
|
|
29
|
+
const engine = new EngineV2(config);
|
|
30
|
+
const builder = new Builder(config);
|
|
31
|
+
builder.build(engine);
|
|
32
|
+
|
|
33
|
+
const source = testUtils.valueSource();
|
|
34
|
+
testUtils.attachEngineTransformValidator(engine, engine.variablePool.var2, source);
|
|
35
|
+
|
|
36
|
+
source.sendValue('complex', [{ subkey: 10, xx: 15 }, { subkey: 20, xx: 30 }], 0);
|
|
37
|
+
|
|
38
|
+
engine.validateFilter([
|
|
39
|
+
[[10, 20], 0],
|
|
40
|
+
]);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Max = require('../../lib/transform').max;
|
|
4
|
+
const testUtils = require('../util/testUtils');
|
|
5
|
+
|
|
6
|
+
describe('max transform tests', function () {
|
|
7
|
+
it('max regular 1', function () {
|
|
8
|
+
const filter = new Max(1);
|
|
9
|
+
testUtils.attachTransformValidator(filter);
|
|
10
|
+
|
|
11
|
+
filter.testAnalog([1, 3, 5, 7, 9, 2, 4, 6, 8, 0], 1);
|
|
12
|
+
filter.valdAnalog([1, 3, 5, 7, 9, 2, 4, 6, 8, 0], 1);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('max regular 2', function () {
|
|
16
|
+
const filter = new Max(2);
|
|
17
|
+
testUtils.attachTransformValidator(filter);
|
|
18
|
+
|
|
19
|
+
filter.testAnalog([1, 3, 5, 7, 9, 2, 4, 6, 8, 0], 1);
|
|
20
|
+
filter.valdAnalog([1, 3, 5, 7, 9, 9, 4, 6, 8, 8], 1);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('max regular 5', function () {
|
|
24
|
+
const filter = new Max(5);
|
|
25
|
+
testUtils.attachTransformValidator(filter);
|
|
26
|
+
|
|
27
|
+
filter.testAnalog([1, 3, 5, 7, 9, 2, 4, 6, 8, 0], 1);
|
|
28
|
+
filter.valdAnalog([1, 3, 5, 7, 9, 9, 9, 9, 9, 8], 1);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const MaxLength = require('../../lib/transform').maxLength;
|
|
4
|
+
const testUtils = require('../util/testUtils');
|
|
5
|
+
|
|
6
|
+
describe('max-length transform tests', async function () {
|
|
7
|
+
let config;
|
|
8
|
+
before(async () => {
|
|
9
|
+
config = await testUtils.loadConfig('transform/maxLength.yml');
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
const setupFilter = (transform) => {
|
|
13
|
+
return new MaxLength(transform.args.count);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
it('max length strings', async function () {
|
|
17
|
+
const filter = setupFilter(config.engine.variables.test1.transform[1]);
|
|
18
|
+
|
|
19
|
+
await testUtils.testValue(filter, 'xatu', 'xatu');
|
|
20
|
+
await testUtils.testValue(filter, 'scyther', 'scyther');
|
|
21
|
+
await testUtils.testValue(filter, 'bulbasaur', 'bulbasa');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('max length arrays', async function () {
|
|
25
|
+
const filter = setupFilter(config.engine.variables.test2.transform[1]);
|
|
26
|
+
|
|
27
|
+
await testUtils.testValue(filter, [], []);
|
|
28
|
+
await testUtils.testValue(filter, [0, 1], [0, 1]);
|
|
29
|
+
await testUtils.testValue(filter, [0, 1, 2], [0, 1, 2]);
|
|
30
|
+
await testUtils.testValue(filter, [0, 1, 2, 4, 5, 6], [0, 1, 2]);
|
|
31
|
+
});
|
|
32
|
+
});
|