@@ -20,6 +20,7 @@ import {
2020} from '../src-js/plugins/tokens.js' ;
2121import { resetSourceAndAst } from '../src-js/plugins/source_code.js' ;
2222import type { Node } from '../src-js/plugins/types.js' ;
23+ import type { BinaryExpression } from '../src-js/generated/types.js' ;
2324
2425// Source text used for most tests
2526const SOURCE_TEXT = '/*A*/var answer/*B*/=/*C*/a/*D*/* b/*E*///F\n call();\n/*Z*/' ;
@@ -50,8 +51,13 @@ beforeEach(() => {
5051// https://eslint.org/blog/2025/10/whats-coming-in-eslint-10.0.0/#updates-to-program-ast-node-range-coverage
5152// https://github.com/typescript-eslint/typescript-eslint/issues/11026#issuecomment-3421887632
5253const Program = { range : [ 5 , 55 ] } as Node ;
53- const BinaryExpression = { range : [ 26 , 35 ] } as Node ;
54+ const BinaryExpression = {
55+ range : [ 26 , 35 ] ,
56+ left : { range : [ 26 , 27 ] } as Node ,
57+ right : { range : [ 34 , 35 ] } as Node ,
58+ } as BinaryExpression ;
5459const VariableDeclaratorIdentifier = { range : [ 9 , 15 ] } as Node ;
60+ const CallExpression = { range : [ 48 , 54 ] } as Node ;
5561
5662// https://github.com/eslint/eslint/blob/v9.39.1/tests/lib/languages/js/source-code/token-store.js#L62
5763describe ( 'when calling getTokens' , ( ) => {
@@ -734,11 +740,62 @@ describe('when calling getFirstTokenBetween', () => {
734740 getFirstTokenBetween ;
735741} ) ;
736742
743+ // https://github.com/eslint/eslint/blob/v9.39.1/tests/lib/languages/js/source-code/token-store.js#L1298-L1382
737744describe ( 'when calling getLastTokensBetween' , ( ) => {
738- /* oxlint-disable-next-line no-disabled-tests expect-expect */
739- it ( 'is to be implemented' ) ;
740- /* oxlint-disable-next-line no-unused-expressions */
741- getLastTokensBetween ;
745+ it ( 'should retrieve zero tokens between adjacent nodes' , ( ) => {
746+ expect ( getLastTokensBetween ( BinaryExpression , CallExpression ) . map ( ( token ) => token . value ) ) . toEqual ( [ ] ) ;
747+ } ) ;
748+
749+ it ( 'should retrieve multiple tokens between non-adjacent nodes with count option' , ( ) => {
750+ expect (
751+ getLastTokensBetween ( VariableDeclaratorIdentifier , BinaryExpression . right , 2 ) . map ( ( token ) => token . value ) ,
752+ ) . toEqual ( [ 'a' , '*' ] ) ;
753+ expect (
754+ getLastTokensBetween ( VariableDeclaratorIdentifier , BinaryExpression . right , { count : 2 } ) . map (
755+ ( token ) => token . value ,
756+ ) ,
757+ ) . toEqual ( [ 'a' , '*' ] ) ;
758+ } ) ;
759+
760+ it ( 'should retrieve matched tokens between non-adjacent nodes with filter option' , ( ) => {
761+ expect (
762+ getLastTokensBetween ( VariableDeclaratorIdentifier , BinaryExpression . right , {
763+ filter : ( t ) => t . type !== 'Punctuator' ,
764+ } ) . map ( ( token ) => token . value ) ,
765+ ) . toEqual ( [ 'a' ] ) ;
766+ } ) ;
767+
768+ it ( 'should retrieve all tokens between non-adjacent nodes with empty object option' , ( ) => {
769+ expect (
770+ getLastTokensBetween ( VariableDeclaratorIdentifier , BinaryExpression . right , { } ) . map ( ( token ) => token . value ) ,
771+ ) . toEqual ( [ '=' , 'a' , '*' ] ) ;
772+ } ) ;
773+
774+ it ( 'should retrieve all tokens and comments between non-adjacent nodes with includeComments option' , ( ) => {
775+ expect (
776+ getLastTokensBetween ( VariableDeclaratorIdentifier , BinaryExpression . right , { includeComments : true } ) . map (
777+ ( token ) => token . value ,
778+ ) ,
779+ ) . toEqual ( [ 'B' , '=' , 'C' , 'a' , 'D' , '*' ] ) ;
780+ } ) ;
781+
782+ it ( 'should retrieve multiple tokens between non-adjacent nodes with includeComments and count options' , ( ) => {
783+ expect (
784+ getLastTokensBetween ( VariableDeclaratorIdentifier , BinaryExpression . right , {
785+ includeComments : true ,
786+ count : 3 ,
787+ } ) . map ( ( token ) => token . value ) ,
788+ ) . toEqual ( [ 'a' , 'D' , '*' ] ) ;
789+ } ) ;
790+
791+ it ( 'should retrieve multiple tokens and comments between non-adjacent nodes with includeComments and filter options' , ( ) => {
792+ expect (
793+ getLastTokensBetween ( VariableDeclaratorIdentifier , BinaryExpression . right , {
794+ includeComments : true ,
795+ filter : ( t ) => t . type !== 'Punctuator' ,
796+ } ) . map ( ( token ) => token . value ) ,
797+ ) . toEqual ( [ 'B' , 'C' , 'a' , 'D' ] ) ;
798+ } ) ;
742799} ) ;
743800
744801describe ( 'when calling getLastTokenBetween' , ( ) => {
0 commit comments