@@ -495,22 +495,41 @@ describe("__table", () => {
495
495
} ) ;
496
496
497
497
it ( "__table sort" , ( ) => {
498
- const operations1 = { ...EMPTY_TABLE_DATA . operations , sort : [ { column : "a" , direction : "desc" } ] } ;
498
+ const operationsDesc = { ...EMPTY_TABLE_DATA . operations , sort : [ { column : "a" , direction : "desc" } ] } ;
499
499
assert . deepStrictEqual (
500
- __table ( source , operations1 ) ,
500
+ __table ( source , operationsDesc ) ,
501
501
[ { a : 3 , b : 6 , c : 9 } , { a : 2 , b : 4 , c : 6 } , { a : 1 , b : 2 , c : 3 } ]
502
502
) ;
503
+ const operationsAsc = { ...EMPTY_TABLE_DATA . operations , sort : [ { column : "a" , direction : "asc" } ] } ;
504
+ assert . deepStrictEqual (
505
+ __table ( source , operationsAsc ) ,
506
+ [ { a : 1 , b : 2 , c : 3 } , { a : 2 , b : 4 , c : 6 } , { a : 3 , b : 6 , c : 9 } ]
507
+ ) ;
503
508
const sourceExtended = [ ...source , { a : 1 , b : 3 , c : 3 } , { a : 1 , b : 5 , c : 3 } ] ;
504
- const operations2 = {
509
+ const operationsMulti = {
505
510
...EMPTY_TABLE_DATA . operations ,
506
511
sort : [ { column : "a" , direction : "desc" } , { column : "b" , direction : "desc" } ]
507
512
} ;
508
513
assert . deepStrictEqual (
509
- __table ( sourceExtended , operations2 ) ,
514
+ __table ( sourceExtended , operationsMulti ) ,
510
515
[ { a : 3 , b : 6 , c : 9 } , { a : 2 , b : 4 , c : 6 } , { a : 1 , b : 5 , c : 3 } , { a : 1 , b : 3 , c : 3 } , { a : 1 , b : 2 , c : 3 } ]
511
516
) ;
512
517
} ) ;
513
518
519
+ it ( "__table sort missing values" , ( ) => {
520
+ const sourceWithMissing = [ { a : 1 } , { a : null } , { a : undefined } , { a : 10 } , { a : 5 } , { a : NaN } , { a : null } , { a : 20 } ] ;
521
+ const operationsDesc = { ...EMPTY_TABLE_DATA . operations , sort : [ { column : "a" , direction : "desc" } ] } ;
522
+ assert . deepStrictEqual (
523
+ __table ( sourceWithMissing , operationsDesc ) ,
524
+ [ { a : 20 } , { a : 10 } , { a : 5 } , { a : 1 } , { a : null } , { a : undefined } , { a : NaN } , { a : null } ]
525
+ ) ;
526
+ const operationsAsc = { ...EMPTY_TABLE_DATA . operations , sort : [ { column : "a" , direction : "asc" } ] } ;
527
+ assert . deepStrictEqual (
528
+ __table ( sourceWithMissing , operationsAsc ) ,
529
+ [ { a : 1 } , { a : 5 } , { a : 10 } , { a : 20 } , { a : null } , { a : undefined } , { a : NaN } , { a : null } ]
530
+ ) ;
531
+ } ) ;
532
+
514
533
it ( "__table sort does not mutate input" , ( ) => {
515
534
const operations = { ...EMPTY_TABLE_DATA . operations , sort : [ { column : "a" , direction : "desc" } ] } ;
516
535
assert . deepStrictEqual (
0 commit comments