-
Notifications
You must be signed in to change notification settings - Fork 46
Support lambda expressions #825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0f48597
Support anonymous classes
ArsenHD ded6d11
Support lambda expressions
ArsenHD 2d2792d
Add tests on lambdas
ArsenHD 10ec634
Fix review comments
ArsenHD 6bcbdd0
Some fixes
ArsenHD 45b988d
Fix subtype check
ArsenHD 95357a1
Minor fix
ArsenHD 97ba522
Minor fix
ArsenHD 848f660
Fix Kotlin nested class code generation
ArsenHD 105615c
Do not run compilation on Kotlin tests on lambdas due to generics issues
ArsenHD File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
81 changes: 81 additions & 0 deletions
81
utbot-framework-test/src/test/kotlin/org/utbot/examples/lambda/CustomPredicateExampleTest.kt
This file contains hidden or 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,81 @@ | ||
package org.utbot.examples.lambda | ||
|
||
import org.junit.jupiter.api.Test | ||
import org.utbot.framework.plugin.api.CodegenLanguage | ||
import org.utbot.testcheckers.eq | ||
import org.utbot.tests.infrastructure.CodeGeneration | ||
import org.utbot.tests.infrastructure.DoNotCalculate | ||
import org.utbot.tests.infrastructure.UtValueTestCaseChecker | ||
import org.utbot.tests.infrastructure.isException | ||
|
||
class CustomPredicateExampleTest : UtValueTestCaseChecker( | ||
testClass = CustomPredicateExample::class, | ||
languagePipelines = listOf( | ||
CodeGenerationLanguageLastStage(CodegenLanguage.JAVA), | ||
// TODO: https://github.com/UnitTestBot/UTBotJava/issues/88 (generics in Kotlin) | ||
// At the moment, when we create an instance of a functional interface via lambda (through reflection), | ||
// we need to do a type cast (e.g. `obj as Predicate<Int>`), but since generics are not supported yet, | ||
// we use a raw type (e.g. `Predicate`) instead (which is not allowed in Kotlin). | ||
CodeGenerationLanguageLastStage(CodegenLanguage.KOTLIN, CodeGeneration) | ||
) | ||
) { | ||
@Test | ||
fun testNoCapturedValuesPredicateCheck() { | ||
checkWithException( | ||
CustomPredicateExample::noCapturedValuesPredicateCheck, | ||
eq(3), | ||
{ predicate, x, r -> !predicate.test(x) && r.getOrNull() == false }, | ||
{ predicate, x, r -> predicate.test(x) && r.getOrNull() == true }, | ||
{ predicate, _, r -> predicate == null && r.isException<NullPointerException>() }, | ||
coverage = DoNotCalculate | ||
) | ||
} | ||
|
||
@Test | ||
fun testCapturedLocalVariablePredicateCheck() { | ||
checkWithException( | ||
CustomPredicateExample::capturedLocalVariablePredicateCheck, | ||
eq(3), | ||
{ predicate, x, r -> !predicate.test(x) && r.getOrNull() == false }, | ||
{ predicate, x, r -> predicate.test(x) && r.getOrNull() == true }, | ||
{ predicate, _, r -> predicate == null && r.isException<NullPointerException>() }, | ||
coverage = DoNotCalculate | ||
) | ||
} | ||
|
||
@Test | ||
fun testCapturedParameterPredicateCheck() { | ||
checkWithException( | ||
CustomPredicateExample::capturedParameterPredicateCheck, | ||
eq(3), | ||
{ predicate, x, r -> !predicate.test(x) && r.getOrNull() == false }, | ||
{ predicate, x, r -> predicate.test(x) && r.getOrNull() == true }, | ||
{ predicate, _, r -> predicate == null && r.isException<NullPointerException>() }, | ||
coverage = DoNotCalculate | ||
) | ||
} | ||
|
||
@Test | ||
fun testCapturedStaticFieldPredicateCheck() { | ||
checkWithException( | ||
CustomPredicateExample::capturedStaticFieldPredicateCheck, | ||
eq(3), | ||
{ predicate, x, r -> !predicate.test(x) && r.getOrNull() == false }, | ||
{ predicate, x, r -> predicate.test(x) && r.getOrNull() == true }, | ||
{ predicate, _, r -> predicate == null && r.isException<NullPointerException>() }, | ||
coverage = DoNotCalculate | ||
) | ||
} | ||
|
||
@Test | ||
fun testCapturedNonStaticFieldPredicateCheck() { | ||
checkWithException( | ||
CustomPredicateExample::capturedNonStaticFieldPredicateCheck, | ||
eq(3), | ||
{ predicate, x, r -> !predicate.test(x) && r.getOrNull() == false }, | ||
{ predicate, x, r -> predicate.test(x) && r.getOrNull() == true }, | ||
{ predicate, _, r -> predicate == null && r.isException<NullPointerException>() }, | ||
coverage = DoNotCalculate | ||
) | ||
} | ||
} |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.