Filter/mirror bugfix
This commit is contained in:
parent
480c362c1e
commit
f0d22328cd
4 changed files with 52 additions and 61 deletions
|
@ -4,48 +4,56 @@ const Point = require('../../src/point')
|
|||
|
||||
describe('Filter', function() {
|
||||
|
||||
it('empty', function() {
|
||||
filter(undefined, '').should.deep.equal([new Point()])
|
||||
filter(true, '').should.deep.equal([])
|
||||
filter(false, '').should.deep.equal([])
|
||||
it('without points', function() {
|
||||
filter(undefined, '').should.deep.equal([new Point()])
|
||||
filter(true, '').should.deep.equal([])
|
||||
filter(false, '').should.deep.equal([])
|
||||
filter({}, '').should.deep.equal([anchor({}, '', points)()])
|
||||
})
|
||||
|
||||
const points = {
|
||||
one: new Point(0, 1, 0, {name: 'one', tags: ['odd']}),
|
||||
two: new Point(0, 2, 0, {name: 'two', tags: ['even', 'prime']}),
|
||||
three: new Point(0, 3, 0, {name: 'three', tags: {odd: 'yes', prime: 'yupp'}})
|
||||
three: new Point(0, 3, 0, {name: 'three', tags: {odd: 'yes', prime: 'yupp'}}),
|
||||
mirror_one: new Point(0, 1, 0, {name: 'mirror_one', tags: ['odd'], mirrored: true})
|
||||
}
|
||||
|
||||
const names = points => points.map(p => p.meta.name)
|
||||
|
||||
it('similar', function() {
|
||||
it('empty filter', function() {
|
||||
// an undefined config leads to a default point
|
||||
filter(undefined, '', points).should.deep.equal([new Point()])
|
||||
// true shouldn't filter anything, while false should filter everything
|
||||
filter(true, '', points).should.deep.equal(Object.values(points))
|
||||
filter(false, '', points).should.deep.equal([])
|
||||
// points should only be returned on their respective halves
|
||||
// - so `source` is every match
|
||||
filter(true, '', points, undefined, 'source').should.deep.equal(Object.values(points))
|
||||
filter(true, '', points, undefined, 'clone').should.deep.equal([])
|
||||
// - `clone` is the mirror image of every match, which maps one to mirror_one, mirror_one to one, and two/three to nothing (as they don't have mirror parts)
|
||||
filter(true, '', points, undefined, 'clone').should.deep.equal([points.mirror_one, points.one])
|
||||
// - and `both` is every match plus its mirror image as well
|
||||
filter(true, '', points, undefined, 'both').should.deep.equal(Object.values(points))
|
||||
// objects just propagate to anchor (and then wrap in array for consistency)
|
||||
filter({}, '', points).should.deep.equal([anchor({}, '', points)()])
|
||||
filter({}, '', points, undefined, 'source').should.deep.equal([anchor({}, '', points)()])
|
||||
filter({}, '', points, undefined, 'clone').should.deep.equal([anchor({}, '', points)()])
|
||||
filter({}, '', points, undefined, 'both').should.deep.equal([anchor({}, '', points)(), anchor({}, '', points)()])
|
||||
filter({}, '', points, undefined, 'both').should.deep.equal([anchor({}, '', points)()])
|
||||
})
|
||||
|
||||
const names = points => points.map(p => p.meta.name)
|
||||
|
||||
it('similar', function() {
|
||||
// simple name string
|
||||
names(filter('one', '', points)).should.deep.equal(['one'])
|
||||
// simple name regex
|
||||
names(filter('/^t/', '', points)).should.deep.equal(['two', 'three'])
|
||||
// tags should count, too (one for the name, three for the odd tag)
|
||||
names(filter('/^o/', '', points)).should.deep.equal(['one', 'three'])
|
||||
// tags should count, too (one and mirror_one for the name, three for the odd tag)
|
||||
names(filter('/^o/', '', points)).should.deep.equal(['one', 'three', 'mirror_one'])
|
||||
// middle spec, should be the same as above, only explicit
|
||||
names(filter('~ /^o/', '', points)).should.deep.equal(['one', 'three'])
|
||||
names(filter('~ /^o/', '', points)).should.deep.equal(['one', 'three', 'mirror_one'])
|
||||
// full spec (n would normally match both one and even, but on the tags level, it's just even)
|
||||
names(filter('meta.tags ~ /n/', '', points)).should.deep.equal(['two'])
|
||||
// negation
|
||||
names(filter('meta.tags ~ -/n/', '', points)).should.deep.equal(['one', 'three'])
|
||||
// arrays OR by default at odd levels levels (including top level)...
|
||||
names(filter('meta.tags ~ -/n/', '', points)).should.deep.equal(['one', 'three', 'mirror_one'])
|
||||
// arrays OR by default at odd levels (including top level)...
|
||||
names(filter(['one', 'two'], '', points)).should.deep.equal(['one', 'two'])
|
||||
// ...and AND at even levels
|
||||
names(filter([['even', 'prime']], '', points)).should.deep.equal(['two'])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue