mjhm / lodash-match-pattern

Deep JSON pattern matching library
MIT License
50 stars 3 forks source link

subset matches for arrays of objects don't properly error #34

Closed mjhm closed 7 years ago

mjhm commented 7 years ago
matchPattern([{a: 'ab'}], '[{a: "ab"} ...]')

Results in error string

'Array [ { a: \'ab\' } ] isn\'t a subset match of Array [ { a: \'ab\' } ]'

This should either be allowed or a more instructive error message.

snowyu commented 7 years ago

this bug confirmed.

matchPattern([{}, 1], [{},'...'])

   'Array [ {}, 1 ] isn\'t a subset match of Array [ {} ]'

It should treat the array as object to match.

mjhm commented 7 years ago

@snowyu Thanks -- I'm going to have to fix this.

mjhm commented 7 years ago

Fixed https://github.com/Originate/lodash-match-pattern/releases/tag/v1.3.1

This now does deep matching of explicit subset, superset, equalset values, though it still doesn't allow matching functions in set elements. Such corner cases are probably too complicated to be implemented in this library.

Sarilha commented 7 years ago

I've solved my problem by getting every object at the set and using "matching functions" to compare every object.

Like the function below: function successArray(res, status, objectToCompare) { chai.expect(res) .to.have.status(status); chai.expect(res.body) .is.an('array'); res.body.forEach(function(entry) { chai.expect(entry).to.matchPattern(objectToCompare); });