Skip to content

Commit e10b010

Browse files
committed
test(kotlin): add test for function call
1 parent 31764a3 commit e10b010

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

chapi-ast-kotlin/src/main/kotlin/chapi/ast/kotlinast/KotlinFullIdentListener.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ open class KotlinFullIdentListener(fileName: String) : KotlinBasicIdentListener(
3030
val functionStart = result.groups[1]!!.range.first
3131
val nodeName = matchedExpression.substring(0, maxOf(functionStart - matchedStart - 1, 0))
3232

33+
val callType = if (functionName[0].isUpperCase()) CallType.CREATOR else CallType.FUNCTION
3334
return CodeCall(
34-
Type = if (functionName[0].isUpperCase()) CallType.CREATOR else CallType.FUNCTION,
35+
Type = callType,
3536
NodeName = nodeName,
3637
FunctionName = functionName,
3738
Parameters = parameters,

chapi-ast-kotlin/src/test/kotlin/chapi/ast/kotlinast/KotlinFullIdentListenerTest.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ internal class KotlinFullIdentListenerTest {
1010
KotlinAnalyser().analysis(code, fileName, AnalysisMode.Full)
1111

1212
@Nested
13-
inner class Calls {
13+
inner class should_analysis_hello_world {
1414
@Test
1515
internal fun `should identify function call of individual function`() {
1616
val code = """
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package chapi.ast.kotlinast
2+
3+
import chapi.parser.ParseMode
4+
import org.junit.jupiter.api.Test
5+
6+
class KotlinFunctionCallTest {
7+
@Test
8+
fun should_identify_constructor_call() {
9+
val code = """
10+
class A {
11+
12+
}
13+
14+
fun foo() {
15+
val a = A()
16+
}
17+
""".trimIndent()
18+
19+
val codeContainer = KotlinAnalyser().analysis(code, "Test.kt", ParseMode.Full)
20+
val dataStructures = codeContainer.DataStructures.filter { it.NodeName == "TestKt" }
21+
val functionCall = dataStructures[0].Functions[0].FunctionCalls[0]
22+
23+
assert(functionCall.FunctionName == "A")
24+
}
25+
}

0 commit comments

Comments
 (0)