Skip to content
This repository has been archived by the owner on Jan 2, 2023. It is now read-only.

Commit

Permalink
Merge pull request #15 from aymanfarhat/develop
Browse files Browse the repository at this point in the history
Implementation a solution for unordered index matching case in object arrays
  • Loading branch information
Bassem Dghaidi authored May 24, 2020
2 parents fa10629 + cf5f9d5 commit f1e8e8f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
10 changes: 9 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,15 @@ const match = (payload, pattern, callback) => {
*/
} else if (element instanceof Object) {
currentNode[key][index] = {}
tester(payload[key][index], element, currentNode[key][index])

payload[key].forEach((payloadItem, payloadIndex) => {
if (payloadItem instanceof Object) {
const payloadItemMatch = match(payloadItem, element)
if (payloadItemMatch.match) {
tester(payload[key][payloadIndex], element, currentNode[key][index])
}
}
})
} else if (payload[key].includes(element)) {
currentNode[key][index] = element
result.total += 1
Expand Down
39 changes: 33 additions & 6 deletions test/test_objectron.js
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,15 @@ suite('Objectron Core Tests', () => {
{
type: 'markdown',
text: '*This must be it*'
}
},
{
type: 'html',
text: '<b>Hello world</b>'
},
{
type: 'yaml',
text: 'Another text!'
},
]
}
}
Expand All @@ -578,14 +586,22 @@ suite('Objectron Core Tests', () => {
{
type: 'markdown',
text: /.*/
}
},
{
type: 'html',
text: /<b>(.*?)<\/b>/
},
{
type: 'yaml',
text: /(?<yamlText>.*)/,
},
]
}
})

const expected = {
match: true,
total: 8,
total: 11,
matches: {
api: 13,
ids: [12, 130, 45],
Expand All @@ -595,13 +611,24 @@ suite('Objectron Core Tests', () => {
{
type: 'markdown',
text: '*This must be it*'
}
},
{
type: 'html',
text: '<b>Hello world</b>'
},
{
type: 'yaml',
text: 'Another text!'
},
]
}
},
groups: {}
groups: {
yamlText: 'Another text!'
}
}

assert.isFalse(result.match)
assert.isTrue(result.match)
assert.deepEqual(result, expected)
})
})

0 comments on commit f1e8e8f

Please sign in to comment.