Skip to content

Commit bab5ab5

Browse files
committed
Fix cleanup function
1 parent 0ceb01b commit bab5ab5

File tree

2 files changed

+99
-1
lines changed

2 files changed

+99
-1
lines changed

pkg/frontend/vcs/source/find_java.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func convertJavaFunctionNameToPath(functionName string) string {
2121
// pos to cut from
2222
pos := -1
2323
updatePos := func(v int) {
24-
if v != -1 {
24+
if v == -1 {
2525
return
2626
}
2727
if pos == -1 || pos > v {
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package source
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func Test_convertJavaFunctionNameToPath(t *testing.T) {
10+
tests := []struct {
11+
name string
12+
functionName string
13+
expected string
14+
}{
15+
{
16+
name: "simple class name",
17+
functionName: "com/example/MyClass",
18+
expected: "com/example/MyClass.java",
19+
},
20+
{
21+
name: "class with method",
22+
functionName: "com/example/MyClass.myMethod",
23+
expected: "com/example/MyClass.java",
24+
},
25+
{
26+
name: "inner class with dollar sign",
27+
functionName: "com/example/OuterClass$InnerClass",
28+
expected: "com/example/OuterClass.java",
29+
},
30+
{
31+
name: "inner class with method",
32+
functionName: "com/example/OuterClass$InnerClass.method",
33+
expected: "com/example/OuterClass.java",
34+
},
35+
{
36+
name: "lambda or anonymous class",
37+
functionName: "com/example/MyClass$1",
38+
expected: "com/example/MyClass.java",
39+
},
40+
{
41+
name: "nested inner class",
42+
functionName: "com/example/Outer$Inner$DeepInner",
43+
expected: "com/example/Outer.java",
44+
},
45+
{
46+
name: "method with parameters in name",
47+
functionName: "com/example/MyClass.method.withDots",
48+
expected: "com/example/MyClass.java",
49+
},
50+
{
51+
name: "single segment with method",
52+
functionName: "MyClass.method",
53+
expected: "MyClass.java",
54+
},
55+
{
56+
name: "single segment with inner class",
57+
functionName: "MyClass$Inner",
58+
expected: "MyClass.java",
59+
},
60+
{
61+
name: "no package, just class",
62+
functionName: "MyClass",
63+
expected: "MyClass.java",
64+
},
65+
{
66+
name: "complex nested structure",
67+
functionName: "org/springframework/boot/Application$Config$Bean.initialize",
68+
expected: "org/springframework/boot/Application.java",
69+
},
70+
{
71+
name: "dollar sign before dot",
72+
functionName: "com/example/Class$Inner.method",
73+
expected: "com/example/Class.java",
74+
},
75+
{
76+
name: "dot before dollar sign",
77+
functionName: "com/example/Class.method$1",
78+
expected: "com/example/Class.java",
79+
},
80+
{
81+
name: "multiple dollar signs",
82+
functionName: "com/example/Outer$Middle$Inner",
83+
expected: "com/example/Outer.java",
84+
},
85+
{
86+
name: "multiple dots",
87+
functionName: "com/example/Class.method.subMethod",
88+
expected: "com/example/Class.java",
89+
},
90+
}
91+
92+
for _, tt := range tests {
93+
t.Run(tt.name, func(t *testing.T) {
94+
result := convertJavaFunctionNameToPath(tt.functionName)
95+
assert.Equal(t, tt.expected, result)
96+
})
97+
}
98+
}

0 commit comments

Comments
 (0)