Skip to content

Commit 421878f

Browse files
committed
Added a few failing tests that should pass.
1 parent fd7aa24 commit 421878f

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

src/test/functionDetails.test.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,22 @@ describe("Go", () => {
6767
const func = funcIterator.next().value;
6868
expect(extractFunctionName(func, "Go")).toBe("outer");
6969
});
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+
});
7086
});
7187

7288
// C Tests
@@ -140,6 +156,33 @@ describe("C++", () => {
140156
const func = funcIterator.next().value;
141157
expect(extractFunctionName(func, "C++")).toBe("speak");
142158
});
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+
});
143186
});
144187

145188
// Python Tests
@@ -241,4 +284,23 @@ describe("TypeScript", () => {
241284
const func = funcIterator.next().value;
242285
expect(extractFunctionName(func, "TypeScript")).toBe("iterTestFunctions");
243286
});
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+
});
244306
});

0 commit comments

Comments
 (0)