@@ -232,7 +232,128 @@ countdown(5)
232232 ] as PartialAnnotationComment [ ] )
233233 } )
234234
235- // TODO: We also need to implement and test the `[!ignore-tags]` logic
235+ describe ( 'Supports ignoring unwanted annotations' , ( ) => {
236+ test ( '[!ignore-tags] ignores all annotations on the next line' , ( ) => {
237+ const lines = [
238+ `// [!before] This is before any ignores` ,
239+ `console.log('Some code')` ,
240+ `// [!ignore-tags]` ,
241+ `testCode() // [!ignored] This should not be parsed` ,
242+ `// [!after] This should be parsed again` ,
243+ ]
244+ const comments = getComments ( lines . join ( '\n' ) )
245+ expect ( comments ) . toHaveLength ( 2 )
246+ expect ( comments ) . toMatchObject ( [
247+ {
248+ tag : { name : 'before' , targetSearchQuery : undefined } ,
249+ contents : [ `This is before any ignores` ] ,
250+ } ,
251+ {
252+ tag : { name : 'after' , targetSearchQuery : undefined } ,
253+ contents : [ `This should be parsed again` ] ,
254+ } ,
255+ ] as PartialAnnotationComment [ ] )
256+ } )
257+ test ( '[!ignore-tags:2] ignores the next two lines' , ( ) => {
258+ const lines = [
259+ `// [!before] This is before any ignores` ,
260+ `console.log('Some code')` ,
261+ `// [!ignore-tags:2]` ,
262+ `testCode() // [!ignored] This should not be parsed` ,
263+ `// [!ignored] Still ignored` ,
264+ `// [!after] This should be parsed again` ,
265+ ]
266+ const comments = getComments ( lines . join ( '\n' ) )
267+ expect ( comments ) . toHaveLength ( 2 )
268+ expect ( comments ) . toMatchObject ( [
269+ {
270+ tag : { name : 'before' , targetSearchQuery : undefined } ,
271+ contents : [ `This is before any ignores` ] ,
272+ } ,
273+ {
274+ tag : { name : 'after' , targetSearchQuery : undefined } ,
275+ contents : [ `This should be parsed again` ] ,
276+ } ,
277+ ] as PartialAnnotationComment [ ] )
278+ } )
279+ test ( '[!ignore-tags:note] ignores the next occurrence of "note"' , ( ) => {
280+ const lines = [
281+ `// [!before] This is before any ignores` ,
282+ `// [!ignore-tags:note]` ,
283+ `console.log('Some code')` ,
284+ `testCode() // [!note] This should not be parsed` ,
285+ `// [!note] This should be parsed again` ,
286+ ]
287+ const comments = getComments ( lines . join ( '\n' ) )
288+ expect ( comments ) . toHaveLength ( 2 )
289+ expect ( comments ) . toMatchObject ( [
290+ {
291+ tag : { name : 'before' , targetSearchQuery : undefined } ,
292+ contents : [ `This is before any ignores` ] ,
293+ } ,
294+ {
295+ tag : { name : 'note' , targetSearchQuery : undefined } ,
296+ contents : [ `This should be parsed again` ] ,
297+ } ,
298+ ] as PartialAnnotationComment [ ] )
299+ } )
300+ test ( '[!ignore-tags:note,ins:3] ignores the next 3 occurrences of "note" and "ins"' , ( ) => {
301+ const lines = [
302+ `// [!before] This is before any ignores` ,
303+ `// [!ignore-tags:note,ins:3]` ,
304+ `console.log('Some code') // [!ins]` ,
305+ `testCode() // [!note] This should not be parsed` ,
306+ `// [!ins] // [!note] Still ignored` ,
307+ `// [!ins] // [!note] Still ignored` ,
308+ `console.log('Test') // [!ins]` ,
309+ `// [!note] This should be parsed again` ,
310+ ]
311+ const comments = getComments ( lines . join ( '\n' ) )
312+ expect ( comments ) . toHaveLength ( 3 )
313+ expect ( comments ) . toMatchObject ( [
314+ {
315+ tag : { name : 'before' , targetSearchQuery : undefined } ,
316+ contents : [ `This is before any ignores` ] ,
317+ } ,
318+ {
319+ tag : { name : 'ins' , targetSearchQuery : undefined } ,
320+ contents : [ ] ,
321+ } ,
322+ {
323+ tag : { name : 'note' , targetSearchQuery : undefined } ,
324+ contents : [ `This should be parsed again` ] ,
325+ } ,
326+ ] as PartialAnnotationComment [ ] )
327+ } )
328+ test ( 'Ignores work in multi-line comments' , ( ) => {
329+ const lines = [
330+ `/*` ,
331+ ` [!before] This is before any ignores` ,
332+ ` [!ignore-tags]` ,
333+ ` [!note] This should not be parsed` ,
334+ ` [!note] This should be parsed again` ,
335+ `*/` ,
336+ `console.log('Some code')` ,
337+ `testCode() // [!ins]` ,
338+ ]
339+ const comments = getComments ( lines . join ( '\n' ) )
340+ expect ( comments ) . toHaveLength ( 3 )
341+ expect ( comments ) . toMatchObject ( [
342+ {
343+ tag : { name : 'before' , targetSearchQuery : undefined } ,
344+ contents : [ `This is before any ignores` ] ,
345+ } ,
346+ {
347+ tag : { name : 'note' , targetSearchQuery : undefined } ,
348+ contents : [ `This should be parsed again` ] ,
349+ } ,
350+ {
351+ tag : { name : 'ins' , targetSearchQuery : undefined } ,
352+ contents : [ ] ,
353+ } ,
354+ ] as PartialAnnotationComment [ ] )
355+ } )
356+ } )
236357
237358 function getComments ( code : string ) {
238359 const codeLines = splitCodeLines ( code )
0 commit comments