diff --git a/compatible.test.js b/compatible.test.js index efd788c..74e2f49 100644 --- a/compatible.test.js +++ b/compatible.test.js @@ -4,19 +4,15 @@ import { LogicEngine, AsyncLogicEngine } from './index.js' const tests = [] -// get all json files from "suites" directory, 1 layer of depth -const files = fs.readdirSync('./suites', { withFileTypes: true }).flatMap(i => { - if (i.isDirectory()) return fs.readdirSync(`./suites/${i.name}`).map(j => `${i.name}/${j}`) - return i.name -}) +// Load test files from index.json +const indexContent = JSON.parse(fs.readFileSync('./suites/index.json').toString()) -for (const file of files) { - if (file.endsWith('.json')) { - tests.push(...JSON.parse(fs.readFileSync(`./suites/${file}`).toString()).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 - })) - } +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 + })) } function correction (x) { diff --git a/suites/additional.json b/suites/additional.json index 1f6cf6d..79bc028 100644 --- a/suites/additional.json +++ b/suites/additional.json @@ -1,24 +1,26 @@ [ "# These are some tests from https://github.com/TotalTechGeek/json-logic-engine/commit/9125e91b5137938a8319de1103b0ebc5819e54e1", - [ - [ + { + "description": "Rule array with val", + "rule": [ 1, { "val": "x" }, 3 ], - { + "data": { "x": 2 }, - [ + "result": [ 1, 2, 3 ] - ], - [ - { + }, + { + "description": "If Operator fetching both condition and consequent from data", + "rule": { "if": [ { "val": "x" @@ -31,16 +33,17 @@ 99 ] }, - { + "data": { "x": true, "y": 42 }, - [ + "result": [ 42 ] - ], - [ - { + }, + { + "description": "Reduce Operator with val", + "rule": { "reduce": [ { "val": "integers" @@ -60,7 +63,7 @@ } ] }, - { + "data": { "integers": [ 1, 2, @@ -69,12 +72,21 @@ ], "start_with": 59 }, - 69 - ], + "result": 69 + }, { "description": "Simple Inlineable Val Chained", - "rule": { "val": { "cat": ["te", "st"] } }, - "data": { "test": 1 }, + "rule": { + "val": { + "cat": [ + "te", + "st" + ] + } + }, + "data": { + "test": 1 + }, "result": 1 } ] \ No newline at end of file diff --git a/suites/index.json b/suites/index.json new file mode 100644 index 0000000..b2acc8b --- /dev/null +++ b/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", + "chained.json", + "iterators.extra.json", + "exists.json", + "scopes.json", + "throw.json", + "try.json", + "val.json", + "val-compat.json" +] \ No newline at end of file