-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselector-semantics.spec.js
644 lines (507 loc) · 23.1 KB
/
selector-semantics.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
import { parse } from './selector.js';
import sinon from 'sinon';
describe('Selector semantics', function() {
const MODE_NORMAL = 0;
const MODE_STRICT = 1;
const MODE_LENIENT = 2;
describe('Simple selectors', function() {
it('should select the root object with an empty selector', function() {
sinon.stub(console, 'warn'); // Disable deprecation warning from showing
try {
const key = '';
const obj = {};
const resolution = parse(key)(obj);
expect(resolution).to.be.an('array').with.lengthOf(1);
expect(resolution[0]).to.have.property('target').that.deep.equals({ obj });
expect(resolution[0]).to.have.property('selection').that.is.an('array').with.members([ 'obj' ]);
} finally {
console.warn.restore();
}
});
it('should select a property by name', function() {
const key = 'a';
const obj = {};
const resolution = parse(key)(obj);
expect(resolution).to.be.an('array').with.lengthOf(1);
expect(resolution[0]).to.have.property('target').that.equals(obj);
expect(resolution[0]).to.have.property('selection').that.is.an('array').with.members([ key ]);
});
it('should select inherited properties', function() {
const key = 'a';
const obj = Object.create({});
const resolution = parse(key)(obj);
expect(resolution).to.be.an('array').with.lengthOf(1);
expect(resolution[0]).to.have.property('target').that.equals(obj);
expect(resolution[0]).to.have.property('selection').that.is.an('array').with.members([ key ]);
});
});
describe('Accessor selectors', function() {
it('should change the targets to the selected properties', function() {
const key = 'a.b';
const obj = { a: {} };
const resolution = parse(key)(obj);
expect(resolution).to.be.an('array').with.lengthOf(1);
expect(resolution[0]).to.have.property('target').that.equals(obj.a);
});
});
describe('Wildcard selectors', function() {
it('should select all properties with matching names (asterisk)', function() {
const key = 'a*';
const obj = { a1: {}, a2: {}, b: {}, abc: {} };
const resolution = parse(key)(obj);
expect(resolution).to.be.an('array').with.lengthOf(1);
expect(resolution[0]).to.have.property('target').that.equals(obj);
expect(resolution[0]).to.have.property('selection').that.has.members([ 'a1', 'a2', 'abc' ]);
});
it('should select all properties with matching names (question mark)', function() {
const key = 'a?';
const obj = { a1: {}, a2: {}, b: {}, abc: {} };
const resolution = parse(key)(obj);
expect(resolution).to.be.an('array').with.lengthOf(1);
expect(resolution[0]).to.have.property('target').that.equals(obj);
expect(resolution[0]).to.have.property('selection').that.has.members([ 'a1', 'a2' ]);
});
it('should select inherited properties', function() {
const key = 'a?';
const obj = Object.create({ a1: {}, a2: {} });
const resolution = parse(key)(obj);
expect(resolution).to.be.an('array').with.lengthOf(1);
expect(resolution[0]).to.have.property('target').that.equals(obj);
expect(resolution[0]).to.have.property('selection').that.has.members([ 'a1', 'a2' ]);
});
it('should not select non-enumerable properties', function() {
const key = 'a?';
const obj = {};
Object.defineProperty(obj, 'a1', {
value: {},
enumerable: false,
configurable: true,
writable: true
});
const resolution = parse(key)(obj);
expect(resolution).to.be.an('array').with.lengthOf(1);
expect(resolution[0]).to.have.property('target').that.equals(obj);
expect(resolution[0]).to.have.property('selection').that.is.empty;
});
});
describe('Pseudo properties', function() {
describe('::root', function() {
it('should select the input object with', function() {
const obj = { a: {} };
[ '::root', 'a.::root' ].forEach(key => {
const resolution = parse(key)(obj);
expect(resolution).to.be.an('array').with.lengthOf(1);
expect(resolution[0]).to.have.property('target').that.deep.equals({ '::root': obj });
expect(resolution[0]).to.have.property('selection').that.has.members([ '::root' ]);
});
});
});
// eslint-disable-next-line mocha/no-setup-in-describe
[ 'first', 'last' ].forEach((pseudo, index) => {
describe(`::${pseudo}`, function() {
it(`should select the ${pseudo} element of an array`, function() {
const obj = [ 0, 1 ];
const resolution = parse(`::${pseudo}`)(obj);
expect(resolution).to.be.an('array').with.lengthOf(1);
expect(resolution[0]).to.have.property('target').that.equals(obj);
expect(resolution[0]).to.have.property('selection').that.has.members([ String(index) ]);
});
it(`should select the ${pseudo} property of an object`, function() {
const obj = { a: 1, b: 2 };
const resolution = parse(`::${pseudo}`)(obj);
expect(resolution).to.be.an('array').with.lengthOf(1);
expect(resolution[0]).to.have.property('target').that.equals(obj);
expect(resolution[0]).to.have.property('selection').that.has.members([ 'ab'[index] ]);
});
it(`should select the ${pseudo} character of a string`, function() {
const obj = 'ab';
const resolution = parse(`::${pseudo}`)(obj);
expect(resolution).to.be.an('array').with.lengthOf(1);
expect(resolution[0]).to.have.property('target').that.equals(obj);
// Object keys are ordered in the order they are defined:
expect(resolution[0]).to.have.property('selection').that.has.members([ String(index) ]);
});
it('should select nothing on anything else', function() {
const obj = 1;
const resolution = parse(`::${pseudo}`)(obj);
expect(resolution).to.be.an('array').with.lengthOf(1);
expect(resolution[0]).to.have.property('target').that.equals(obj);
// Object keys are ordered in the order they are defined:
expect(resolution[0]).to.have.property('selection').that.is.empty;
});
});
});
});
describe('Meta properties', function() {
// eslint-disable-next-line mocha/no-setup-in-describe
const PRIMITIVES = [ 'string', 123, 123n, true, undefined, Symbol(), null ]
// eslint-disable-next-line mocha/no-setup-in-describe
describe(`${new Intl.ListFormat('en', { style: 'long', type: 'conjunction' }).format(PRIMITIVES.map(primitive => primitive === null ? 'null' : typeof primitive).map(metaProperty => `:${metaProperty}`))}`, function() {
it('should select primitives of the given type', function() {
PRIMITIVES.forEach(primitive => {
const obj = { a: primitive }
const resolution = parse(`*:${primitive === null ? 'null' : typeof primitive}`)(obj);
expect(resolution).to.be.an('array').with.lengthOf(1);
expect(resolution[0]).to.have.property('target').that.equals(obj);
expect(resolution[0]).to.have.property('selection').that.has.members([ 'a' ]);
});
});
it('should discard all other values', function() {
PRIMITIVES.forEach(primitive => {
const others = [ {}, [], ...PRIMITIVES.filter(x => x !== primitive) ];
others.forEach(other => {
const obj = { a: other };
const resolution = parse(`*:${primitive === null ? 'null' : typeof primitive}`)(obj);
expect(resolution).to.be.an('array').with.lengthOf(1);
expect(resolution[0]).to.have.property('target').that.equals(obj);
expect(resolution[0]).to.have.property('selection').that.is.empty;
});
});
});
});
describe(':primitive', function() {
it(`should select values of type ${new Intl.ListFormat('en', { style: 'long', type: 'conjunction' }).format(PRIMITIVES.map(primitive => primitive === null ? 'null' : typeof primitive))}`, function() {
PRIMITIVES.forEach(primitive => {
const obj = { a: primitive }
const resolution = parse('*:primitive')(obj);
expect(resolution).to.be.an('array').with.lengthOf(1);
expect(resolution[0]).to.have.property('target').that.equals(obj);
expect(resolution[0]).to.have.property('selection').that.has.members([ 'a' ]);
});
});
it('should discard values of type object', function() {
const obj = { a: {} }
const resolution = parse('*:primitive')(obj);
expect(resolution).to.be.an('array').with.lengthOf(1);
expect(resolution[0]).to.have.property('target').that.equals(obj);
expect(resolution[0]).to.have.property('selection').that.is.empty;
});
});
describe(':object', function() {
it('should select values of type object', function() {
const obj = { a: {} }
const resolution = parse('*:object')(obj);
expect(resolution).to.be.an('array').with.lengthOf(1);
expect(resolution[0]).to.have.property('target').that.equals(obj);
expect(resolution[0]).to.have.property('selection').that.has.members([ 'a' ]);
});
it('should not select primitives', function() {
PRIMITIVES.forEach(primitive => {
const obj = { a: primitive }
const resolution = parse('*:object')(obj);
expect(resolution).to.be.an('array').with.lengthOf(1);
expect(resolution[0]).to.have.property('target').that.equals(obj);
expect(resolution[0]).to.have.property('selection').that.is.empty;
});
});
it('should not select arrays', function() {
const obj = { a: [] }
const resolution = parse('*:object')(obj);
expect(resolution).to.be.an('array').with.lengthOf(1);
expect(resolution[0]).to.have.property('target').that.equals(obj);
expect(resolution[0]).to.have.property('selection').that.is.empty;
});
});
describe(':array', function() {
it('should select values of type array', function() {
const obj = { a: [] }
const resolution = parse('*:array')(obj);
expect(resolution).to.be.an('array').with.lengthOf(1);
expect(resolution[0]).to.have.property('target').that.equals(obj);
expect(resolution[0]).to.have.property('selection').that.has.members([ 'a' ]);
});
it('should not select objects or primitives', function() {
[ {}, ...PRIMITIVES ].forEach(objectOrPrimitive => {
const obj = { a: objectOrPrimitive }
const resolution = parse('*:array')(obj);
expect(resolution).to.be.an('array').with.lengthOf(1);
expect(resolution[0]).to.have.property('target').that.equals(obj);
expect(resolution[0]).to.have.property('selection').that.is.empty;
});
});
});
describe(':complex', function() {
it('should select values of type array', function() {
const obj = { a: [] }
const resolution = parse('*:complex')(obj);
expect(resolution).to.be.an('array').with.lengthOf(1);
expect(resolution[0]).to.have.property('target').that.equals(obj);
expect(resolution[0]).to.have.property('selection').that.has.members([ 'a' ]);
});
it('should select values of type object', function() {
const obj = { a: {} }
const resolution = parse('*:complex')(obj);
expect(resolution).to.be.an('array').with.lengthOf(1);
expect(resolution[0]).to.have.property('target').that.equals(obj);
expect(resolution[0]).to.have.property('selection').that.has.members([ 'a' ]);
});
it('should not select primitives', function() {
PRIMITIVES.forEach(primitive => {
const obj = { a: primitive }
const resolution = parse('*:complex')(obj);
expect(resolution).to.be.an('array').with.lengthOf(1);
expect(resolution[0]).to.have.property('target').that.equals(obj);
expect(resolution[0]).to.have.property('selection').that.is.empty;
});
});
});
describe(':existent', function() {
it('should select values other than null/undefined', function() {
const obj = { a: null, b: undefined, c: 1 }
const resolution = parse('*:existent')(obj);
expect(resolution).to.be.an('array').with.lengthOf(1);
expect(resolution[0]).to.have.property('target').that.equals(obj);
expect(resolution[0]).to.have.property('selection').that.has.members([ 'c' ]);
});
});
describe(':nonexistent', function() {
it('should select only values null/undefined', function() {
const obj = { a: null, b: undefined, c: 1 }
const resolution = parse('*:nonexistent')(obj);
expect(resolution).to.be.an('array').with.lengthOf(1);
expect(resolution[0]).to.have.property('target').that.equals(obj);
expect(resolution[0]).to.have.property('selection').that.has.members([ 'a', 'b' ]);
});
});
describe(':unique', function() {
it('should filter out values that are present more than once', function() {
const obj = {
a: 1,
b: 1
}
const resolution = parse('*:unique')(obj);
expect(resolution).to.be.an('array').with.lengthOf(1);
expect(resolution[0]).to.have.property('target').that.equals(obj);
expect(resolution[0]).to.have.property('selection').that.has.members([ 'a' ]);
});
it('should not filter out values that are present only once', function() {
const obj = {
a: 1,
b: 2
}
const resolution = parse('*:unique')(obj);
expect(resolution).to.be.an('array').with.lengthOf(1);
expect(resolution[0]).to.have.property('target').that.equals(obj);
expect(resolution[0]).to.have.property('selection').that.has.members([ 'a', 'b' ]);
});
});
});
describe('Conditional selectors', function() {
it('should select with complex selectors in conditions', function() {
const obj = {
a1: {
b: {
c1: 0
}
},
a2: {
b: {
cde: 1
}
},
b: {},
abc: {
b: {
cdef: 2
}
}
};
// Select all properties starting with the letter a that have a property b with a sub-property
// starting with c and ending with f that has the value 2
const key = 'a*[b.c*f == 2]';
const resolution = parse(key)(obj);
expect(resolution).to.be.an('array').with.lengthOf(1);
expect(resolution[0]).to.have.property('target').that.equals(obj);
expect(resolution[0]).to.have.property('selection').that.has.members([ 'abc' ]);
});
it('should select only properties with a truthy value for a unary condition', function() {
const key = 'a[b]';
let obj = { a: { b: 1 } };
// Condition satisfied:
let resolution = parse(key)(obj);
expect(resolution).to.be.an('array').with.lengthOf(1);
expect(resolution[0]).to.have.property('target').that.equals(obj);
expect(resolution[0]).to.have.property('selection').that.has.members([ 'a' ]);
// Condition not satisfied:
obj.a.b = 0;
resolution = parse(key)(obj);
expect(resolution).to.be.an('array').with.lengthOf(1);
expect(resolution[0]).to.have.property('target').that.equals(obj);
expect(resolution[0]).to.have.property('selection').that.is.empty;
});
// The following tests are auto-generated to test all recognized condition operators.
// The condition is generated as [b <operator> <value>].
// A positive test is generated by setting obj.a.b to satisifed, a negative test is
// generated by setting obj.a.b to violated.
// If value is not supplied, it is set to the value of satisfied.
// eslint-disable-next-line mocha/no-setup-in-describe
[
{ operator: '==', meaning: 'loosely equal to', satisfied: 1, violated: 2 },
{ operator: '===', meaning: 'strictly equal to', satisfied: '1', violated: 1 },
{ operator: '!==', meaning: 'not strictly equal to', satisfied: 1, violated: '1' },
{ operator: '!=', meaning: 'not loosely equal to', satisfied: 2, violated: 1, value: 1 },
{ operator: '^=', meaning: 'beginning with', satisfied: 'xyz', violated: 'zyx', value: 'x' },
{ operator: '$=', meaning: 'ending with', satisfied: 'xyz', violated: 'zyx', value: 'z' },
{ operator: '~=', meaning: 'matching the regex of', satisfied: 'abba', violated: 'aa', value: 'ab\\+a' },
{ operator: '<', meaning: 'strictly less than', satisfied: 'a', violated: 'b', value: 'b' },
{ operator: '<=', meaning: 'less than or equal to', satisfied: 'a', violated: 'c', value: 'b' },
{ operator: '>', meaning: 'strictly greater than', satisfied: 'c', violated: 'b', value: 'b' },
{ operator: '>=', meaning: 'greater than or equal', satisfied: 'c', violated: 'a', value: 'b' },
].forEach(({ operator, meaning, satisfied, violated, value }) =>
it(`should select only properties with a value ${meaning} the value of the condition with ${operator}`, function() {
value ??= satisfied;
const key = `a[b ${operator} ${value}]`;
let obj = { a: { b: satisfied } };
// Condition satisfied:
let resolution = parse(key)(obj);
expect(resolution).to.be.an('array').with.lengthOf(1);
expect(resolution[0]).to.have.property('target').that.equals(obj);
expect(resolution[0]).to.have.property('selection').that.has.members([ 'a' ]);
// Condition not satisfied:
obj.a.b = violated;
resolution = parse(key)(obj);
expect(resolution).to.be.an('array').with.lengthOf(1);
expect(resolution[0]).to.have.property('target').that.equals(obj);
expect(resolution[0]).to.have.property('selection').that.is.empty;
})
);
it('should replace the value in a reference value', function() {
const references = { val: 'abc' };
const obj = { a: { b: references.val }};
const resolution = parse('a[b === @val]')(obj, references);
expect(resolution).to.be.an('array').with.lengthOf(1);
expect(resolution[0]).to.have.property('target').that.equals(obj);
expect(resolution[0]).to.have.property('selection').that.has.members([ 'a' ]);
});
it('should combine multiple conditions with logical and', function() {
const obj = { a1: { b: 'x', c: 'y' }, a2: { b: 'x', c: 'not y' }};
const resolution = parse('a*[b===x][c===y]')(obj);
expect(resolution).to.be.an('array').with.lengthOf(1);
expect(resolution[0]).to.have.property('target').that.equals(obj);
expect(resolution[0]).to.have.property('selection').that.has.members([ 'a1' ]);
});
});
describe('Selection modes', function() {
describe('Normal mode', function() {
it('should not throw when selecting a non-existing property that is the terminal part of its selector', function() {
const parser = parse('a');
expect(parser.bind(null, {}, null, MODE_NORMAL)).to.not.throw();
});
it('should throw when selecting a non-existing property that is an intermediate part of the selector', function() {
expect(parse('a.b.c').bind(null, {}, null, MODE_NORMAL)).to.throw();
// There is another, slightly more complex case here: when selecting a.b on {}, parse will actually NOT throw,
// but return a resolution with an undefined target.
// (Trying to work with that resolution however will invariable throw.)
const parser = parse('a.b');
expect(parser.bind(null, {}, null, MODE_NORMAL)).to.not.throw();
const resolution = parser({}, null, MODE_NORMAL);
expect(resolution).to.be.an('array').with.lengthOf(1);
expect(resolution[0].target).to.not.exist;
});
it('should not error but resolve to a non-existent target when trying to select unambiguously on null/undefined', function() {
[ null, undefined ].forEach(tgt => {
// Helper function that invokes the parser, then executes the selection
// This ensures that even if the parser itself doesn't throw, the selection step will
function invoke(parser) {
return parser().flatMap(({ tgt, selection }) => selection.flatMap(prop => tgt[prop]));
}
expect(invoke.bind(null, parse('a').bind(null, tgt, null, MODE_NORMAL))).to.throw();
expect(invoke.bind(null, parse('*').bind(null, tgt, null, MODE_NORMAL))).to.throw();
});
});
});
describe('Strict mode', function() {
it('should throw an error when selecting a non-existing property', function() {
expect(parse('a').bind(null, {}, null, MODE_STRICT)).to.throw();
});
it('should throw an error when no properties match a wildcard selector' , function() {
expect(parse('a*').bind(null, {}, null, MODE_STRICT)).to.throw();
});
it('should throw an error when a condition uses a non-existent property', function() {
const obj = {
a1: { b: { c: 1 }},
a2: { not_b: { c: 1 }}
}
expect(parse('a?[b.c == 1]').bind(null, obj, null, MODE_STRICT)).to.throw();
});
it('should throw when the target of the resolution in a conditional selection is a literal', function() {
const obj = {
a1: { b: { c: 1 }},
a2: { b: 'literal' }
}
expect(parse('a?[b.c == 1 ]').bind(null, obj, null, MODE_STRICT)).to.throw();
});
it('should throw an error when trying to select on null/undefined', function() {
[ null, undefined ].forEach(tgt => {
expect(parse('a').bind(null, tgt, null, MODE_STRICT), `unambiguous on ${tgt}`).to.throw();
expect(parse('*').bind(null, tgt, null, MODE_NORMAL), `ambiguous on ${tgt}`).to.throw();
});
});
});
describe('Lenient mode', function() {
it('should ignore intermediate non-matches when selecting unambiguously', function() {
expect(parse('a.b')({}, {}, MODE_LENIENT)).to.be.empty;
});
it('should silently discard intermediate non-matches when selecting with wildcards', function() {
const obj = {
a1: { b: { c: 1 }},
a2: { not_b: { c: 2 }}
}
const parser = parse('a?.b.c');
expect(parser.bind(null, obj, null, MODE_LENIENT)).to.not.throw();
const resolution = parser(obj, null, MODE_LENIENT);
expect(resolution).to.be.an('array').with.lengthOf(1);
expect(resolution[0]).to.have.property('target').that.equals(obj.a1.b);
expect(resolution[0]).to.have.property('selection').that.has.members([ 'c' ]);
});
it('should evaluate a condition using non-existent properties to false', function() {
const obj = {
a1: { b: { c: 1 }},
a2: { not_b: { c: 1 }}
}
const parser = parse('a?[b.c == 1 ]');
expect(parser.bind(null, obj, null, MODE_LENIENT)).to.not.throw();
const resolution = parser(obj, null, MODE_LENIENT);
expect(resolution).to.be.an('array').with.lengthOf(1);
expect(resolution[0]).to.have.property('target').that.equals(obj);
expect(resolution[0]).to.have.property('selection').that.has.members([ 'a1' ]);
});
it('should silently discard conditional selections where the target of the resolution is a literal', function() {
const obj = {
a1: { b: { c: 1 }},
a2: { b: 'literal' }
}
const parser = parse('a?[b.c == 1 ]');
expect(parser.bind(null, obj, null, MODE_LENIENT)).to.not.throw();
const resolution = parser(obj, null, MODE_LENIENT);
expect(resolution).to.be.an('array').with.lengthOf(1);
expect(resolution[0]).to.have.property('target').that.equals(obj);
expect(resolution[0]).to.have.property('selection').that.has.members([ 'a1' ]);
});
it('should silently discard selections made on null/undefined', function() {
[ null, undefined ].forEach(tgt => {
let parser = parse('a');
const args = [ tgt, null, MODE_LENIENT ];
expect(parser.bind(null, ...args), `unambiguous on ${tgt}`).to.not.throw();
expect(parser(...args)).to.be.empty;
parser = parse('*');
expect(parser.bind(null, ...args), `ambiguous on ${tgt}`).to.not.throw();
expect(parser(...args)).to.be.empty;
});
});
});
});
describe('Selector Union', function() {
it('should return the concatenated results of all constituent selectors', function() {
const selector = `a1, a2`;
const obj = { a1: {}, a2: {}, b: {}, abc: {} };
const resolution = parse(selector)(obj);
expect(resolution).to.be.an('array').with.lengthOf(2);
resolution.forEach((res, i) => {
const sel = [ 'a1', 'a2' ][i];
expect(res).to.have.property('target').that.equals(obj);
expect(res).to.have.property('selection').that.has.members([ sel ]);
});
});
});
});