aboutsummaryrefslogtreecommitdiff
path: root/src/test/kotlin/com/replaymod/gradle/remap
diff options
context:
space:
mode:
authorJonas Herzig <me@johni0702.de>2022-05-24 15:13:42 +0200
committerJonas Herzig <me@johni0702.de>2022-05-27 08:46:01 +0200
commit51cf5a796dbf3a185bb80044976dc8f32ebbf040 (patch)
treed06b45bea0f262b8a7e90d296450502011dfc7a4 /src/test/kotlin/com/replaymod/gradle/remap
parent1e3fab153d134f7dec5601cbdbca3c27d6aebc58 (diff)
downloadRemap-51cf5a796dbf3a185bb80044976dc8f32ebbf040.tar.gz
Remap-51cf5a796dbf3a185bb80044976dc8f32ebbf040.tar.bz2
Remap-51cf5a796dbf3a185bb80044976dc8f32ebbf040.zip
Properly support new expression matching in @Pattern
Used to only compare the arguments, nether the class nor the qualifier (the outer class instance for inner classes constructor calls).
Diffstat (limited to 'src/test/kotlin/com/replaymod/gradle/remap')
-rw-r--r--src/test/kotlin/com/replaymod/gradle/remap/pattern/TestNewExpression.kt69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/test/kotlin/com/replaymod/gradle/remap/pattern/TestNewExpression.kt b/src/test/kotlin/com/replaymod/gradle/remap/pattern/TestNewExpression.kt
new file mode 100644
index 0000000..669cffb
--- /dev/null
+++ b/src/test/kotlin/com/replaymod/gradle/remap/pattern/TestNewExpression.kt
@@ -0,0 +1,69 @@
+package com.replaymod.gradle.remap.pattern
+
+import com.replaymod.gradle.remap.util.TestData
+import io.kotest.matchers.shouldBe
+import org.junit.jupiter.api.Test
+
+class TestNewExpression {
+ @Test
+ fun `should find regular constructor`() {
+ TestData.remap("""
+ class Test {
+ private void test() {
+ new a.pkg.A(null);
+ new a.pkg.A().new a.pkg.A.Inner();
+ new a.pkg.AParent(null);
+ }
+ }
+ """.trimIndent(), """
+ @remap.Pattern
+ private a.pkg.A matchNew(a.pkg.A arg) {
+ return new a.pkg.A(arg);
+ }
+ """.trimIndent(), """
+ @remap.Pattern
+ private b.pkg.B matchNew(b.pkg.B arg) {
+ return arg;
+ }
+ """.trimIndent()) shouldBe """
+ class Test {
+ private void test() {
+ null;
+ new b.pkg.B().new b.pkg.B.Inner();
+ new b.pkg.BParent(null);
+ }
+ }
+ """.trimIndent()
+ }
+
+ @Test
+ fun `should find inner class constructor`() {
+ TestData.remap("""
+ class Test {
+ private void test() {
+ new a.pkg.A(null);
+ new a.pkg.A().new Inner();
+ new a.pkg.AParent(null);
+ }
+ }
+ """.trimIndent(), """
+ @remap.Pattern
+ private a.pkg.A.Inner matchNew(a.pkg.A arg) {
+ return arg.new a.pkg.A.Inner();
+ }
+ """.trimIndent(), """
+ @remap.Pattern
+ private b.pkg.B matchNew(b.pkg.B arg) {
+ return arg;
+ }
+ """.trimIndent()) shouldBe """
+ class Test {
+ private void test() {
+ new b.pkg.B(null);
+ new b.pkg.B();
+ new b.pkg.BParent(null);
+ }
+ }
+ """.trimIndent()
+ }
+} \ No newline at end of file