diff options
author | Jonas Herzig <me@johni0702.de> | 2022-05-25 07:35:00 +0200 |
---|---|---|
committer | Jonas Herzig <me@johni0702.de> | 2022-05-27 08:46:01 +0200 |
commit | 4019ebe20786059fdce5b25c7cf6d746a083eef3 (patch) | |
tree | e2aee9d92f7287d735a82f21debb91ad8d8b2fe4 /src/test/kotlin/com/replaymod/gradle/remap | |
parent | 3104e9fdb3c2df7528813e03e4a3e08a3e1a8c2a (diff) | |
download | Remap-4019ebe20786059fdce5b25c7cf6d746a083eef3.tar.gz Remap-4019ebe20786059fdce5b25c7cf6d746a083eef3.tar.bz2 Remap-4019ebe20786059fdce5b25c7cf6d746a083eef3.zip |
Support matching lambda expressions with @Pattern
Diffstat (limited to 'src/test/kotlin/com/replaymod/gradle/remap')
-rw-r--r-- | src/test/kotlin/com/replaymod/gradle/remap/pattern/TestLambdaExpression.kt | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/src/test/kotlin/com/replaymod/gradle/remap/pattern/TestLambdaExpression.kt b/src/test/kotlin/com/replaymod/gradle/remap/pattern/TestLambdaExpression.kt new file mode 100644 index 0000000..dc45492 --- /dev/null +++ b/src/test/kotlin/com/replaymod/gradle/remap/pattern/TestLambdaExpression.kt @@ -0,0 +1,90 @@ +package com.replaymod.gradle.remap.pattern + +import com.replaymod.gradle.remap.util.TestData +import io.kotest.matchers.shouldBe +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test + +class TestLambdaExpression { + @Test + fun `should find simply lambda expression`() { + TestData.remap(""" + class Test { + private void test() { + a.pkg.A.supplier(() -> "test"); + } + } + """.trimIndent(), """ + @remap.Pattern + private void pattern(String str) { + return a.pkg.A.supplier(() -> str); + } + """.trimIndent(), """ + @remap.Pattern + private void pattern(String str) { + return matched(str); + } + """.trimIndent()) shouldBe """ + class Test { + private void test() { + matched("test"); + } + } + """.trimIndent() + } + + @Test + fun `should find lambda expression with bound arguments`() { + TestData.remap(""" + class Test { + private void test() { + a.pkg.A.function(str -> str + "test"); + } + } + """.trimIndent(), """ + @remap.Pattern + private void pattern(String str) { + return a.pkg.A.function(s -> s + str); + } + """.trimIndent(), """ + @remap.Pattern + private void pattern(String str) { + return matched(str); + } + """.trimIndent()) shouldBe """ + class Test { + private void test() { + matched("test"); + } + } + """.trimIndent() + } + + @Test + @Disabled("Not yet implemented. Requires more complex replacement scheme.") + fun `should preserve bound lambda argument names`() { + TestData.remap(""" + class Test { + private void test() { + a.pkg.A.function(str -> str + "test"); + } + } + """.trimIndent(), """ + @remap.Pattern + private void pattern(String str) { + return a.pkg.A.function(s -> s + str); + } + """.trimIndent(), """ + @remap.Pattern + private void pattern(String str) { + return matched(s -> s + str); + } + """.trimIndent()) shouldBe """ + class Test { + private void test() { + matched(str -> str + "test"); + } + } + """.trimIndent() + } +}
\ No newline at end of file |