Skip to content

Commit 505bd00

Browse files
committed
Fixed issue in JS error comparison and updated JLE version
1 parent 146e975 commit 505bd00

File tree

9 files changed

+147
-281
lines changed

9 files changed

+147
-281
lines changed

docs/index.html

Lines changed: 37 additions & 37 deletions
Large diffs are not rendered by default.

js-tests/engines/TestRunner.js

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,20 @@ export class TestRunner {
2323
if (!testCase.expectedError) {
2424
return false;
2525
}
26-
return this.compareErrors(error.message, testCase.expectedError);
26+
if (Number.isNaN(error))
27+
error = { type: 'NaN' }
28+
else if (error.message)
29+
error = { type: error.message }
30+
31+
if (JSON.stringify(error) === JSON.stringify(testCase.expectedError) ) {
32+
return true;
33+
}
34+
35+
const success = this.compareErrors(error.type, testCase.expectedError);
36+
if (!success) {
37+
console.log('Result:', error);
38+
}
39+
return success;
2740
}
2841
}
2942

@@ -63,19 +76,43 @@ export class TestRunner {
6376
return got.every((value, index) => this.compareValues(value, expected[index]));
6477
}
6578

79+
// Handle object comparisons
80+
if (typeof got === 'object' && typeof expected === 'object') {
81+
if (got === null || expected === null) {
82+
return got === expected;
83+
}
84+
const gotKeys = Object.keys(got);
85+
const expectedKeys = Object.keys(expected);
86+
if (gotKeys.length !== expectedKeys.length) {
87+
return false;
88+
}
89+
return gotKeys.every(key =>
90+
expectedKeys.includes(key) &&
91+
this.compareValues(got[key], expected[key])
92+
);
93+
}
94+
6695
// Default strict comparison
6796
return got === expected;
6897
}
6998

7099
compareErrors(got, expected) {
71-
if (typeof expected !== 'object') {
100+
console.log('compareErrors: got:', got);
101+
console.log('expected:', expected.type);
102+
103+
if (!got || typeof expected !== 'object') {
72104
return false;
73105
}
106+
107+
if (expected.type === got || expected === got) {
108+
return true;
109+
}
74110

75-
const expectedType = expected.type?.toLowerCase() ?? '';
76-
const expectedMessage = expected.message?.toLowerCase() ?? '';
111+
const gotLower = got.toLowerCase();
112+
const expectedType = expected?.type?.toLowerCase() ?? '';
113+
const expectedMessage = expected?.message?.toLowerCase() ?? '';
77114

78-
return (!expectedType || got.toLowerCase().includes(expectedType)) &&
79-
(!expectedMessage || got.toLowerCase().includes(expectedMessage));
115+
return (!expectedType || gotLower.includes(expectedType)) &&
116+
(!expectedMessage || gotLower.includes(expectedMessage));
80117
}
81118
}

js-tests/main.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ async function runEngineSuite(engine, suite) {
3434
if (await runner.runTest(case_)) {
3535
passed++;
3636
} else {
37-
console.log('Failed test case:', case_);
38-
37+
console.log('Failed test case:', testCase);
3938
}
4039
}
4140

@@ -53,7 +52,7 @@ async function main() {
5352
console.log(`Successfully loaded ${Object.keys(suites).length} test suites`);
5453

5554
const summary = new TestSummary();
56-
const engines = ['json-logic-js', 'json-logic-engine'];
55+
const engines = ['json-logic-engine'];
5756

5857
for (const [name, suite] of Object.entries(suites)) {
5958
console.log(`\nRunning suite: ${name}`);

js-tests/package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js-tests/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"test": "node main.js"
99
},
1010
"dependencies": {
11-
"json-logic-engine": "^4.0.1",
11+
"json-logic-engine": "^5.0.0-6",
1212
"json-logic-js": "^2.0.5"
1313
}
14-
}
14+
}

results/csharp.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,5 +239,5 @@
239239
"success_rate": 63.0457933972311
240240
}
241241
},
242-
"timestamp": "2025-02-15T14:24:59.394922Z"
242+
"timestamp": "2025-02-16T04:20:45.879302Z"
243243
}

results/go.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,6 @@
341341
"total": 939
342342
}
343343
},
344-
"timestamp": "2025-02-15T14:24:54Z",
344+
"timestamp": "2025-02-16T04:20:40Z",
345345
"go_version": "go1.23.0"
346346
}

results/java.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,5 +239,5 @@
239239
"success_rate" : 58.040468583599576
240240
}
241241
},
242-
"timestamp" : "2025-02-15T14:24:58.505962Z"
242+
"timestamp" : "2025-02-16T04:20:44.939676Z"
243243
}

0 commit comments

Comments
 (0)