@@ -34,10 +34,8 @@ function parseComment(text: string): Requirements {
3434 const jsonContent = text
3535 . slice ( 2 , - 2 )
3636 . trim ( )
37- . replaceAll ( / ^ / gm, '"' )
38- . replaceAll ( / : / gm, '":' )
39- . replaceAll ( / $ / gm, "," )
40- . replaceAll ( / , $ / gm, "" ) ;
37+ . replaceAll ( / ^ (? = \w ) / gm, '"' )
38+ . replaceAll ( / : / gm, '":' ) ;
4139 return JSON . parse ( `{${ jsonContent } }` ) ;
4240}
4341
@@ -89,21 +87,26 @@ function buildSimpleCFG(functionNode: Parser.SyntaxNode): CFG {
8987function buildMarkerCFG ( functionNode : Parser . SyntaxNode ) : CFG {
9088 const builder = new CFGBuilder ( { markerPattern } ) ;
9189 return builder . buildCFG ( functionNode ) ;
92-
9390}
9491
95- function pathExists ( graph : MultiDirectedGraph , source : string , target : string ) : boolean {
92+ function pathExists (
93+ graph : MultiDirectedGraph ,
94+ source : string ,
95+ target : string ,
96+ ) : boolean {
9697 let foundTarget = false ;
9798 bfsFromNode ( graph , source , ( node ) => {
9899 foundTarget ||= node == target ;
99100 return foundTarget ;
100- } )
101+ } ) ;
101102 return foundTarget ;
102103}
103104
104105function getMarkerMap ( cfg : CFG ) : Map < string , string > {
105106 const markerMap : Map < string , string > = new Map ( ) ;
106- cfg . graph . forEachNode ( ( node , { markers } ) => { markers ?. forEach ( marker => markerMap . set ( marker , node ) ) } )
107+ cfg . graph . forEachNode ( ( node , { markers } ) => {
108+ markers ?. forEach ( ( marker ) => markerMap . set ( marker , node ) ) ;
109+ } ) ;
107110 return markerMap ;
108111}
109112
@@ -112,7 +115,15 @@ const testMap = new Map(
112115 testFunctions . map ( ( testFunc ) => [ testFunc . name , testFunc ] ) ,
113116) ;
114117const testNames = [ ...testMap . keys ( ) ] ;
115- test . each ( testNames ) ( "Node count for %s" , ( name ) => {
118+
119+ function testsFor ( reqName : string ) : string [ ] {
120+ return testNames . filter ( ( name ) => {
121+ const testFunc = testMap . get ( name ) as TestFunction ;
122+ return Object . hasOwn ( testFunc . reqs , reqName ) ;
123+ } ) ;
124+ }
125+
126+ test . each ( testsFor ( "nodes" ) ) ( "Node count for %s" , ( name ) => {
116127 const testFunc = testMap . get ( name ) as TestFunction ;
117128 expect ( testFunc ) . toBeDefined ( ) ;
118129
@@ -122,7 +133,7 @@ test.each(testNames)("Node count for %s", (name) => {
122133 }
123134} ) ;
124135
125- test . each ( testNames ) ( "Reachability for %s" , ( name ) => {
136+ test . each ( testsFor ( "reaches" ) ) ( "Reachability for %s" , ( name ) => {
126137 const testFunc = testMap . get ( name ) as TestFunction ;
127138 expect ( testFunc ) . toBeDefined ( ) ;
128139
@@ -134,8 +145,12 @@ test.each(testNames)("Reachability for %s", (name) => {
134145 if ( node ) {
135146 return node ;
136147 }
137- throw new Error ( `No node found for marker ${ marker } ` )
138- }
139- testFunc . reqs . reaches . forEach ( ( [ source , target ] ) => expect ( pathExists ( cfg . graph , getNode ( source ) , getNode ( target ) ) ) . toBe ( true ) )
148+ throw new Error ( `No node found for marker ${ marker } ` ) ;
149+ } ;
150+ testFunc . reqs . reaches . forEach ( ( [ source , target ] ) =>
151+ expect ( pathExists ( cfg . graph , getNode ( source ) , getNode ( target ) ) ) . toBe (
152+ true ,
153+ ) ,
154+ ) ;
140155 }
141156} ) ;
0 commit comments