-
Notifications
You must be signed in to change notification settings - Fork 2
/
Tester1.js
157 lines (157 loc) · 5.66 KB
/
Tester1.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const common_1 = require("./common");
const ExpressionEngine_1 = require("./ExpressionEngine");
function testCond(expr, value, res) {
const engine = new ExpressionEngine_1.ExpressionEngine();
const ret = engine.evaluateCondition(expr, value);
if (ret !== res) {
console.log("***Error -" + expr + " for " + value + "result: " + ret + "expecting:" + res);
common_1.logger.log("***Error -" + expr + " for " + value + "result: " + ret + "expecting:" + res);
}
return;
}
function testExp(expr, res) {
console.log('expecting: ' + res);
common_1.logger.log('expecting: ' + res);
const engine = new ExpressionEngine_1.ExpressionEngine();
const ret = engine.evaluate(expr);
if (ret !== res) {
common_1.Options.debugExecution = true;
common_1.Options.debugExpression = true;
// parser.evaluateCondition(expr, value);
console.log("***Error -" + expr + "result: " + ret + "expecting:" + res);
common_1.logger.log("***Error -" + expr + "result: " + ret + "expecting:" + res);
// throw Error("Error -" + expr + " failed for " + value);
}
return;
}
function runTest(list, category = '') {
console.log(list);
list.forEach(item => {
const cat = item.category;
console.log("Running " + cat.name);
if (cat.expressions) {
cat.expressions.forEach(expr => {
console.log(expr);
try {
testExp(expr[0], expr[1]);
}
catch (exc) {
console.log(exc);
common_1.logger.log(exc.message);
}
});
}
if (cat.conditions) {
cat.conditions.forEach(expr => {
console.log(expr);
try {
testCond(expr[0], expr[1], expr[2]);
}
catch (exc) {
console.log(exc);
common_1.logger.log(exc.message);
}
});
}
});
}
// Structure for Expression
var scripts = [{
category: {
name: 'tokens syntax',
expressions: [
[`2 + 3 'test' > and < == or function - * () []`, 20],
["caseId", 1001],
[`2 + 3`, 5],
[`(2 + 3) * 4`, 20],
[`4 * (2 + 3)`, 20],
[`4 * (2 + (3+0))`, 20],
[`2 + 3 * 4`, 14],
[`3 * 4 +2`, 14],
['"high"', 'high'],
[`2+3`, 5]
]
}
}
];
var conditions = [{
category: {
name: 'tokens syntax',
conditions: [
["> 200 or < 500", 20, true],
["-20", '55', false],
["20+35", '55', true],
["> 200 or < 500", 20, true],
[`'High'`, 'High', true],
[`High`, 'Low', false],
["> 200 or < 500", 20, true],
["(> 200) or (< 500)", 20, true],
["(in ('abc','xyz-abc')", 'abc', true],
["(in ('abc','xyz-abc') ) and startsWith('a')", 'abc', true],
["in ('abc','xyz-abc','another entry', 9)", "abc", true],
["(2+3)", '5', true],
["2+3", '5', true],
["2*4", '8', true],
["(2+3)*4", '20', true],
["(in (abc,'xyz-abc') ) and startsWith('a')", 'abc', true],
["in (abc,'xyz-abc') and startsWith('a')", 'abc', true],
["75.25", '75', false],
//["75.25", '75.25', true],
["2,075.25", '75', false],
["2,075.25", '2075.25', true],
["-20", '-20', true],
[">=75", '75', true],
["<=55", '55', true],
["==55", '55', true],
["2 + 3", '5', true],
["> 200 or < 500", 20, true],
["object.fun('test')", '75', true],
["5 + object.fun('test')", '75', true],
["in (abc,'xyz-abc','another entry')", "abc", true],
["not in (abc,'xyz-abc') ", 'abc', true],
["in (abc,'xyz-abc') and startsWith('a') ", 'abc', true],
["in (abc,'xyz-abc') and not startsWith('a') ", 'abc', false],
["in (abc,'xyz-abc') and startsWith('a') and 3 ", 'abc', false],
["75", 'not 75', false],
["'High'", 'High', true],
["in (abc,'xyz-abc','another entry')", "abc", true],
["between ( 95 , 2500.0 )", 200, true],
]
}
}
];
common_1.Options.debugTokens = true;
common_1.Options.debugExpression = true;
common_1.Options.debugExecution = true;
testCond(`$ not 10 and $<500`, 20, true);
//testExp(`20 <500 `, true);
//testExp(`2 + 3`, true);
//main();
//testExp(` in ('1','2','3')`, null);
//testExp(` (1> $v1) and funct (v1 , 2 , 3) startsWith "abc12$@!3z"`, null);
//testExp(` (1>2) and funct (v1 , 2 , 3) `, null);
//testExp(` between a and b `, null);
// make between an operator
// operators: type:
// L 0-1
// R 0-2
/*console.log(process.argv);
var args = process.argv;
if (args.length > 4) {
console.log('testing condition ' + args[2], args[3], args[4]);
// testCond(args[2], args[3], args[4]);
}
else if (args.length > 3) {
console.log('testing expression' + args[2], args[3]);
// testExp(args[2], args[3]);
}
*/
function main() {
common_1.logger.log("starting");
runTest(scripts);
runTest(conditions);
common_1.logger.save("./parser.log");
}
//# sourceMappingURL=Tester1.js.map