@@ -60,7 +60,7 @@ const VariableDeclaration = { range: [5, 35] } as Node;
6060const VariableDeclaratorIdentifier = { range : [ 9 , 15 ] } as Node ;
6161const CallExpression = { range : [ 48 , 54 ] } as Node ;
6262
63- // https://github.com/eslint/eslint/blob/v9.39.1/tests/lib/languages/js/source-code/token-store.js#L62
63+ // https://github.com/eslint/eslint/blob/v9.39.1/tests/lib/languages/js/source-code/token-store.js#L62-L155
6464describe ( "when calling getTokens" , ( ) => {
6565 it ( "should retrieve all tokens for root node" , ( ) => {
6666 expect ( getTokens ( Program ) . map ( ( token ) => token . value ) ) . toEqual ( [
@@ -164,7 +164,7 @@ describe("when calling getTokens", () => {
164164 } ) ;
165165} ) ;
166166
167- // https://github.com/eslint/eslint/blob/v9.39.1/tests/lib/languages/js/source-code/token-store.js#L157
167+ // https://github.com/eslint/eslint/blob/v9.39.1/tests/lib/languages/js/source-code/token-store.js#L157-L236
168168describe ( "when calling getTokensBefore" , ( ) => {
169169 it ( "should retrieve zero tokens before a node" , ( ) => {
170170 expect ( getTokensBefore ( BinaryExpression , 0 ) . map ( ( token ) => token . value ) ) . toEqual ( [ ] ) ;
@@ -253,6 +253,7 @@ describe("when calling getTokensBefore", () => {
253253 } ) ;
254254} ) ;
255255
256+ // https://github.com/eslint/eslint/blob/v9.39.1/tests/lib/languages/js/source-code/token-store.js#L238-L361
256257describe ( "when calling getTokenBefore" , ( ) => {
257258 it ( "should retrieve one token before a node" , ( ) => {
258259 expect ( getTokenBefore ( BinaryExpression ) ! . value ) . toBe ( "=" ) ;
@@ -330,7 +331,7 @@ describe("when calling getTokenBefore", () => {
330331 } ) ;
331332} ) ;
332333
333- // https://github.com/eslint/eslint/blob/v9.39.1/tests/lib/languages/js/source-code/token-store.js#L461
334+ // https://github.com/eslint/eslint/blob/v9.39.1/tests/lib/languages/js/source-code/token-store.js#L363-L459
334335describe ( "when calling getTokenAfter" , ( ) => {
335336 it ( "should retrieve one token after a node" , ( ) => {
336337 expect ( getTokenAfter ( VariableDeclaratorIdentifier ) ! . value ) . toBe ( "=" ) ;
@@ -419,7 +420,7 @@ describe("when calling getTokenAfter", () => {
419420 } ) ;
420421} ) ;
421422
422- // https://github.com/eslint/eslint/blob/v9.39.1/tests/lib/languages/js/source-code/token-store.js#L363-L459
423+ // https://github.com/eslint/eslint/blob/v9.39.1/tests/lib/languages/js/source-code/token-store.js#L461-L592
423424describe ( "when calling getTokensAfter" , ( ) => {
424425 it ( "should retrieve zero tokens after a node" , ( ) => {
425426 expect ( getTokensAfter ( VariableDeclaratorIdentifier , 0 ) . map ( ( token ) => token . value ) ) . toEqual ( [ ] ) ;
@@ -919,79 +920,6 @@ describe("when calling getLastToken", () => {
919920 } ) ;
920921} ) ;
921922
922- // https://github.com/eslint/eslint/blob/v9.39.1/tests/lib/languages/js/source-code/token-store.js#L1384-L1487
923- describe ( "when calling getLastTokenBetween" , ( ) => {
924- it ( "should return null between adjacent nodes" , ( ) => {
925- expect ( getLastTokenBetween ( BinaryExpression , CallExpression ) ) . toBeNull ( ) ;
926- } ) ;
927-
928- it ( "should retrieve the last token between non-adjacent nodes with count option" , ( ) => {
929- expect ( getLastTokenBetween ( VariableDeclaratorIdentifier , BinaryExpression . right ) ! . value ) . toBe (
930- "*" ,
931- ) ;
932- } ) ;
933-
934- it ( "should retrieve one token between non-adjacent nodes with skip option" , ( ) => {
935- expect (
936- getLastTokenBetween ( VariableDeclaratorIdentifier , BinaryExpression . right , 1 ) ! . value ,
937- ) . toBe ( "a" ) ;
938- expect (
939- getLastTokenBetween ( VariableDeclaratorIdentifier , BinaryExpression . right , { skip : 2 } ) ! . value ,
940- ) . toBe ( "=" ) ;
941- } ) ;
942-
943- it ( "should return null if it's skipped beyond the right token" , ( ) => {
944- expect (
945- getLastTokenBetween ( VariableDeclaratorIdentifier , BinaryExpression . right , { skip : 3 } ) ,
946- ) . toBeNull ( ) ;
947- expect (
948- getLastTokenBetween ( VariableDeclaratorIdentifier , BinaryExpression . right , { skip : 4 } ) ,
949- ) . toBeNull ( ) ;
950- } ) ;
951-
952- it ( "should retrieve the last matched token between non-adjacent nodes with filter option" , ( ) => {
953- expect (
954- getLastTokenBetween (
955- VariableDeclaratorIdentifier ,
956- BinaryExpression . right ,
957- ( t ) => t . type !== "Identifier" ,
958- ) ! . value ,
959- ) . toBe ( "*" ) ;
960- expect (
961- getLastTokenBetween ( VariableDeclaratorIdentifier , BinaryExpression . right , {
962- filter : ( t ) => t . type !== "Identifier" ,
963- } ) ! . value ,
964- ) . toBe ( "*" ) ;
965- } ) ;
966-
967- it ( "should retrieve last token or comment between non-adjacent nodes with includeComments option" , ( ) => {
968- expect (
969- getLastTokenBetween ( VariableDeclaratorIdentifier , BinaryExpression . right , {
970- includeComments : true ,
971- } ) ! . value ,
972- ) . toBe ( "*" ) ;
973- } ) ;
974-
975- it ( "should retrieve last token or comment between non-adjacent nodes with includeComments and skip options" , ( ) => {
976- expect (
977- getLastTokenBetween ( VariableDeclaratorIdentifier , BinaryExpression . right , {
978- includeComments : true ,
979- skip : 1 ,
980- } ) ! . value ,
981- ) . toBe ( "D" ) ;
982- } ) ;
983-
984- it ( "should retrieve last token or comment between non-adjacent nodes with includeComments and skip and filter options" , ( ) => {
985- expect (
986- getLastTokenBetween ( VariableDeclaratorIdentifier , BinaryExpression . right , {
987- includeComments : true ,
988- skip : 1 ,
989- filter : ( t ) => t . type !== "Punctuator" ,
990- } ) ! . value ,
991- ) . toBe ( "a" ) ;
992- } ) ;
993- } ) ;
994-
995923// https://github.com/eslint/eslint/blob/v9.39.1/tests/lib/languages/js/source-code/token-store.js#L1107-L1191
996924describe ( "when calling getFirstTokensBetween" , ( ) => {
997925 it ( "should retrieve zero tokens between adjacent nodes" , ( ) => {
@@ -1187,11 +1115,77 @@ describe("when calling getLastTokensBetween", () => {
11871115 } ) ;
11881116} ) ;
11891117
1118+ // https://github.com/eslint/eslint/blob/v9.39.1/tests/lib/languages/js/source-code/token-store.js#L1384-L1487
11901119describe ( "when calling getLastTokenBetween" , ( ) => {
1191- /* oxlint-disable-next-line no-disabled-tests expect-expect */
1192- it ( "is to be implemented" ) ;
1193- /* oxlint-disable-next-line no-unused-expressions */
1194- getLastTokenBetween ;
1120+ it ( "should return null between adjacent nodes" , ( ) => {
1121+ expect ( getLastTokenBetween ( BinaryExpression , CallExpression ) ) . toBeNull ( ) ;
1122+ } ) ;
1123+
1124+ it ( "should retrieve the last token between non-adjacent nodes with count option" , ( ) => {
1125+ expect ( getLastTokenBetween ( VariableDeclaratorIdentifier , BinaryExpression . right ) ! . value ) . toBe (
1126+ "*" ,
1127+ ) ;
1128+ } ) ;
1129+
1130+ it ( "should retrieve one token between non-adjacent nodes with skip option" , ( ) => {
1131+ expect (
1132+ getLastTokenBetween ( VariableDeclaratorIdentifier , BinaryExpression . right , 1 ) ! . value ,
1133+ ) . toBe ( "a" ) ;
1134+ expect (
1135+ getLastTokenBetween ( VariableDeclaratorIdentifier , BinaryExpression . right , { skip : 2 } ) ! . value ,
1136+ ) . toBe ( "=" ) ;
1137+ } ) ;
1138+
1139+ it ( "should return null if it's skipped beyond the right token" , ( ) => {
1140+ expect (
1141+ getLastTokenBetween ( VariableDeclaratorIdentifier , BinaryExpression . right , { skip : 3 } ) ,
1142+ ) . toBeNull ( ) ;
1143+ expect (
1144+ getLastTokenBetween ( VariableDeclaratorIdentifier , BinaryExpression . right , { skip : 4 } ) ,
1145+ ) . toBeNull ( ) ;
1146+ } ) ;
1147+
1148+ it ( "should retrieve the last matched token between non-adjacent nodes with filter option" , ( ) => {
1149+ expect (
1150+ getLastTokenBetween (
1151+ VariableDeclaratorIdentifier ,
1152+ BinaryExpression . right ,
1153+ ( t ) => t . type !== "Identifier" ,
1154+ ) ! . value ,
1155+ ) . toBe ( "*" ) ;
1156+ expect (
1157+ getLastTokenBetween ( VariableDeclaratorIdentifier , BinaryExpression . right , {
1158+ filter : ( t ) => t . type !== "Identifier" ,
1159+ } ) ! . value ,
1160+ ) . toBe ( "*" ) ;
1161+ } ) ;
1162+
1163+ it ( "should retrieve last token or comment between non-adjacent nodes with includeComments option" , ( ) => {
1164+ expect (
1165+ getLastTokenBetween ( VariableDeclaratorIdentifier , BinaryExpression . right , {
1166+ includeComments : true ,
1167+ } ) ! . value ,
1168+ ) . toBe ( "*" ) ;
1169+ } ) ;
1170+
1171+ it ( "should retrieve last token or comment between non-adjacent nodes with includeComments and skip options" , ( ) => {
1172+ expect (
1173+ getLastTokenBetween ( VariableDeclaratorIdentifier , BinaryExpression . right , {
1174+ includeComments : true ,
1175+ skip : 1 ,
1176+ } ) ! . value ,
1177+ ) . toBe ( "D" ) ;
1178+ } ) ;
1179+
1180+ it ( "should retrieve last token or comment between non-adjacent nodes with includeComments and skip and filter options" , ( ) => {
1181+ expect (
1182+ getLastTokenBetween ( VariableDeclaratorIdentifier , BinaryExpression . right , {
1183+ includeComments : true ,
1184+ skip : 1 ,
1185+ filter : ( t ) => t . type !== "Punctuator" ,
1186+ } ) ! . value ,
1187+ ) . toBe ( "a" ) ;
1188+ } ) ;
11951189} ) ;
11961190
11971191// https://github.com/eslint/eslint/blob/v9.39.1/tests/lib/languages/js/source-code/token-store.js#L1489-L1524
0 commit comments