We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d6f02aa commit b4b3bc7Copy full SHA for b4b3bc7
compatible.test.js
@@ -4,19 +4,15 @@ import { LogicEngine, AsyncLogicEngine } from './index.js'
4
5
const tests = []
6
7
-// get all json files from "suites" directory, 1 layer of depth
8
-const files = fs.readdirSync('./suites', { withFileTypes: true }).flatMap(i => {
9
- if (i.isDirectory()) return fs.readdirSync(`./suites/${i.name}`).map(j => `${i.name}/${j}`)
10
- return i.name
11
-})
+// Load test files from index.json
+const indexContent = JSON.parse(fs.readFileSync('./suites/index.json').toString())
12
13
-for (const file of files) {
14
- if (file.endsWith('.json')) {
15
- tests.push(...JSON.parse(fs.readFileSync(`./suites/${file}`).toString()).filter(i => typeof i !== 'string').map(i => {
16
- if (Array.isArray(i)) return { rule: i[0], data: i[1] || null, result: i[2], description: JSON.stringify(i[0]) }
17
- return i
18
- }))
19
- }
+for (const file of indexContent) {
+ const testContent = JSON.parse(fs.readFileSync(`./suites/${file}`).toString())
+ tests.push(...testContent.filter(i => typeof i !== 'string').map(i => {
+ if (Array.isArray(i)) return { rule: i[0], data: i[1] || null, result: i[2], description: JSON.stringify(i[0]) }
+ return i
+ }))
20
}
21
22
function correction (x) {
suites/additional.json
@@ -1,24 +1,26 @@
1
[
2
"# These are some tests from https://github.com/TotalTechGeek/json-logic-engine/commit/9125e91b5137938a8319de1103b0ebc5819e54e1",
3
- [
+ {
+ "description": "Rule array with val",
+ "rule": [
1,
{
"val": "x"
},
],
- {
+ "data": {
"x": 2
+ "result": [
2,
]
- ],
+ },
+ "description": "If Operator fetching both condition and consequent from data",
23
+ "rule": {
24
"if": [
25
26
@@ -31,16 +33,17 @@
31
33
99
32
34
35
36
37
"x": true,
38
"y": 42
39
40
41
42
43
44
45
+ "description": "Reduce Operator with val",
46
47
"reduce": [
48
49
"val": "integers"
@@ -60,7 +63,7 @@
60
63
61
64
62
65
66
67
"integers": [
68
69
@@ -69,12 +72,21 @@
72
70
73
"start_with": 59
71
74
- 69
75
+ "result": 69
76
77
78
"description": "Simple Inlineable Val Chained",
- "rule": { "val": { "cat": ["te", "st"] } },
- "data": { "test": 1 },
79
80
+ "val": {
81
+ "cat": [
82
+ "te",
83
+ "st"
84
+ ]
85
+ }
86
87
88
+ "test": 1
89
90
"result": 1
91
92
suites/index.json
@@ -0,0 +1,35 @@
+[
+ "compatible.json",
+ "arithmetic/plus.json",
+ "arithmetic/plus.extra.json",
+ "arithmetic/multiply.json",
+ "arithmetic/multiply.extra.json",
+ "arithmetic/minus.json",
+ "arithmetic/minus.extra.json",
+ "arithmetic/divide.json",
+ "arithmetic/divide.extra.json",
+ "arithmetic/modulo.json",
+ "arithmetic/modulo.extra.json",
+ "comparison/greaterThan.json",
+ "comparison/greaterThanEquals.json",
+ "comparison/lessThan.json",
+ "comparison/lessThanEquals.json",
+ "comparison/softEquals.json",
+ "comparison/softNotEquals.json",
+ "comparison/strictEquals.json",
+ "comparison/strictNotEquals.json",
+ "control/and.json",
+ "control/if.json",
+ "control/or.json",
+ "truthiness.json",
+ "additional.json",
+ "coalesce.json",
27
+ "chained.json",
28
+ "iterators.extra.json",
29
+ "exists.json",
30
+ "scopes.json",
+ "throw.json",
+ "try.json",
+ "val.json",
+ "val-compat.json"
+]
0 commit comments