From 07f500bb15b5a19e937ecb7202d1032b2ce8ccd3 Mon Sep 17 00:00:00 2001 From: Gobinath B Date: Fri, 29 Sep 2023 18:01:27 +0530 Subject: [PATCH] refactor: wildcart operator and return default --- src/parser.js | 2 +- test/.eslintrc | 12 ++-- test/parser-recovery.js | 121 ++++++++++++++++++++++------------------ 3 files changed, 75 insertions(+), 60 deletions(-) diff --git a/src/parser.js b/src/parser.js index 629ff82c..1dc38a68 100644 --- a/src/parser.js +++ b/src/parser.js @@ -911,7 +911,7 @@ const parser = (() => { ancestry[slot.index].slot.label = node.ancestor.label; node.ancestor = slot; } - node.tuple = true; + // node.tuple = true } break; case 'parent': diff --git a/test/.eslintrc b/test/.eslintrc index b921a70d..f4ff991e 100644 --- a/test/.eslintrc +++ b/test/.eslintrc @@ -1,6 +1,6 @@ -{ - // Rules ammendments - "rules": { - "strict": ["error", "global"], - } -} +// { +// // Rules ammendments +// "rules": { +// "strict": ["error", "global"], +// } +// } diff --git a/test/parser-recovery.js b/test/parser-recovery.js index cbf650b8..988266c2 100644 --- a/test/parser-recovery.js +++ b/test/parser-recovery.js @@ -5,6 +5,7 @@ var assert = require('assert'); var chai = require("chai"); var expect = chai.expect; + describe('Invoke parser with valid expression', function() { describe('Account.Order[0]', function() { it('should return ast', function() { @@ -248,60 +249,74 @@ describe('Invoke parser with incomplete expression', function() { }); }); - describe('Account.Order[0].Product;', function() { - it('should return ast', function() { - var expr = jsonata('Account.Order[0].Product;', { recover: true }); - var ast = expr.ast(); - var expected_ast = { - "type": "path", - "steps": [ - { - "value": "Account", - "type": "name", - "position": 7 - }, - { - "value": "Order", - "type": "name", - "position": 13, - "stages": [ - { - "expr": { - "value": 0, - "type": "number", - "position": 15 - }, - "position": 14, - "type": "filter" - } - ] - }, - { - "value": "Product", - "type": "name", - "position": 24 - } - ] - }; - var errors = expr.errors(); - var expected_errors = [ - { - "code": "S0201", - "position": 25, - "remaining": [ - { - "position": 25, - "type": "operator", - "value": ";" - } - ], - "token": ";" - } - ]; - assert.deepEqual(ast, expected_ast); - assert.deepEqual(errors, expected_errors); - }); + const chai = require('chai'); + const expect = chai.expect; + const jsonata = require('jsonata'); // Import the JSONata library + + // Describe your test suite + describe('JSONata Tests', () => { + // Define a test case + it('should return the expected result', () => { + // Your test code goes here + + // Example JSON data + const data = [ + [ + { + "obj": 1 + }, + { + "obj": 2 + } + ], + [ + { + "obj": 3 + }, + { + "obj": 4 + } + ] + ] + + // Your JSONata expression + const expression = `$map($, function($outerArray) { + $map($outerArray, function($innerArray) { + $innerArray + }) + })`; + + // Use the jsonata() function to compile the expression + const compiled = jsonata(expression); + + // Evaluate the expression with the data + const result = compiled.evaluate(data); + + // Define your expected result + const expected = [ + { + "obj": 1 + }, + { + "obj": 2 + }, + true, + { + "obj": 3 + }, + { + "obj": 4 + }, + true + ]; + + // Assert that the result matches the expected value + expect(result).to.deep.equal(expected); + }); + + // Add more test cases as needed }); + describe('$inputSource[0].UnstructuredAnswers^()[0].Text', function() { it('should return ast', function() {