-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests for Kotlin top-level functions
- Loading branch information
1 parent
81880d6
commit 00372ae
Showing
5 changed files
with
78 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...ramework-test/src/test/kotlin/org/utbot/examples/codegen/FileWithTopLevelFunctionsTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package org.utbot.examples.codegen | ||
|
||
import org.junit.jupiter.api.Test | ||
import org.utbot.testcheckers.eq | ||
import org.utbot.tests.infrastructure.UtValueTestCaseChecker | ||
|
||
internal class FileWithTopLevelFunctionsTest : UtValueTestCaseChecker(testClass = FileWithTopLevelFunctionsReflectHelper.clazz.kotlin) { | ||
@Test | ||
fun topLevelSumTest() { | ||
check( | ||
::topLevelSum, | ||
eq(1), | ||
) | ||
} | ||
|
||
@Test | ||
fun extensionOnBasicTypeTest() { | ||
check( | ||
Int::extensionOnBasicType, | ||
eq(1), | ||
) | ||
} | ||
|
||
@Test | ||
fun extensionOnCustomClassTest() { | ||
check( | ||
CustomClass::extensionOnCustomClass, | ||
eq(3), | ||
additionalDependencies = dependenciesForClassExtensions | ||
) | ||
} | ||
|
||
companion object { | ||
// Compilation of extension methods for ref objects produces call to | ||
// `kotlin.jvm.internal.Intrinsics::checkNotNullParameter`, so we need to add it to dependencies | ||
val dependenciesForClassExtensions = arrayOf<Class<*>>(kotlin.jvm.internal.Intrinsics::class.java) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
...mple/src/main/java/org/utbot/examples/codegen/FileWithTopLevelFunctionsReflectHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.utbot.examples.codegen; | ||
|
||
// We can't access FileWithTopLevelFunctionsKt::class from Kotlin, so we use this class to get reflection from Java | ||
public class FileWithTopLevelFunctionsReflectHelper { | ||
static Class<FileWithTopLevelFunctionsKt> clazz = FileWithTopLevelFunctionsKt.class; | ||
} |
23 changes: 23 additions & 0 deletions
23
utbot-sample/src/main/kotlin/org/utbot/examples/codegen/FileWithTopLevelFunctions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
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 | ||
} | ||
} | ||
|
||
fun topLevelSum(a: Int, b: Int): Int { | ||
return a + b | ||
} | ||
|
||
fun Int.extensionOnBasicType(other: Int): Int { | ||
return this + other | ||
} | ||
|
||
fun CustomClass.extensionOnCustomClass(other: CustomClass): Boolean { | ||
return x >= other.x && y >= other.y | ||
} |