Skip to content

Commit

Permalink
Improved tests and some comments added
Browse files Browse the repository at this point in the history
  • Loading branch information
volivan239 committed Oct 25, 2022
1 parent a3538da commit cfe5932
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package org.utbot.examples.codegen
import org.junit.jupiter.api.Test
import org.utbot.testcheckers.eq
import org.utbot.tests.infrastructure.UtValueTestCaseChecker
import kotlin.reflect.KFunction3

@Suppress("UNCHECKED_CAST")
internal class FileWithTopLevelFunctionsTest : UtValueTestCaseChecker(testClass = FileWithTopLevelFunctionsReflectHelper.clazz.kotlin) {
@Test
fun topLevelSumTest() {
Expand All @@ -24,8 +26,11 @@ internal class FileWithTopLevelFunctionsTest : UtValueTestCaseChecker(testClass
@Test
fun extensionOnCustomClassTest() {
check(
CustomClass::extensionOnCustomClass,
eq(3),
// NB: cast is important here because we need to treat receiver as an argument to be able to check its content in matchers
CustomClass::extensionOnCustomClass as KFunction3<*, CustomClass, CustomClass, Boolean>,
eq(2),
{ receiver, argument, result -> receiver === argument && result == true },
{ receiver, argument, result -> receiver !== argument && result == false },
additionalDependencies = dependenciesForClassExtensions
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ internal class CgKotlinRenderer(context: CgRendererContext, printer: CgPrinter =
override val langPackage: String = "kotlin"

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

override fun visit(element: AbstractCgClass<*>) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
package org.utbot.examples.codegen

// TODO: currently we can't properly handle properties in constructors, change CustomClass to data class after that is fixed
class CustomClass {
var x: Int = 0
var y: Int = 0

fun f(): Int {
return 0
}
}
class CustomClass

fun topLevelSum(a: Int, b: Int): Int {
return a + b
Expand All @@ -19,5 +11,5 @@ fun Int.extensionOnBasicType(other: Int): Int {
}

fun CustomClass.extensionOnCustomClass(other: CustomClass): Boolean {
return x >= other.x && y >= other.y
return this === other
}

0 comments on commit cfe5932

Please sign in to comment.