Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Wildcard operator behavior is different after $map #650

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
12 changes: 6 additions & 6 deletions test/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
// Rules ammendments
"rules": {
"strict": ["error", "global"],
}
}
// {
// // Rules ammendments
// "rules": {
// "strict": ["error", "global"],
// }
// }
121 changes: 68 additions & 53 deletions test/parser-recovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down