From 8b1a5a77e75d868cd13ad7dc4d109125711898ce Mon Sep 17 00:00:00 2001 From: Jonas Herzig Date: Thu, 11 Nov 2021 22:25:12 +0100 Subject: Add tests for Kotlin synthetic properties --- src/test/java/a/pkg/A.java | 42 +++++++++ src/test/java/b/pkg/B.java | 42 +++++++++ .../mapper/kotlin/TestKotlinSyntheticProperties.kt | 100 +++++++++++++++++++++ src/test/resources/mappings.srg | 12 +++ 4 files changed, 196 insertions(+) create mode 100644 src/test/kotlin/com/replaymod/gradle/remap/mapper/kotlin/TestKotlinSyntheticProperties.kt diff --git a/src/test/java/a/pkg/A.java b/src/test/java/a/pkg/A.java index 32fa2a9..fd177e5 100644 --- a/src/test/java/a/pkg/A.java +++ b/src/test/java/a/pkg/A.java @@ -20,6 +20,48 @@ public class A extends AParent implements AInterface { return this; } + public A getSyntheticA() { + return this; + } + + public void setSyntheticA(A arg) { + } + + public boolean isSyntheticBooleanA() { + return false; + } + + public void setSyntheticBooleanA(boolean arg) { + } + + public A getNonSyntheticA() { + return this; + } + + public void setNonSyntheticA(A arg) { + } + + public boolean isNonSyntheticBooleanA() { + return false; + } + + public void setNonSyntheticBooleanA(boolean arg) { + } + + public A getterA() { + return this; + } + + public void setterA(A arg) { + } + + public boolean getterBooleanA() { + return false; + } + + public void setterBooleanA(boolean arg) { + } + public void aOverloaded() { } diff --git a/src/test/java/b/pkg/B.java b/src/test/java/b/pkg/B.java index 3af7381..b153be4 100644 --- a/src/test/java/b/pkg/B.java +++ b/src/test/java/b/pkg/B.java @@ -20,6 +20,48 @@ public class B extends BParent implements BInterface { return this; } + public B getSyntheticB() { + return this; + } + + public void setSyntheticB(B arg) { + } + + public boolean isSyntheticBooleanB() { + return false; + } + + public void setSyntheticBooleanB(boolean arg) { + } + + public B getNonSyntheticB() { + return this; + } + + public void setNonSyntheticB(B arg) { + } + + public boolean isNonSyntheticBooleanB() { + return false; + } + + public void setNonSyntheticBooleanB(boolean arg) { + } + + public B getterB() { + return this; + } + + public void setterB(B arg) { + } + + public boolean getterBooleanB() { + return false; + } + + public void setterBooleanB(boolean arg) { + } + public void bOverloaded() { } diff --git a/src/test/kotlin/com/replaymod/gradle/remap/mapper/kotlin/TestKotlinSyntheticProperties.kt b/src/test/kotlin/com/replaymod/gradle/remap/mapper/kotlin/TestKotlinSyntheticProperties.kt new file mode 100644 index 0000000..d0f6fc2 --- /dev/null +++ b/src/test/kotlin/com/replaymod/gradle/remap/mapper/kotlin/TestKotlinSyntheticProperties.kt @@ -0,0 +1,100 @@ +package com.replaymod.gradle.remap.mapper.kotlin + +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 TestKotlinSyntheticProperties { + @Test + fun `remaps synthetic getter`() { + TestData.remapKt(""" + import a.pkg.A + val v = A().syntheticA + val b = A().isSyntheticBooleanA + """.trimIndent()) shouldBe """ + import b.pkg.B + val v = B().syntheticB + val b = B().isSyntheticBooleanB + """.trimIndent() + } + + @Test + fun `remaps synthetic setter`() { + TestData.remapKt(""" + import a.pkg.A + fun test() { + A().syntheticA = A() + A().isSyntheticBooleanA = true + } + """.trimIndent()) shouldBe """ + import b.pkg.B + fun test() { + B().syntheticB = B() + B().isSyntheticBooleanB = true + } + """.trimIndent() + } + + @Test + fun `converts synthetic property to getter if no longer synthetic`() { + TestData.remapKt(""" + import a.pkg.A + val v = A().nonSyntheticA + val b = A().isNonSyntheticBooleanA + """.trimIndent()) shouldBe """ + import b.pkg.B + val v = B().getterB() + val b = B().getterBooleanB() + """.trimIndent() + } + + @Test + fun `converts getter to synthetic property if now synthetic`() { + TestData.remapKt(""" + import a.pkg.A + val v = A().getterA() + val b = A().getterBooleanA() + """.trimIndent()) shouldBe """ + import b.pkg.B + val v = B().nonSyntheticB + val b = B().isNonSyntheticBooleanB + """.trimIndent() + } + + @Test + @Disabled("not yet implemented") + fun `converts synthetic property to setter if no longer synthetic`() { + TestData.remapKt(""" + import a.pkg.A + fun test() { + A().nonSyntheticA = A() + A().isNonSyntheticBooleanA = true + } + """.trimIndent()) shouldBe """ + import b.pkg.B + fun test() { + B().setterB(B()) + B().setterBooleanB(true) + } + """.trimIndent() + } + + @Test + @Disabled("not yet implemented") + fun `converts setter to synthetic property if now synthetic`() { + TestData.remapKt(""" + import a.pkg.A + fun test() { + A().setterA(A()) + A().setterBooleanA(true) + } + """.trimIndent()) shouldBe """ + import b.pkg.B + fun test() { + B().nonSyntheticB = B() + B().isNonSyntheticBooleanB = true + } + """.trimIndent() + } +} diff --git a/src/test/resources/mappings.srg b/src/test/resources/mappings.srg index 2a14ef5..df3d7ef 100644 --- a/src/test/resources/mappings.srg +++ b/src/test/resources/mappings.srg @@ -3,6 +3,18 @@ FD: a/pkg/A/a b/pkg/B/b FD: a/pkg/A/aField b/pkg/B/bField MD: a/pkg/A/aMethod ()V b/pkg/B/bMethod ()V MD: a/pkg/A/getA ()La/pkg/A; b/pkg/B/getB ()Lb/pkg/B; +MD: a/pkg/A/getSyntheticA ()La/pkg/A; b/pkg/B/getSyntheticB ()Lb/pkg/B; +MD: a/pkg/A/setSyntheticA (La/pkg/A;)V; b/pkg/B/setSyntheticB (Lb/pkg/B;)V; +MD: a/pkg/A/isSyntheticBooleanA ()Z; b/pkg/B/isSyntheticBooleanB ()Z; +MD: a/pkg/A/setSyntheticBooleanA (Z)V; b/pkg/B/setSyntheticBooleanB (Z)V; +MD: a/pkg/A/getNonSyntheticA ()La/pkg/A; b/pkg/B/getterB ()Lb/pkg/B; +MD: a/pkg/A/setNonSyntheticA (La/pkg/A;)V; b/pkg/B/setterB (Lb/pkg/B;)V; +MD: a/pkg/A/isNonSyntheticBooleanA ()Z; b/pkg/B/getterBooleanB ()Z; +MD: a/pkg/A/setNonSyntheticBooleanA (Z)V; b/pkg/B/setterBooleanB (Z)V; +MD: a/pkg/A/getterA ()La/pkg/A; b/pkg/B/getNonSyntheticB ()Lb/pkg/B; +MD: a/pkg/A/setterA (La/pkg/A;)V; b/pkg/B/setNonSyntheticB (Lb/pkg/B;)V; +MD: a/pkg/A/getterBooleanA ()Z; b/pkg/B/isNonSyntheticBooleanB ()Z; +MD: a/pkg/A/setterBooleanA (Z)V; b/pkg/B/setNonSyntheticBooleanB (Z)V; MD: a/pkg/A/aOverloaded ()V b/pkg/B/bOverloaded ()V MD: a/pkg/A/aOverloaded (I)V b/pkg/B/bOverloaded (I)V MD: a/pkg/A/aOverloaded (Z)V b/pkg/B/bOverloaded (Z)V -- cgit