@@ -1354,6 +1354,46 @@ describe('StrNode', () => {
1354
1354
} ) ;
1355
1355
} ) ;
1356
1356
1357
+ describe ( '.prevId()' , ( ) => {
1358
+ test ( 'can iterate through IDs in reverse' , ( ) => {
1359
+ const type = new StrNode ( ts ( 1 , 1 ) ) ;
1360
+ type . ins ( ts ( 1 , 1 ) , ts ( 1 , 2 ) , '123456789' ) ;
1361
+ type . ins ( ts ( 1 , 4 ) , ts ( 2 , 5 ) , 'xxx' ) ;
1362
+ type . ins ( ts ( 1 , 7 ) , ts ( 3 , 5 ) , 'yyy' ) ;
1363
+ let id = ts ( 1 , 10 ) ;
1364
+ id = type . prevId ( id ) ! ;
1365
+ expect ( id ) . toStrictEqual ( ts ( 1 , 9 ) ) ;
1366
+ id = type . prevId ( id ) ! ;
1367
+ expect ( id ) . toStrictEqual ( ts ( 1 , 8 ) ) ;
1368
+ id = type . prevId ( id ) ! ;
1369
+ expect ( id ) . toStrictEqual ( ts ( 3 , 7 ) ) ;
1370
+ id = type . prevId ( id ) ! ;
1371
+ expect ( id ) . toStrictEqual ( ts ( 3 , 6 ) ) ;
1372
+ id = type . prevId ( id ) ! ;
1373
+ expect ( id ) . toStrictEqual ( ts ( 3 , 5 ) ) ;
1374
+ id = type . prevId ( id ) ! ;
1375
+ expect ( id ) . toStrictEqual ( ts ( 1 , 7 ) ) ;
1376
+ id = type . prevId ( id ) ! ;
1377
+ expect ( id ) . toStrictEqual ( ts ( 1 , 6 ) ) ;
1378
+ id = type . prevId ( id ) ! ;
1379
+ expect ( id ) . toStrictEqual ( ts ( 1 , 5 ) ) ;
1380
+ id = type . prevId ( id ) ! ;
1381
+ expect ( id ) . toStrictEqual ( ts ( 2 , 7 ) ) ;
1382
+ id = type . prevId ( id ) ! ;
1383
+ expect ( id ) . toStrictEqual ( ts ( 2 , 6 ) ) ;
1384
+ id = type . prevId ( id ) ! ;
1385
+ expect ( id ) . toStrictEqual ( ts ( 2 , 5 ) ) ;
1386
+ id = type . prevId ( id ) ! ;
1387
+ expect ( id ) . toStrictEqual ( ts ( 1 , 4 ) ) ;
1388
+ id = type . prevId ( id ) ! ;
1389
+ expect ( id ) . toStrictEqual ( ts ( 1 , 3 ) ) ;
1390
+ id = type . prevId ( id ) ! ;
1391
+ expect ( id ) . toStrictEqual ( ts ( 1 , 2 ) ) ;
1392
+ id = type . prevId ( id ) ! ;
1393
+ expect ( id ) . toBe ( undefined ) ;
1394
+ } ) ;
1395
+ } ) ;
1396
+
1357
1397
describe ( 'export / import' , ( ) => {
1358
1398
type Entry = [ ITimestampStruct , number , string ] ;
1359
1399
const exp = ( type : StrNode ) => {
0 commit comments