@fincity/kirun-js 2.3.2 → 2.5.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/__tests__/engine/function/system/date/AddTimeTest.ts +115 -0
- package/__tests__/engine/function/system/date/GetMonthTest.ts +3 -3
- package/__tests__/engine/function/system/date/SubtractTimeTest.ts +95 -0
- package/__tests__/engine/function/system/math/MathFunctionRepositoryTest.ts +7 -16
- package/__tests__/engine/repository/RepositoryFilterTest.ts +5 -4
- package/__tests__/engine/runtime/expression/ExpressionEvaluationTest.ts +80 -0
- package/__tests__/engine/runtime/expression/ExpressionEvaluatorStringLiteralTest.ts +73 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/module.js +1 -1
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/generator/generateValidationCSV.ts +87 -0
- package/generator/validation-js.csv +1146 -0
- package/package.json +4 -4
- package/src/engine/function/system/date/AbstractDateFunction.ts +60 -2
- package/src/engine/function/system/date/DateFunctionRepository.ts +105 -2
- package/src/engine/function/system/math/MathFunctionRepository.ts +9 -9
- package/src/engine/runtime/expression/tokenextractor/TokenValueExtractor.ts +63 -59
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { FunctionExecutionParameters, KIRunFunctionRepository, KIRunSchemaRepository, Namespaces } from "../../../../../src";
|
|
2
|
+
import { AbstractDateFunction } from "../../../../../src/engine/function/system/date/AbstractDateFunction";
|
|
3
|
+
import { DateFunctionRepository } from "../../../../../src/engine/function/system/date/DateFunctionRepository";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
const dfr : DateFunctionRepository = new DateFunctionRepository();
|
|
7
|
+
|
|
8
|
+
const fep : FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
9
|
+
new KIRunFunctionRepository(),
|
|
10
|
+
new KIRunSchemaRepository());
|
|
11
|
+
|
|
12
|
+
test('check for invalid dates', async () => {
|
|
13
|
+
|
|
14
|
+
const addTimeFunction = await dfr.find(Namespaces.DATE, 'AddTime');
|
|
15
|
+
|
|
16
|
+
if (!addTimeFunction) {
|
|
17
|
+
throw new Error("Function not found");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
fep.setArguments(new Map<string, any>([
|
|
21
|
+
[AbstractDateFunction.PARAMETER_DATE_NAME, '2029-15-05T06:04:18.073Z'],
|
|
22
|
+
[AbstractDateFunction.PARAMETER_INT_NAME, 10],
|
|
23
|
+
[AbstractDateFunction.PARAMETER_UNIT_NAME, 'SECOND']
|
|
24
|
+
]));
|
|
25
|
+
|
|
26
|
+
await expect( () => addTimeFunction.execute(fep)).rejects.toThrow();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('Add Time 1', async () => {
|
|
30
|
+
|
|
31
|
+
const addTimeFunction = await dfr.find(Namespaces.DATE, 'AddTime');
|
|
32
|
+
|
|
33
|
+
if (!addTimeFunction) {
|
|
34
|
+
throw new Error("Function not found");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
fep.setArguments(new Map<string, any>([
|
|
38
|
+
[AbstractDateFunction.PARAMETER_DATE_NAME, '2024-09-13T23:52:34.633-05:30'],
|
|
39
|
+
[AbstractDateFunction.PARAMETER_INT_NAME, 10],
|
|
40
|
+
[AbstractDateFunction.PARAMETER_UNIT_NAME, 'MINUTE']
|
|
41
|
+
]));
|
|
42
|
+
|
|
43
|
+
expect((await addTimeFunction.execute(fep)).allResults()[0].getResult().get('result')).toBe('2024-09-14T00:02:34.633-05:30');
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
test('Add Time 2', async () => {
|
|
47
|
+
|
|
48
|
+
const addTimeFunction = await dfr.find(Namespaces.DATE, 'AddTime');
|
|
49
|
+
|
|
50
|
+
if (!addTimeFunction) {
|
|
51
|
+
throw new Error("Function not found");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
fep.setArguments(new Map<string, any>([
|
|
55
|
+
[AbstractDateFunction.PARAMETER_DATE_NAME, '2024-09-13T23:52:34.633-05:30'],
|
|
56
|
+
[AbstractDateFunction.PARAMETER_INT_NAME, 13],
|
|
57
|
+
[AbstractDateFunction.PARAMETER_UNIT_NAME, 'MONTH']
|
|
58
|
+
]));
|
|
59
|
+
|
|
60
|
+
expect((await addTimeFunction.execute(fep)).allResults()[0].getResult().get('result')).toBe('2025-10-13T23:52:34.633-05:30');
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
test('Add Time 2', async () => {
|
|
65
|
+
|
|
66
|
+
const addTimeFunction = await dfr.find(Namespaces.DATE, 'AddTime');
|
|
67
|
+
|
|
68
|
+
if (!addTimeFunction) {
|
|
69
|
+
throw new Error("Function not found");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
fep.setArguments(new Map<string, any>([
|
|
73
|
+
[AbstractDateFunction.PARAMETER_DATE_NAME, '2024-09-13T23:52:34.633-05:30'],
|
|
74
|
+
[AbstractDateFunction.PARAMETER_INT_NAME, 3],
|
|
75
|
+
[AbstractDateFunction.PARAMETER_UNIT_NAME, 'MONTH']
|
|
76
|
+
]));
|
|
77
|
+
|
|
78
|
+
expect((await addTimeFunction.execute(fep)).allResults()[0].getResult().get('result')).toBe('2024-12-13T23:52:34.633-05:30');
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
test('Add Time 3', async () => {
|
|
82
|
+
|
|
83
|
+
const addTimeFunction = await dfr.find(Namespaces.DATE, 'AddTime');
|
|
84
|
+
|
|
85
|
+
if (!addTimeFunction) {
|
|
86
|
+
throw new Error("Function not found");
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
fep.setArguments(new Map<string, any>([
|
|
90
|
+
[AbstractDateFunction.PARAMETER_DATE_NAME, '2024-09-13T23:52:34.633-05:30'],
|
|
91
|
+
[AbstractDateFunction.PARAMETER_INT_NAME, 10],
|
|
92
|
+
[AbstractDateFunction.PARAMETER_UNIT_NAME, 'SECOND']
|
|
93
|
+
]));
|
|
94
|
+
|
|
95
|
+
expect((await addTimeFunction.execute(fep)).allResults()[0].getResult().get('result')).toBe('2024-09-13T23:52:44.633-05:30');
|
|
96
|
+
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
test('Add Time 4', async () => {
|
|
101
|
+
|
|
102
|
+
const addTimeFunction = await dfr.find(Namespaces.DATE, 'AddTime');
|
|
103
|
+
|
|
104
|
+
if (!addTimeFunction) {
|
|
105
|
+
throw new Error("Function not found");
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
fep.setArguments(new Map<string, any>([
|
|
109
|
+
[AbstractDateFunction.PARAMETER_DATE_NAME, '2024-09-13T23:52:34.633-05:30'],
|
|
110
|
+
[AbstractDateFunction.PARAMETER_INT_NAME, 5],
|
|
111
|
+
[AbstractDateFunction.PARAMETER_UNIT_NAME, 'YEAR']
|
|
112
|
+
]));
|
|
113
|
+
|
|
114
|
+
expect((await addTimeFunction.execute(fep)).allResults()[0].getResult().get('result')).toBe('2029-09-13T23:52:34.633-05:30');
|
|
115
|
+
})
|
|
@@ -49,7 +49,7 @@ test('fetching for valid date' , async () => {
|
|
|
49
49
|
fep.setArguments(new Map([[AbstractDateFunction.PARAMETER_DATE_NAME, '2024-09-01T23:52:34.633-05:30' ]]));
|
|
50
50
|
|
|
51
51
|
|
|
52
|
-
expect( (await getMonthFunction.execute(fep)).allResults()[0].getResult().get(AbstractDateFunction.EVENT_RESULT_NAME)).toBe(
|
|
52
|
+
expect( (await getMonthFunction.execute(fep)).allResults()[0].getResult().get(AbstractDateFunction.EVENT_RESULT_NAME)).toBe(8);
|
|
53
53
|
|
|
54
54
|
})
|
|
55
55
|
|
|
@@ -64,7 +64,7 @@ test('fetching for valid date' , async () => {
|
|
|
64
64
|
fep.setArguments(new Map([[AbstractDateFunction.PARAMETER_DATE_NAME, '2019-11-13T23:52:34.633Z' ]]));
|
|
65
65
|
|
|
66
66
|
|
|
67
|
-
expect( (await getMonthFunction.execute(fep)).allResults()[0].getResult().get(AbstractDateFunction.EVENT_RESULT_NAME)).toBe(
|
|
67
|
+
expect( (await getMonthFunction.execute(fep)).allResults()[0].getResult().get(AbstractDateFunction.EVENT_RESULT_NAME)).toBe(10);
|
|
68
68
|
|
|
69
69
|
})
|
|
70
70
|
|
|
@@ -80,6 +80,6 @@ test('fetching for valid date' , async () => {
|
|
|
80
80
|
fep.setArguments(new Map([[AbstractDateFunction.PARAMETER_DATE_NAME, '2023-12-31T07:35:17.000-12:00' ]]));
|
|
81
81
|
|
|
82
82
|
|
|
83
|
-
expect( (await getMonthFunction.execute(fep)).allResults()[0].getResult().get(AbstractDateFunction.EVENT_RESULT_NAME)).toBe(
|
|
83
|
+
expect( (await getMonthFunction.execute(fep)).allResults()[0].getResult().get(AbstractDateFunction.EVENT_RESULT_NAME)).toBe(11);
|
|
84
84
|
|
|
85
85
|
})
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { FunctionExecutionParameters, KIRunFunctionRepository, KIRunSchemaRepository, Namespaces } from "../../../../../src";
|
|
2
|
+
import { AbstractDateFunction } from "../../../../../src/engine/function/system/date/AbstractDateFunction";
|
|
3
|
+
import { DateFunctionRepository } from "../../../../../src/engine/function/system/date/DateFunctionRepository";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
const dfr : DateFunctionRepository = new DateFunctionRepository();
|
|
7
|
+
|
|
8
|
+
const fep : FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
9
|
+
new KIRunFunctionRepository(),
|
|
10
|
+
new KIRunSchemaRepository());
|
|
11
|
+
|
|
12
|
+
test('check for invalid dates', async () => {
|
|
13
|
+
|
|
14
|
+
const subtractTimeFunction = await dfr.find(Namespaces.DATE, 'SubtractTime');
|
|
15
|
+
|
|
16
|
+
if (!subtractTimeFunction) {
|
|
17
|
+
throw new Error("Function not found");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
fep.setArguments(new Map<string, any>([
|
|
21
|
+
[AbstractDateFunction.PARAMETER_DATE_NAME, '2029-15-05T06:04:18.073Z'],
|
|
22
|
+
[AbstractDateFunction.PARAMETER_INT_NAME, 10],
|
|
23
|
+
[AbstractDateFunction.PARAMETER_UNIT_NAME, 'SECOND']
|
|
24
|
+
]));
|
|
25
|
+
|
|
26
|
+
await expect( () => subtractTimeFunction.execute(fep)).rejects.toThrow();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('Subtract Time 1', async () => {
|
|
30
|
+
|
|
31
|
+
const subtractTimeFunction = await dfr.find(Namespaces.DATE, 'SubtractTime');
|
|
32
|
+
|
|
33
|
+
if (!subtractTimeFunction) {
|
|
34
|
+
throw new Error("Function not found");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
fep.setArguments(new Map<string, any>([
|
|
38
|
+
[AbstractDateFunction.PARAMETER_DATE_NAME, '2024-09-13T23:52:34.633-05:30'],
|
|
39
|
+
[AbstractDateFunction.PARAMETER_INT_NAME, 10],
|
|
40
|
+
[AbstractDateFunction.PARAMETER_UNIT_NAME, 'MINUTE']
|
|
41
|
+
]));
|
|
42
|
+
|
|
43
|
+
expect((await subtractTimeFunction.execute(fep)).allResults()[0].getResult().get('result')).toBe('2024-09-13T23:42:34.633-05:30');
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('Subtract Time 2', async () => {
|
|
47
|
+
|
|
48
|
+
const subtractTimeFunction = await dfr.find(Namespaces.DATE, 'SubtractTime');
|
|
49
|
+
|
|
50
|
+
if (!subtractTimeFunction) {
|
|
51
|
+
throw new Error("Function not found");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
fep.setArguments(new Map<string, any>([
|
|
55
|
+
[AbstractDateFunction.PARAMETER_DATE_NAME, '2024-09-13T23:52:34.633-05:30'],
|
|
56
|
+
[AbstractDateFunction.PARAMETER_INT_NAME, 13],
|
|
57
|
+
[AbstractDateFunction.PARAMETER_UNIT_NAME, 'MONTH']
|
|
58
|
+
]));
|
|
59
|
+
|
|
60
|
+
expect((await subtractTimeFunction.execute(fep)).allResults()[0].getResult().get('result')).toBe('2023-08-13T23:52:34.633-05:30');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('Subtract Time 3', async () => {
|
|
64
|
+
|
|
65
|
+
const subtractTimeFunction = await dfr.find(Namespaces.DATE, 'SubtractTime');
|
|
66
|
+
|
|
67
|
+
if (!subtractTimeFunction) {
|
|
68
|
+
throw new Error("Function not found");
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
fep.setArguments(new Map<string, any>([
|
|
72
|
+
[AbstractDateFunction.PARAMETER_DATE_NAME, '2024-09-13T23:52:34.633-05:30'],
|
|
73
|
+
[AbstractDateFunction.PARAMETER_INT_NAME, 70],
|
|
74
|
+
[AbstractDateFunction.PARAMETER_UNIT_NAME, 'SECOND']
|
|
75
|
+
]));
|
|
76
|
+
|
|
77
|
+
expect((await subtractTimeFunction.execute(fep)).allResults()[0].getResult().get('result')).toBe('2024-09-13T23:51:24.633-05:30');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test('Subtract Time 4', async () => {
|
|
81
|
+
|
|
82
|
+
const subtractTimeFunction = await dfr.find(Namespaces.DATE, 'SubtractTime');
|
|
83
|
+
|
|
84
|
+
if (!subtractTimeFunction) {
|
|
85
|
+
throw new Error("Function not found");
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
fep.setArguments(new Map<string, any>([
|
|
89
|
+
[AbstractDateFunction.PARAMETER_DATE_NAME, '2024-09-13T23:52:34.633-05:30'],
|
|
90
|
+
[AbstractDateFunction.PARAMETER_INT_NAME, 5],
|
|
91
|
+
[AbstractDateFunction.PARAMETER_UNIT_NAME, 'YEAR']
|
|
92
|
+
]));
|
|
93
|
+
|
|
94
|
+
expect((await subtractTimeFunction.execute(fep)).allResults()[0].getResult().get('result')).toBe('2019-09-13T23:52:34.633-05:30');
|
|
95
|
+
});
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { KIRunFunctionRepository, KIRunSchemaRepository } from '../../../../../src';
|
|
2
|
-
import { GenericMathFunction } from '../../../../../src/engine/function/system/math/GenericMathFunction';
|
|
3
2
|
import { MathFunctionRepository } from '../../../../../src/engine/function/system/math/MathFunctionRepository';
|
|
4
3
|
import { Namespaces } from '../../../../../src/engine/namespaces/Namespaces';
|
|
5
4
|
import { FunctionExecutionParameters } from '../../../../../src/engine/runtime/FunctionExecutionParameters';
|
|
@@ -42,32 +41,24 @@ test('Test Math Functions 3', async () => {
|
|
|
42
41
|
new KIRunSchemaRepository(),
|
|
43
42
|
).setArguments(new Map([['value', 90]]));
|
|
44
43
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
?.getResult()
|
|
49
|
-
?.get('value'),
|
|
50
|
-
).toBe(NaN);
|
|
44
|
+
const func = await MathFunction.find(Namespaces.MATH, 'ACosine');
|
|
45
|
+
if (!func)
|
|
46
|
+
expect(func).toBe(undefined);
|
|
51
47
|
});
|
|
52
48
|
|
|
53
49
|
test('Test Math Functions 4', async () => {
|
|
54
50
|
expect(await MathFunction.find(Namespaces.STRING, 'ASine')).toBe(undefined);
|
|
55
51
|
});
|
|
56
52
|
|
|
57
|
-
test('test Math Functions 5', () => {
|
|
53
|
+
test('test Math Functions 5', async () => {
|
|
58
54
|
let fep: FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
59
55
|
new KIRunFunctionRepository(),
|
|
60
56
|
new KIRunSchemaRepository(),
|
|
61
57
|
).setArguments(new Map([['value', '-1']]));
|
|
62
58
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
?.getResult()
|
|
67
|
-
?.get('value'),
|
|
68
|
-
).rejects.toThrowError(
|
|
69
|
-
'Value "-1" is not of valid type(s)\n-1 is not a Integer\n-1 is not a Long\n-1 is not a Float\n-1 is not a Double',
|
|
70
|
-
);
|
|
59
|
+
const func = await MathFunction.find(Namespaces.MATH, 'ATangent');
|
|
60
|
+
if (!func)
|
|
61
|
+
expect(func).toBe(undefined);
|
|
71
62
|
});
|
|
72
63
|
|
|
73
64
|
test('test Math Functions 6', async () => {
|
|
@@ -23,7 +23,11 @@ test('Repository Filter Test', async () => {
|
|
|
23
23
|
|
|
24
24
|
expect(await schemaRepo.filter('ny')).toStrictEqual(['System.any']);
|
|
25
25
|
|
|
26
|
-
expect(await schemaRepo.filter('')).toStrictEqual([
|
|
26
|
+
expect((await schemaRepo.filter('')).sort()).toStrictEqual([
|
|
27
|
+
'System.Date.timeStamp',
|
|
28
|
+
'System.Null',
|
|
29
|
+
'System.ParameterExpression',
|
|
30
|
+
'System.Schema',
|
|
27
31
|
'System.any',
|
|
28
32
|
'System.boolean',
|
|
29
33
|
'System.double',
|
|
@@ -32,8 +36,5 @@ test('Repository Filter Test', async () => {
|
|
|
32
36
|
'System.long',
|
|
33
37
|
'System.number',
|
|
34
38
|
'System.string',
|
|
35
|
-
'System.ParameterExpression',
|
|
36
|
-
'System.Null',
|
|
37
|
-
'System.Schema',
|
|
38
39
|
]);
|
|
39
40
|
});
|
|
@@ -139,6 +139,86 @@ test('Expression Test', () => {
|
|
|
139
139
|
);
|
|
140
140
|
});
|
|
141
141
|
|
|
142
|
+
test('Expression Evaluation with Square Access Bracket', () => {
|
|
143
|
+
let phone = { phone1: '1234', phone2: '5678', phone3: '5678' };
|
|
144
|
+
|
|
145
|
+
let address = {
|
|
146
|
+
line1: 'Flat 202, PVR Estates',
|
|
147
|
+
line2: 'Nagvara',
|
|
148
|
+
city: 'Benguluru',
|
|
149
|
+
pin: '560048',
|
|
150
|
+
phone: phone,
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
let arr = [10, 20, 30];
|
|
154
|
+
|
|
155
|
+
let obj = {
|
|
156
|
+
studentName: 'Kumar',
|
|
157
|
+
math: 20,
|
|
158
|
+
isStudent: true,
|
|
159
|
+
address: address,
|
|
160
|
+
array: arr,
|
|
161
|
+
num: 1,
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
let inMap: Map<string, any> = new Map();
|
|
165
|
+
inMap.set('name', 'Kiran');
|
|
166
|
+
inMap.set('obj', obj);
|
|
167
|
+
|
|
168
|
+
let output: Map<string, Map<string, Map<string, any>>> = new Map([
|
|
169
|
+
['step1', new Map([['output', inMap]])],
|
|
170
|
+
]);
|
|
171
|
+
|
|
172
|
+
let parameters: FunctionExecutionParameters = new FunctionExecutionParameters(
|
|
173
|
+
new KIRunFunctionRepository(),
|
|
174
|
+
new KIRunSchemaRepository(),
|
|
175
|
+
)
|
|
176
|
+
.setArguments(new Map())
|
|
177
|
+
.setContext(new Map())
|
|
178
|
+
.setSteps(output);
|
|
179
|
+
|
|
180
|
+
// New test cases for square access bracket using parameters value map
|
|
181
|
+
expect(
|
|
182
|
+
new ExpressionEvaluator('Steps.step1.output.obj.phone.phone2 = Steps.step1.output.obj["phone"]["phone2"]')
|
|
183
|
+
.evaluate(parameters.getValuesMap())
|
|
184
|
+
).toBe(true);
|
|
185
|
+
|
|
186
|
+
expect(
|
|
187
|
+
new ExpressionEvaluator('Steps.step1.output.obj["phone"]["phone2"] = Steps.step1.output.obj["phone"]["phone2"]')
|
|
188
|
+
.evaluate(parameters.getValuesMap())
|
|
189
|
+
).toBe(true);
|
|
190
|
+
|
|
191
|
+
expect(
|
|
192
|
+
new ExpressionEvaluator('Steps.step1.output.obj["address"].phone["phone2"] != Steps.step1.output.address.obj.phone.phone1')
|
|
193
|
+
.evaluate(parameters.getValuesMap())
|
|
194
|
+
).toBe(true);
|
|
195
|
+
|
|
196
|
+
expect(
|
|
197
|
+
new ExpressionEvaluator('Steps.step1.output.obj["address"]["phone"]["phone2"] != Steps.step1.output.address.obj.phone.phone1')
|
|
198
|
+
.evaluate(parameters.getValuesMap())
|
|
199
|
+
).toBe(true);
|
|
200
|
+
|
|
201
|
+
expect(
|
|
202
|
+
new ExpressionEvaluator('Steps.step1.output.obj["address"]["phone"]["phone2"] != Steps.step1.output["address"]["phone"]["phone2"]')
|
|
203
|
+
.evaluate(parameters.getValuesMap())
|
|
204
|
+
).toBe(true);
|
|
205
|
+
|
|
206
|
+
expect(
|
|
207
|
+
new ExpressionEvaluator('Steps.step1.output.obj.array[Steps.step1.output.obj["num"] + 1] + 2')
|
|
208
|
+
.evaluate(parameters.getValuesMap())
|
|
209
|
+
).toBe(32);
|
|
210
|
+
|
|
211
|
+
expect(
|
|
212
|
+
new ExpressionEvaluator('Steps.step1.output.obj.array[Steps.step1.output.obj["num"] + 1] + Steps.step1.output.obj.array[Steps.step1.output.obj["num"] + 1]')
|
|
213
|
+
.evaluate(parameters.getValuesMap())
|
|
214
|
+
).toBe(60);
|
|
215
|
+
|
|
216
|
+
expect(
|
|
217
|
+
new ExpressionEvaluator('Steps.step1.output.obj.array[Steps.step1.output.obj.num + 1] + Steps.step1.output.obj.array[Steps.step1.output.obj.num + 1]')
|
|
218
|
+
.evaluate(parameters.getValuesMap())
|
|
219
|
+
).toBe(60);
|
|
220
|
+
});
|
|
221
|
+
|
|
142
222
|
test('ExpressionEvaluation deep tests', () => {
|
|
143
223
|
let atv: ArgumentsTokenValueExtractor = new ArgumentsTokenValueExtractor(
|
|
144
224
|
new Map<string, any>([
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
MapUtil,
|
|
5
5
|
TokenValueExtractor,
|
|
6
6
|
} from '../../../../src';
|
|
7
|
-
import { ExpressionEvaluator } from '../../../../src
|
|
7
|
+
import { ExpressionEvaluator } from '../../../../src';
|
|
8
8
|
|
|
9
9
|
test('Expression with String Literal - 1 ', () => {
|
|
10
10
|
let ex: Expression = new Expression("'ki/run'+'ab'");
|
|
@@ -98,3 +98,75 @@ test('Expression with String Literal - 2 ', () => {
|
|
|
98
98
|
ev = new ExpressionEvaluator('2.val');
|
|
99
99
|
expect(ev.evaluate(valuesMap)).toBe('2.val');
|
|
100
100
|
});
|
|
101
|
+
|
|
102
|
+
test('Testing for string length with object', () => {
|
|
103
|
+
const jsonObj = {
|
|
104
|
+
greeting: 'hello',
|
|
105
|
+
name: 'surendhar'
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
let atv: ArgumentsTokenValueExtractor = new ArgumentsTokenValueExtractor(
|
|
109
|
+
new Map<string, any>([
|
|
110
|
+
['a', 'surendhar '],
|
|
111
|
+
['b', 2],
|
|
112
|
+
['c', true],
|
|
113
|
+
['d', 1.5],
|
|
114
|
+
['obj', jsonObj],
|
|
115
|
+
]),
|
|
116
|
+
);
|
|
117
|
+
const valuesMap: Map<string, TokenValueExtractor> = MapUtil.of(atv.getPrefix(), atv);
|
|
118
|
+
|
|
119
|
+
let ev: ExpressionEvaluator = new ExpressionEvaluator('Arguments.a.length');
|
|
120
|
+
expect(ev.evaluate(valuesMap)).toBe(10);
|
|
121
|
+
|
|
122
|
+
ev = new ExpressionEvaluator('Arguments.b.length');
|
|
123
|
+
expect(() => ev.evaluate(valuesMap)).toThrow();
|
|
124
|
+
|
|
125
|
+
ev = new ExpressionEvaluator('Arguments.obj.greeting.length * "S"');
|
|
126
|
+
expect(ev.evaluate(valuesMap)).toBe('SSSSS');
|
|
127
|
+
|
|
128
|
+
ev = new ExpressionEvaluator('Arguments.obj.greeting.length * "SP"');
|
|
129
|
+
expect(ev.evaluate(valuesMap)).toBe('SPSPSPSPSP');
|
|
130
|
+
|
|
131
|
+
ev = new ExpressionEvaluator('Arguments.obj.name.length ? "fun" : "not Fun"');
|
|
132
|
+
expect(ev.evaluate(valuesMap)).toBe('fun');
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test('Testing for string length with square brackets', () => {
|
|
136
|
+
const jsonObj = {
|
|
137
|
+
greeting: 'hello',
|
|
138
|
+
name: 'surendhar'
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
let atv: ArgumentsTokenValueExtractor = new ArgumentsTokenValueExtractor(
|
|
142
|
+
new Map<string, any>([
|
|
143
|
+
['a', 'surendhar '],
|
|
144
|
+
['b', 2],
|
|
145
|
+
['c', true],
|
|
146
|
+
['d', 1.5],
|
|
147
|
+
['obj', jsonObj],
|
|
148
|
+
]),
|
|
149
|
+
);
|
|
150
|
+
const valuesMap: Map<string, TokenValueExtractor> = MapUtil.of(atv.getPrefix(), atv);
|
|
151
|
+
|
|
152
|
+
let ev: ExpressionEvaluator = new ExpressionEvaluator('Arguments.a["length"]');
|
|
153
|
+
expect(ev.evaluate(valuesMap)).toBe(10);
|
|
154
|
+
|
|
155
|
+
ev = new ExpressionEvaluator('Arguments.b["length"]');
|
|
156
|
+
expect(() => ev.evaluate(valuesMap)).toThrow();
|
|
157
|
+
|
|
158
|
+
ev = new ExpressionEvaluator('Arguments.obj.greeting["length"] * "S"');
|
|
159
|
+
expect(ev.evaluate(valuesMap)).toBe('SSSSS');
|
|
160
|
+
|
|
161
|
+
ev = new ExpressionEvaluator('Arguments.obj.greeting["length"] * "SP"');
|
|
162
|
+
expect(ev.evaluate(valuesMap)).toBe('SPSPSPSPSP');
|
|
163
|
+
|
|
164
|
+
ev = new ExpressionEvaluator('Arguments.obj["greeting"]["length"] * "S"');
|
|
165
|
+
expect(ev.evaluate(valuesMap)).toBe('SSSSS');
|
|
166
|
+
|
|
167
|
+
ev = new ExpressionEvaluator('Arguments.obj["greeting"]["length"] * "SP"');
|
|
168
|
+
expect(ev.evaluate(valuesMap)).toBe('SPSPSPSPSP');
|
|
169
|
+
|
|
170
|
+
ev = new ExpressionEvaluator('Arguments.obj.name["length"] ? "fun" : "not Fun"');
|
|
171
|
+
expect(ev.evaluate(valuesMap)).toBe('fun');
|
|
172
|
+
});
|