Skip to content

Commit cfe5932

Browse files
committed
Improved tests and some comments added
1 parent a3538da commit cfe5932

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/FileWithTopLevelFunctionsTest.kt

+7-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package org.utbot.examples.codegen
33
import org.junit.jupiter.api.Test
44
import org.utbot.testcheckers.eq
55
import org.utbot.tests.infrastructure.UtValueTestCaseChecker
6+
import kotlin.reflect.KFunction3
67

8+
@Suppress("UNCHECKED_CAST")
79
internal class FileWithTopLevelFunctionsTest : UtValueTestCaseChecker(testClass = FileWithTopLevelFunctionsReflectHelper.clazz.kotlin) {
810
@Test
911
fun topLevelSumTest() {
@@ -24,8 +26,11 @@ internal class FileWithTopLevelFunctionsTest : UtValueTestCaseChecker(testClass
2426
@Test
2527
fun extensionOnCustomClassTest() {
2628
check(
27-
CustomClass::extensionOnCustomClass,
28-
eq(3),
29+
// NB: cast is important here because we need to treat receiver as an argument to be able to check its content in matchers
30+
CustomClass::extensionOnCustomClass as KFunction3<*, CustomClass, CustomClass, Boolean>,
31+
eq(2),
32+
{ receiver, argument, result -> receiver === argument && result == true },
33+
{ receiver, argument, result -> receiver !== argument && result == false },
2934
additionalDependencies = dependenciesForClassExtensions
3035
)
3136
}

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/visitor/CgKotlinRenderer.kt

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ internal class CgKotlinRenderer(context: CgRendererContext, printer: CgPrinter =
7474
override val langPackage: String = "kotlin"
7575

7676
override val ClassId.methodsAreAccessibleAsTopLevel: Boolean
77+
// NB: the order of operands is important as `isKotlinFile` uses reflection and thus can't be called on context.generatedClass
7778
get() = (this == context.generatedClass) || isKotlinFile
7879

7980
override fun visit(element: AbstractCgClass<*>) {
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
package org.utbot.examples.codegen
22

3-
// TODO: currently we can't properly handle properties in constructors, change CustomClass to data class after that is fixed
4-
class CustomClass {
5-
var x: Int = 0
6-
var y: Int = 0
7-
8-
fun f(): Int {
9-
return 0
10-
}
11-
}
3+
class CustomClass
124

135
fun topLevelSum(a: Int, b: Int): Int {
146
return a + b
@@ -19,5 +11,5 @@ fun Int.extensionOnBasicType(other: Int): Int {
1911
}
2012

2113
fun CustomClass.extensionOnCustomClass(other: CustomClass): Boolean {
22-
return x >= other.x && y >= other.y
14+
return this === other
2315
}

0 commit comments

Comments
 (0)