Skip to content

Commit 91584a7

Browse files
committed
Switch to new spec format on chained / compatible
1 parent 06d0af9 commit 91584a7

File tree

5 files changed

+1774
-3580
lines changed

5 files changed

+1774
-3580
lines changed

.npmignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ bench/
99
.eslintrc.json
1010
perf*.js
1111
*.test.js
12-
experiments/
12+
experiments/
13+
suites/

compatible.test.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ const tests = []
55
// get all json files from "suites" directory
66
const files = fs.readdirSync('./suites')
77
for (const file of files) {
8-
if (file.endsWith('.json')) tests.push(...JSON.parse(fs.readFileSync(`./suites/${file}`).toString()).filter(i => typeof i !== 'string'))
8+
if (file.endsWith('.json')) {
9+
tests.push(...JSON.parse(fs.readFileSync(`./suites/${file}`).toString()).filter(i => typeof i !== 'string').map(i => {
10+
if (Array.isArray(i)) return i
11+
return [i.rule, i.data || {}, i.result]
12+
}))
13+
}
914
}
1015

1116
// eslint-disable-next-line no-labels

suites/additional.json

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
[
2+
"# These are some tests from https://github.com/TotalTechGeek/json-logic-engine/commit/9125e91b5137938a8319de1103b0ebc5819e54e1",
3+
[
4+
[
5+
1,
6+
{
7+
"var": "x"
8+
},
9+
3
10+
],
11+
{
12+
"x": 2
13+
},
14+
[
15+
1,
16+
2,
17+
3
18+
]
19+
],
20+
[
21+
{
22+
"if": [
23+
{
24+
"var": "x"
25+
},
26+
[
27+
{
28+
"var": "y"
29+
}
30+
],
31+
99
32+
]
33+
},
34+
{
35+
"x": true,
36+
"y": 42
37+
},
38+
[
39+
42
40+
]
41+
],
42+
[
43+
{
44+
"reduce": [
45+
{
46+
"var": "integers"
47+
},
48+
{
49+
"+": [
50+
{
51+
"var": "current"
52+
},
53+
{
54+
"var": "accumulator"
55+
}
56+
]
57+
},
58+
{
59+
"var": "start_with"
60+
}
61+
]
62+
},
63+
{
64+
"integers": [
65+
1,
66+
2,
67+
3,
68+
4
69+
],
70+
"start_with": 59
71+
},
72+
69
73+
]
74+
]

suites/chained.json

Lines changed: 59 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,62 @@
11
[
2-
"These are tests from https://github.com/orgs/json-logic/discussions/2",
3-
[
4-
{ "max": [1, 2, 3] },
5-
{},
6-
3,
7-
"Standard Max"
8-
],
9-
[
10-
{ "max": 1 },
11-
{},
12-
1,
13-
"Standard Max, Single Argument Sugared"
14-
],
15-
[
16-
{ "max": { "var": "data" } },
17-
{ "data": [1, 2, 3] },
18-
3,
19-
"Max with Logic Chaining"
20-
],
21-
[
22-
{ "cat": { "merge": [["Hello "], ["World", "!"]] } },
23-
{},
24-
"Hello World!",
25-
"Cat with Logic Chaining"
26-
],
27-
[
28-
{ "cat": { "var": "text" } },
29-
{ "text": ["Hello ", "World", "!"] },
30-
"Hello World!",
31-
"Cat with Logic Chaining (Simple)"
32-
],
33-
[
34-
{
35-
"max": {
36-
"map": [
37-
{
38-
"filter": [
39-
{ "var": "people" },
40-
{ "===": [{ "var": "department" }, "Engineering"] }
41-
]
42-
},
43-
{ "var": "salary" }
44-
]
45-
}
2+
"# These are tests from https://github.com/orgs/json-logic/discussions/2",
3+
{
4+
"description": "Standard Max",
5+
"rule": { "max": [1, 2, 3] },
6+
"data": {},
7+
"result": 3
8+
},
9+
{
10+
"description": "Standard Max, Single Argument Sugared",
11+
"rule": { "max": 1 },
12+
"data": {},
13+
"result": 1
14+
},
15+
{
16+
"description": "Max with Logic Chaining",
17+
"rule": { "max": { "var": "data" } },
18+
"data": { "data": [1, 2, 3] },
19+
"result": 3
20+
},
21+
{
22+
"description": "Cat with Logic Chaining",
23+
"rule": { "cat": { "merge": [["Hello "], ["World", "!"]] } },
24+
"data": {},
25+
"result": "Hello World!"
26+
},
27+
{
28+
"description": "Cat with Logic Chaining (Simple)",
29+
"rule": { "cat": { "var": "text" } },
30+
"data": { "text": ["Hello ", "World", "!"] },
31+
"result": "Hello World!"
32+
},
33+
{
34+
"rule": {
35+
"max": {
36+
"map": [{
37+
"filter": [
38+
{ "var": "people" },
39+
{ "===": [{ "var": "department" }, "Engineering"] }
40+
]},
41+
{ "var": "salary" }
42+
]
43+
}
4644
},
47-
{
48-
"people": [
49-
{ "name": "Jay Ortiz", "salary": 100414, "department": "Engineering"},
50-
{ "name": "Louisa Hall", "salary": 133601, "department": "Sales"},
51-
{ "name": "Kyle Carlson", "salary": 139803, "department": "Sales"},
52-
{ "name": "Grace Ortiz", "salary": 147068, "department": "Engineering"},
53-
{ "name": "Isabelle Harrington", "salary": 112704, "department": "Marketing"},
54-
{ "name": "Harold Moore", "salary": 125221, "department": "Sales"},
55-
{ "name": "Clarence Schultz", "salary": 127985, "department": "Sales"},
56-
{ "name": "Jesse Keller", "salary": 149212, "department": "Engineering"},
57-
{ "name": "Phillip Holland", "salary": 105888, "department": "Marketing"},
58-
{ "name": "Mason Sullivan", "salary": 147161, "department": "Engineering" }
59-
]
45+
"data": {
46+
"people": [
47+
{ "name": "Jay Ortiz", "salary": 100414, "department": "Engineering"},
48+
{ "name": "Louisa Hall", "salary": 133601, "department": "Sales"},
49+
{ "name": "Kyle Carlson", "salary": 139803, "department": "Sales"},
50+
{ "name": "Grace Ortiz", "salary": 147068, "department": "Engineering"},
51+
{ "name": "Isabelle Harrington", "salary": 112704, "department": "Marketing"},
52+
{ "name": "Harold Moore", "salary": 125221, "department": "Sales"},
53+
{ "name": "Clarence Schultz", "salary": 127985, "department": "Sales"},
54+
{ "name": "Jesse Keller", "salary": 149212, "department": "Engineering"},
55+
{ "name": "Phillip Holland", "salary": 105888, "department": "Marketing"},
56+
{ "name": "Mason Sullivan", "salary": 147161, "department": "Engineering" }
57+
]
6058
},
61-
149212,
62-
"Max with Logic Chaining (Complex)"
63-
]
64-
]
59+
"result": 149212,
60+
"description": "Max with Logic Chaining (Complex)"
61+
}
62+
]

0 commit comments

Comments
 (0)