@@ -20,6 +20,11 @@ vi.mock('../src-js/plugins/source_code.ts', async (importOriginal) => {
2020 get sourceText ( ) {
2121 return sourceText ;
2222 } ,
23+ resetSourceAndAst ( ) {
24+ // TODO: refactor this quick fix to get the tests working
25+ original . resetSourceAndAst ( ) ;
26+ sourceText = '/*A*/var answer/*B*/=/*C*/a/*D*/* b/*E*///F\n call();\n/*Z*/' ;
27+ } ,
2328 } ;
2429} ) ;
2530
@@ -305,11 +310,91 @@ describe('when calling getTokenAfter', () => {
305310 getTokenAfter ;
306311} ) ;
307312
313+ // https://github.com/eslint/eslint/blob/v9.39.1/tests/lib/languages/js/source-code/token-store.js#L363-L459
308314describe ( 'when calling getTokensAfter' , ( ) => {
309- /* oxlint-disable-next-line no-disabled-tests expect-expect */
310- it ( 'is to be implemented' ) ;
311- /* oxlint-disable-next-line no-unused-expressions */
312- getTokensAfter ;
315+ it ( 'should retrieve zero tokens after a node' , ( ) => {
316+ assert . deepStrictEqual (
317+ getTokensAfter ( VariableDeclaratorIdentifier , 0 ) . map ( ( token ) => token . value ) ,
318+ [ ] ,
319+ ) ;
320+ } ) ;
321+
322+ it ( 'should retrieve one token after a node' , ( ) => {
323+ assert . deepStrictEqual (
324+ getTokensAfter ( VariableDeclaratorIdentifier , 1 ) . map ( ( token ) => token . value ) ,
325+ [ '=' ] ,
326+ ) ;
327+ } ) ;
328+
329+ it ( 'should retrieve more than one token after a node' , ( ) => {
330+ assert . deepStrictEqual (
331+ getTokensAfter ( VariableDeclaratorIdentifier , 2 ) . map ( ( token ) => token . value ) ,
332+ [ '=' , 'a' ] ,
333+ ) ;
334+ } ) ;
335+
336+ it ( 'should retrieve all tokens after a node' , ( ) => {
337+ assert . deepStrictEqual (
338+ getTokensAfter ( VariableDeclaratorIdentifier , 9e9 ) . map ( ( token ) => token . value ) ,
339+ [ '=' , 'a' , '*' , 'b' , 'call' , '(' , ')' , ';' ] ,
340+ ) ;
341+ } ) ;
342+
343+ it ( 'should retrieve more than one token after a node with count option' , ( ) => {
344+ assert . deepStrictEqual (
345+ getTokensAfter ( VariableDeclaratorIdentifier , { count : 2 } ) . map ( ( token ) => token . value ) ,
346+ [ '=' , 'a' ] ,
347+ ) ;
348+ } ) ;
349+
350+ it ( 'should retrieve all matched tokens after a node with filter option' , ( ) => {
351+ assert . deepStrictEqual (
352+ getTokensAfter ( VariableDeclaratorIdentifier , {
353+ filter : ( t ) => t . type === 'Identifier' ,
354+ } ) . map ( ( token ) => token . value ) ,
355+ [ 'a' , 'b' , 'call' ] ,
356+ ) ;
357+ } ) ;
358+
359+ it ( 'should retrieve matched tokens after a node with count and filter options' , ( ) => {
360+ assert . deepStrictEqual (
361+ getTokensAfter ( VariableDeclaratorIdentifier , {
362+ count : 2 ,
363+ filter : ( t ) => t . type === 'Identifier' ,
364+ } ) . map ( ( token ) => token . value ) ,
365+ [ 'a' , 'b' ] ,
366+ ) ;
367+ } ) ;
368+
369+ it ( 'should retrieve all tokens and comments after a node with includeComments option' , ( ) => {
370+ assert . deepStrictEqual (
371+ getTokensAfter ( VariableDeclaratorIdentifier , {
372+ includeComments : true ,
373+ } ) . map ( ( token ) => token . value ) ,
374+ [ 'B' , '=' , 'C' , 'a' , 'D' , '*' , 'b' , 'E' , 'F' , 'call' , '(' , ')' , ';' , 'Z' ] ,
375+ ) ;
376+ } ) ;
377+
378+ it ( 'should retrieve several tokens and comments after a node with includeComments and count options' , ( ) => {
379+ assert . deepStrictEqual (
380+ getTokensAfter ( VariableDeclaratorIdentifier , {
381+ includeComments : true ,
382+ count : 3 ,
383+ } ) . map ( ( token ) => token . value ) ,
384+ [ 'B' , '=' , 'C' ] ,
385+ ) ;
386+ } ) ;
387+
388+ it ( 'should retrieve matched tokens and comments after a node with includeComments and count and filter options' , ( ) => {
389+ assert . deepStrictEqual (
390+ getTokensAfter ( VariableDeclaratorIdentifier , {
391+ includeComments : true ,
392+ count : 3 ,
393+ filter : ( t ) => t . type . startsWith ( 'Block' ) ,
394+ } ) . map ( ( token ) => token . value ) ,
395+ [ 'B' , 'C' , 'D' ] ,
396+ ) ;
397+ } ) ;
313398} ) ;
314399
315400describe ( 'when calling getFirstTokens' , ( ) => {
0 commit comments