@@ -106,4 +106,71 @@ $mOther.key = "value"`;
106106 expect ( assignments [ 0 ] . key ) . toBe ( 'name' ) ;
107107 } ) ;
108108 } ) ;
109+
110+ describe ( 'parseFunctionBoundaries' , ( ) => {
111+ it ( 'should detect function start and end' , ( ) => {
112+ const source = `Func MyFunction()
113+ Local $x = 1
114+ EndFunc` ;
115+ const parser = new MapParser ( source ) ;
116+ const functions = parser . parseFunctionBoundaries ( ) ;
117+
118+ expect ( functions ) . toHaveLength ( 1 ) ;
119+ expect ( functions [ 0 ] ) . toMatchObject ( {
120+ name : 'MyFunction' ,
121+ startLine : 0 ,
122+ endLine : 2 ,
123+ } ) ;
124+ } ) ;
125+
126+ it ( 'should detect multiple functions' , ( ) => {
127+ const source = `Func First()
128+ EndFunc
129+
130+ Func Second()
131+ Local $x = 1
132+ EndFunc` ;
133+ const parser = new MapParser ( source ) ;
134+ const functions = parser . parseFunctionBoundaries ( ) ;
135+
136+ expect ( functions ) . toHaveLength ( 2 ) ;
137+ expect ( functions [ 0 ] . name ) . toBe ( 'First' ) ;
138+ expect ( functions [ 1 ] . name ) . toBe ( 'Second' ) ;
139+ } ) ;
140+
141+ it ( 'should detect function parameters' , ( ) => {
142+ const source = `Func ProcessUser($mUser, $name)
143+ EndFunc` ;
144+ const parser = new MapParser ( source ) ;
145+ const functions = parser . parseFunctionBoundaries ( ) ;
146+
147+ expect ( functions ) . toHaveLength ( 1 ) ;
148+ expect ( functions [ 0 ] . parameters ) . toEqual ( [ '$mUser' , '$name' ] ) ;
149+ } ) ;
150+ } ) ;
151+
152+ describe ( 'getFunctionAtLine' , ( ) => {
153+ it ( 'should return function containing the line' , ( ) => {
154+ const source = `Func MyFunction()
155+ Local $x = 1
156+ EndFunc` ;
157+ const parser = new MapParser ( source ) ;
158+ parser . parseFunctionBoundaries ( ) ;
159+ const func = parser . getFunctionAtLine ( 1 ) ;
160+
161+ expect ( func ) . toBeDefined ( ) ;
162+ expect ( func . name ) . toBe ( 'MyFunction' ) ;
163+ } ) ;
164+
165+ it ( 'should return null for line outside functions' , ( ) => {
166+ const source = `Func MyFunction()
167+ EndFunc
168+ Local $x = 1` ;
169+ const parser = new MapParser ( source ) ;
170+ parser . parseFunctionBoundaries ( ) ;
171+ const func = parser . getFunctionAtLine ( 2 ) ;
172+
173+ expect ( func ) . toBeNull ( ) ;
174+ } ) ;
175+ } ) ;
109176} ) ;
0 commit comments