@@ -67,6 +67,22 @@ describe("Go", () => {
67
67
const func = funcIterator . next ( ) . value ;
68
68
expect ( extractFunctionName ( func , "Go" ) ) . toBe ( "outer" ) ;
69
69
} ) ;
70
+
71
+ test ( "nested short var" , ( ) => {
72
+ const code = `func main() {
73
+ \tvar x = func() {
74
+ \t\ty := func() {}
75
+ \t\ty()
76
+ \t}
77
+ \tx()
78
+ }` ;
79
+ const funcIterator = iterFunctions ( code , "Go" ) ;
80
+ const foundNames = [ ...funcIterator ] . map ( ( func ) =>
81
+ extractFunctionName ( func , "Go" ) ,
82
+ ) ;
83
+ const expectedNames = [ "main" , "x" , "y" ] ;
84
+ expect ( foundNames ) . toContainEqual ( expectedNames ) ;
85
+ } ) ;
70
86
} ) ;
71
87
72
88
// C Tests
@@ -140,6 +156,33 @@ describe("C++", () => {
140
156
const func = funcIterator . next ( ) . value ;
141
157
expect ( extractFunctionName ( func , "C++" ) ) . toBe ( "speak" ) ;
142
158
} ) ;
159
+
160
+ test ( "class nested in function" , ( ) => {
161
+ const code = `
162
+ int square(int num) {
163
+ class X {
164
+ ~X() {};
165
+ };
166
+ return num * num;
167
+ }` ;
168
+ const funcIterator = iterFunctions ( code , "C++" ) ;
169
+ const func = funcIterator . next ( ) . value ;
170
+ expect ( extractFunctionName ( func , "C++" ) ) . toBe ( "square" ) ;
171
+ } ) ;
172
+
173
+ test ( "anynomous lambda inside named lambda" , ( ) => {
174
+ const code = `void f() {
175
+ auto my_func = [](){
176
+ [](){}();
177
+ };
178
+ }` ;
179
+ const funcIterator = iterFunctions ( code , "C++" ) ;
180
+ const foundNames = [ ...funcIterator ] . map ( ( func ) =>
181
+ extractFunctionName ( func , "C++" ) ,
182
+ ) ;
183
+ const expectedNames = [ "f" , "my_func" , "<anonymous>" ] ;
184
+ expect ( foundNames ) . toContainEqual ( expectedNames ) ;
185
+ } ) ;
143
186
} ) ;
144
187
145
188
// Python Tests
@@ -241,4 +284,23 @@ describe("TypeScript", () => {
241
284
const func = funcIterator . next ( ) . value ;
242
285
expect ( extractFunctionName ( func , "TypeScript" ) ) . toBe ( "iterTestFunctions" ) ;
243
286
} ) ;
287
+ test ( "var arrow function" , ( ) => {
288
+ const code = "var name = ()=>{};" ;
289
+ const funcIterator = iterFunctions ( code , "TypeScript" ) ;
290
+ const func = funcIterator . next ( ) . value ;
291
+ expect ( extractFunctionName ( func , "TypeScript" ) ) . toBe ( "name" ) ;
292
+ } ) ;
293
+ test ( "global arrow function" , ( ) => {
294
+ const code = "name = ()=>{};" ;
295
+ const funcIterator = iterFunctions ( code , "TypeScript" ) ;
296
+ const func = funcIterator . next ( ) . value ;
297
+ expect ( extractFunctionName ( func , "TypeScript" ) ) . toBe ( "name" ) ;
298
+ } ) ;
299
+
300
+ test ( "constant in anonymous arrow function" , ( ) => {
301
+ const code = "()=>{ const x = 2; };" ;
302
+ const funcIterator = iterFunctions ( code , "TypeScript" ) ;
303
+ const func = funcIterator . next ( ) . value ;
304
+ expect ( extractFunctionName ( func , "TypeScript" ) ) . toBe ( "<anonymous>" ) ;
305
+ } ) ;
244
306
} ) ;
0 commit comments