@@ -370,159 +370,14 @@ loader.paths('f-json-pretty-%N.html').forEach((path) => {
370370 test ( `json pretty - ${ path } ` , ( ) => loader . execute ( path ) ) ;
371371} ) ;
372372
373- test ( 'find-first' , ( ) => {
374- // no args: return first element unconditionally
375- let vars = variables ( [ 'a' , 'b' , 'c' ] ) ;
376- Core [ 'find-first' ] . apply ( [ ] , vars , CTX ) ;
377- expect ( vars [ 0 ] . get ( ) ) . toEqual ( 'a' ) ;
378-
379- // empty array → missing
380- vars = variables ( [ ] ) ;
381- Core [ 'find-first' ] . apply ( [ ] , vars , CTX ) ;
382- expect ( vars [ 0 ] . node . isMissing ( ) ) . toBe ( true ) ;
383-
384- // non-array → missing
385- vars = variables ( 'not-an-array' ) ;
386- Core [ 'find-first' ] . apply ( [ ] , vars , CTX ) ;
387- expect ( vars [ 0 ] . node . isMissing ( ) ) . toBe ( true ) ;
388-
389- // no args: first object element
390- vars = variables ( [ { x : 1 } , { x : 2 } ] ) ;
391- Core [ 'find-first' ] . apply ( [ ] , vars , CTX ) ;
392- expect ( vars [ 0 ] . get ( ) ) . toEqual ( { x : 1 } ) ;
393-
394- // 1 arg: find first element where path is truthy
395- vars = variables ( [ { id : 'a' , enabled : false } , { id : 'b' , enabled : true } , { id : 'c' , enabled : true } ] ) ;
396- Core [ 'find-first' ] . apply ( [ 'enabled' ] , vars , CTX ) ;
397- expect ( vars [ 0 ] . get ( ) ) . toEqual ( { id : 'b' , enabled : true } ) ;
398-
399- // 1 arg: none match → missing
400- vars = variables ( [ { id : 'a' , enabled : false } , { id : 'b' } ] ) ;
401- Core [ 'find-first' ] . apply ( [ 'enabled' ] , vars , CTX ) ;
402- expect ( vars [ 0 ] . node . isMissing ( ) ) . toBe ( true ) ;
403- } ) ;
404-
405373loader . paths ( 'f-find-first-%N.html' ) . forEach ( ( path ) => {
406374 test ( `find-first - ${ path } ` , ( ) => loader . execute ( path ) ) ;
407375} ) ;
408376
409- test ( 'find-last' , ( ) => {
410- // no args: return last element unconditionally
411- let vars = variables ( [ 'a' , 'b' , 'c' ] ) ;
412- Core [ 'find-last' ] . apply ( [ ] , vars , CTX ) ;
413- expect ( vars [ 0 ] . get ( ) ) . toEqual ( 'c' ) ;
414-
415- // empty array → missing
416- vars = variables ( [ ] ) ;
417- Core [ 'find-last' ] . apply ( [ ] , vars , CTX ) ;
418- expect ( vars [ 0 ] . node . isMissing ( ) ) . toBe ( true ) ;
419-
420- // non-array → missing
421- vars = variables ( 'not-an-array' ) ;
422- Core [ 'find-last' ] . apply ( [ ] , vars , CTX ) ;
423- expect ( vars [ 0 ] . node . isMissing ( ) ) . toBe ( true ) ;
424-
425- // no args: last object element
426- vars = variables ( [ { x : 1 } , { x : 2 } ] ) ;
427- Core [ 'find-last' ] . apply ( [ ] , vars , CTX ) ;
428- expect ( vars [ 0 ] . get ( ) ) . toEqual ( { x : 2 } ) ;
429-
430- // 1 arg: find last element where path is truthy
431- vars = variables ( [ { id : 'a' , enabled : true } , { id : 'b' , enabled : true } , { id : 'c' , enabled : false } ] ) ;
432- Core [ 'find-last' ] . apply ( [ 'enabled' ] , vars , CTX ) ;
433- expect ( vars [ 0 ] . get ( ) ) . toEqual ( { id : 'b' , enabled : true } ) ;
434-
435- // 1 arg: none match → missing
436- vars = variables ( [ { id : 'a' , enabled : false } , { id : 'b' } ] ) ;
437- Core [ 'find-last' ] . apply ( [ 'enabled' ] , vars , CTX ) ;
438- expect ( vars [ 0 ] . node . isMissing ( ) ) . toBe ( true ) ;
439- } ) ;
440-
441377loader . paths ( 'f-find-last-%N.html' ) . forEach ( ( path ) => {
442378 test ( `find-last - ${ path } ` , ( ) => loader . execute ( path ) ) ;
443379} ) ;
444380
445- test ( 'find-nth' , ( ) => {
446- // no filter: return element at index 0
447- let vars = variables ( [ 'a' , 'b' , 'c' ] ) ;
448- Core [ 'find-nth' ] . apply ( [ '0' ] , vars , CTX ) ;
449- expect ( vars [ 0 ] . get ( ) ) . toEqual ( 'a' ) ;
450-
451- // no filter: return element at index 1
452- vars = variables ( [ 'a' , 'b' , 'c' ] ) ;
453- Core [ 'find-nth' ] . apply ( [ '1' ] , vars , CTX ) ;
454- expect ( vars [ 0 ] . get ( ) ) . toEqual ( 'b' ) ;
455-
456- // no filter: negative index counts from end
457- vars = variables ( [ 'a' , 'b' , 'c' ] ) ;
458- Core [ 'find-nth' ] . apply ( [ '-1' ] , vars , CTX ) ;
459- expect ( vars [ 0 ] . get ( ) ) . toEqual ( 'c' ) ;
460-
461- vars = variables ( [ 'a' , 'b' , 'c' ] ) ;
462- Core [ 'find-nth' ] . apply ( [ '-2' ] , vars , CTX ) ;
463- expect ( vars [ 0 ] . get ( ) ) . toEqual ( 'b' ) ;
464-
465- // non-numeric index defaults to 0
466- vars = variables ( [ 'a' , 'b' , 'c' ] ) ;
467- Core [ 'find-nth' ] . apply ( [ 'foo' ] , vars , CTX ) ;
468- expect ( vars [ 0 ] . get ( ) ) . toEqual ( 'a' ) ;
469-
470- // index out of bounds → missing
471- vars = variables ( [ 'a' , 'b' , 'c' ] ) ;
472- Core [ 'find-nth' ] . apply ( [ '5' ] , vars , CTX ) ;
473- expect ( vars [ 0 ] . node . isMissing ( ) ) . toBe ( true ) ;
474-
475- // negative index out of bounds → missing
476- vars = variables ( [ 'a' , 'b' , 'c' ] ) ;
477- Core [ 'find-nth' ] . apply ( [ '-5' ] , vars , CTX ) ;
478- expect ( vars [ 0 ] . node . isMissing ( ) ) . toBe ( true ) ;
479-
480- // empty array → missing
481- vars = variables ( [ ] ) ;
482- Core [ 'find-nth' ] . apply ( [ '0' ] , vars , CTX ) ;
483- expect ( vars [ 0 ] . node . isMissing ( ) ) . toBe ( true ) ;
484-
485- // non-array → missing
486- vars = variables ( 'not-an-array' ) ;
487- Core [ 'find-nth' ] . apply ( [ '0' ] , vars , CTX ) ;
488- expect ( vars [ 0 ] . node . isMissing ( ) ) . toBe ( true ) ;
489-
490- // no filter: nth object element
491- vars = variables ( [ { x : 1 } , { x : 2 } , { x : 3 } ] ) ;
492- Core [ 'find-nth' ] . apply ( [ '2' ] , vars , CTX ) ;
493- expect ( vars [ 0 ] . get ( ) ) . toEqual ( { x : 3 } ) ;
494-
495- // with path: find nth element where path is truthy
496- vars = variables ( [
497- { id : 'a' , enabled : false } ,
498- { id : 'b' , enabled : true } ,
499- { id : 'c' , enabled : true } ,
500- { id : 'd' , enabled : true } ,
501- ] ) ;
502- Core [ 'find-nth' ] . apply ( [ '1' , 'enabled' ] , vars , CTX ) ;
503- expect ( vars [ 0 ] . get ( ) ) . toEqual ( { id : 'c' , enabled : true } ) ;
504-
505- // with path: index 0 of matching elements
506- vars = variables ( [ { id : 'a' , enabled : false } , { id : 'b' , enabled : true } , { id : 'c' , enabled : true } ] ) ;
507- Core [ 'find-nth' ] . apply ( [ '0' , 'enabled' ] , vars , CTX ) ;
508- expect ( vars [ 0 ] . get ( ) ) . toEqual ( { id : 'b' , enabled : true } ) ;
509-
510- // with path: negative index among matching elements
511- vars = variables ( [ { id : 'a' , enabled : true } , { id : 'b' , enabled : false } , { id : 'c' , enabled : true } ] ) ;
512- Core [ 'find-nth' ] . apply ( [ '-1' , 'enabled' ] , vars , CTX ) ;
513- expect ( vars [ 0 ] . get ( ) ) . toEqual ( { id : 'c' , enabled : true } ) ;
514-
515- // with path: none match → missing
516- vars = variables ( [ { id : 'a' , enabled : false } , { id : 'b' } ] ) ;
517- Core [ 'find-nth' ] . apply ( [ '0' , 'enabled' ] , vars , CTX ) ;
518- expect ( vars [ 0 ] . node . isMissing ( ) ) . toBe ( true ) ;
519-
520- // with path: index out of bounds among matches → missing
521- vars = variables ( [ { id : 'a' , enabled : true } , { id : 'b' , enabled : false } ] ) ;
522- Core [ 'find-nth' ] . apply ( [ '1' , 'enabled' ] , vars , CTX ) ;
523- expect ( vars [ 0 ] . node . isMissing ( ) ) . toBe ( true ) ;
524- } ) ;
525-
526381test ( 'key-by' , ( ) => {
527382 let vars = variables ( [ { id : 1 } ] ) ;
528383 Core [ 'key-by' ] . apply ( [ ] , vars , CTX ) ;
0 commit comments