diff options
author | Jonas Herzig <jonas@spark-squared.com> | 2021-11-12 15:22:24 +0100 |
---|---|---|
committer | Jonas Herzig <jonas@spark-squared.com> | 2021-11-13 10:28:09 +0100 |
commit | e96738ddc97b4f564a8f783be1b5e5f937bef4a6 (patch) | |
tree | 2a0c4c218db2f303999062eb2a880c6755195b39 /src/test/kotlin/com/replaymod/gradle/remap/mapper/mixin | |
parent | 358136a97feff6fd0586fe04a39adbc7ced381c1 (diff) | |
download | Remap-e96738ddc97b4f564a8f783be1b5e5f937bef4a6.tar.gz Remap-e96738ddc97b4f564a8f783be1b5e5f937bef4a6.tar.bz2 Remap-e96738ddc97b4f564a8f783be1b5e5f937bef4a6.zip |
Move mixin-related tests into their own package
Diffstat (limited to 'src/test/kotlin/com/replaymod/gradle/remap/mapper/mixin')
5 files changed, 431 insertions, 0 deletions
diff --git a/src/test/kotlin/com/replaymod/gradle/remap/mapper/mixin/TestMixinAccessors.kt b/src/test/kotlin/com/replaymod/gradle/remap/mapper/mixin/TestMixinAccessors.kt new file mode 100644 index 0000000..aae4cba --- /dev/null +++ b/src/test/kotlin/com/replaymod/gradle/remap/mapper/mixin/TestMixinAccessors.kt @@ -0,0 +1,82 @@ +package com.replaymod.gradle.remap.mapper.mixin + +import com.replaymod.gradle.remap.util.TestData +import io.kotest.matchers.shouldBe +import org.junit.jupiter.api.Test + +class TestMixinAccessors { + @Test + fun `remaps @Invoker`() { + TestData.remap(""" + @org.spongepowered.asm.mixin.Mixin(a.pkg.A.class) + interface MixinA { + @org.spongepowered.asm.mixin.gen.Invoker + void invokeAMethod(); + @org.spongepowered.asm.mixin.gen.Invoker("aMethod") + void invokeBMethod(); + } + """.trimIndent()) shouldBe """ + @org.spongepowered.asm.mixin.Mixin(b.pkg.B.class) + interface MixinA { + @org.spongepowered.asm.mixin.gen.Invoker("bMethod") + void invokeAMethod(); + @org.spongepowered.asm.mixin.gen.Invoker + void invokeBMethod(); + } + """.trimIndent() + } + + @Test + fun `remaps @Accessor`() { + TestData.remap(""" + @org.spongepowered.asm.mixin.Mixin(a.pkg.A.class) + interface MixinA { + @org.spongepowered.asm.mixin.gen.Accessor + int isAField(); + @org.spongepowered.asm.mixin.gen.Accessor + int getAField(); + @org.spongepowered.asm.mixin.gen.Accessor + void setAField(int value); + @org.spongepowered.asm.mixin.gen.Accessor("aField") + int isBField(); + @org.spongepowered.asm.mixin.gen.Accessor("aField") + int getBField(); + @org.spongepowered.asm.mixin.gen.Accessor("aField") + void setBField(int value); + } + """.trimIndent()) shouldBe """ + @org.spongepowered.asm.mixin.Mixin(b.pkg.B.class) + interface MixinA { + @org.spongepowered.asm.mixin.gen.Accessor("bField") + int isAField(); + @org.spongepowered.asm.mixin.gen.Accessor("bField") + int getAField(); + @org.spongepowered.asm.mixin.gen.Accessor("bField") + void setAField(int value); + @org.spongepowered.asm.mixin.gen.Accessor + int isBField(); + @org.spongepowered.asm.mixin.gen.Accessor + int getBField(); + @org.spongepowered.asm.mixin.gen.Accessor + void setBField(int value); + } + """.trimIndent() + } + + @Test + fun `does not change @Accessor method name even when it happens to be the same as a method in the target`() { + TestData.remap(""" + @org.spongepowered.asm.mixin.Mixin(a.pkg.A.class) + interface MixinA { + @org.spongepowered.asm.mixin.gen.Accessor + a.pkg.A getA(); + } + """.trimIndent()) shouldBe """ + @org.spongepowered.asm.mixin.Mixin(b.pkg.B.class) + interface MixinA { + @org.spongepowered.asm.mixin.gen.Accessor("b") + b.pkg.B getA(); + } + """.trimIndent() + } +}
\ No newline at end of file diff --git a/src/test/kotlin/com/replaymod/gradle/remap/mapper/mixin/TestMixinAnnotation.kt b/src/test/kotlin/com/replaymod/gradle/remap/mapper/mixin/TestMixinAnnotation.kt new file mode 100644 index 0000000..bc7cd8f --- /dev/null +++ b/src/test/kotlin/com/replaymod/gradle/remap/mapper/mixin/TestMixinAnnotation.kt @@ -0,0 +1,63 @@ +package com.replaymod.gradle.remap.mapper.mixin + +import com.replaymod.gradle.remap.util.TestData +import io.kotest.matchers.shouldBe +import org.junit.jupiter.api.Test + +class TestMixinAnnotation { + @Test + fun `remaps with class target`() { + TestData.remap(""" + @org.spongepowered.asm.mixin.Mixin(a.pkg.A.class) + class MixinA { @Shadow private int aField; } + """.trimIndent()) shouldBe """ + @org.spongepowered.asm.mixin.Mixin(b.pkg.B.class) + class MixinA { @Shadow private int bField; } + """.trimIndent() + } + + @Test + fun `remaps with string target`() { + TestData.remap(""" + @org.spongepowered.asm.mixin.Mixin(targets = "a.pkg.A") + class MixinA { @Shadow private int aField; } + """.trimIndent()) shouldBe """ + @org.spongepowered.asm.mixin.Mixin(targets = "b.pkg.B") + class MixinA { @Shadow private int bField; } + """.trimIndent() + } + + @Test + fun `remaps with inner class string target separated by dot`() { + // FIXME should probably keep the dot? + TestData.remap(""" + @org.spongepowered.asm.mixin.Mixin(targets = "a.pkg.A.Inner") + class MixinA { @Shadow private int aField; } + """.trimIndent()) shouldBe """ + @org.spongepowered.asm.mixin.Mixin(targets = "b.pkg.B${'$'}Inner") + class MixinA { @Shadow private int bField; } + """.trimIndent() + } + + @Test + fun `remaps with inner class string target separated by dollar`() { + TestData.remap(""" + @org.spongepowered.asm.mixin.Mixin(targets = "a.pkg.A${'$'}Inner") + class MixinA { @Shadow private int aField; } + """.trimIndent()) shouldBe """ + @org.spongepowered.asm.mixin.Mixin(targets = "b.pkg.B${'$'}Inner") + class MixinA { @Shadow private int bField; } + """.trimIndent() + } + + @Test + fun `remaps with anonymous inner class target`() { + TestData.remap(""" + @org.spongepowered.asm.mixin.Mixin(targets = "a.pkg.A${'$'}1") + class MixinA {} + """.trimIndent()) shouldBe """ + @org.spongepowered.asm.mixin.Mixin(targets = "b.pkg.B${'$'}1") + class MixinA {} + """.trimIndent() + } +}
\ No newline at end of file diff --git a/src/test/kotlin/com/replaymod/gradle/remap/mapper/mixin/TestMixinInjections.kt b/src/test/kotlin/com/replaymod/gradle/remap/mapper/mixin/TestMixinInjections.kt new file mode 100644 index 0000000..0cba1ae --- /dev/null +++ b/src/test/kotlin/com/replaymod/gradle/remap/mapper/mixin/TestMixinInjections.kt @@ -0,0 +1,232 @@ +package com.replaymod.gradle.remap.mapper.mixin + +import com.replaymod.gradle.remap.util.TestData +import io.kotest.matchers.collections.shouldHaveSize +import io.kotest.matchers.shouldBe +import io.kotest.matchers.string.shouldContain +import org.junit.jupiter.api.Test + +class TestMixinInjections { + private fun remaps(annotation: String) { + TestData.remap(""" + @org.spongepowered.asm.mixin.Mixin(a.pkg.A.class) + class MixinA { + @$annotation(method = "aMethod") + private void test() {} + @$annotation(method = "aInterfaceMethod") + private void testInterface() {} + } + """.trimIndent()) shouldBe """ + @org.spongepowered.asm.mixin.Mixin(b.pkg.B.class) + class MixinA { + @$annotation(method = "bMethod") + private void test() {} + @$annotation(method = "bInterfaceMethod") + private void testInterface() {} + } + """.trimIndent() + } + + @Test + fun `remaps @Inject method`() = remaps("org.spongepowered.asm.mixin.injection.Inject") + + @Test + fun `remaps @ModifyArg method`() = remaps("org.spongepowered.asm.mixin.injection.ModifyArg") + + @Test + fun `remaps @ModifyArgs method`() = remaps("org.spongepowered.asm.mixin.injection.ModifyArgs") + + @Test + fun `remaps @ModifyConstant method`() = remaps("org.spongepowered.asm.mixin.injection.ModifyConstant") + + @Test + fun `remaps @ModifyVariable method`() = remaps("org.spongepowered.asm.mixin.injection.ModifyVariable") + + @Test + fun `remaps @Redirect method`() = remaps("org.spongepowered.asm.mixin.injection.Redirect") + + @Test + fun `throws when injecting into ambiguous method`() { + val (_, errors) = TestData.remapWithErrors(""" + @org.spongepowered.asm.mixin.Mixin(a.pkg.A.class) + class MixinA { + @org.spongepowered.asm.mixin.injection.Inject(method = "aOverloaded") + private void test() {} + } + """.trimIndent()) + errors shouldHaveSize 1 + val (line, error) = errors[0] + line shouldBe 2 + error shouldContain "aOverloaded" + error shouldContain "(I)V" + error shouldContain "(Z)V" + } + + @Test + fun `remaps qualified method`() { + TestData.remap(""" + @org.spongepowered.asm.mixin.Mixin(a.pkg.A.class) + class MixinA { + @org.spongepowered.asm.mixin.injection.Inject(method = "aOverloaded()V") + private void test() {} + @org.spongepowered.asm.mixin.injection.Inject(method = "aOverloaded(I)V") + private void testArg() {} + } + """.trimIndent()) shouldBe """ + @org.spongepowered.asm.mixin.Mixin(b.pkg.B.class) + class MixinA { + @org.spongepowered.asm.mixin.injection.Inject(method = "bOverloaded()V") + private void test() {} + @org.spongepowered.asm.mixin.injection.Inject(method = "bOverloaded(I)V") + private void testArg() {} + } + """.trimIndent() + } + + @Test + fun `remaps qualified method argument`() { + TestData.remap(""" + @org.spongepowered.asm.mixin.Mixin(a.pkg.A.class) + class MixinA { + @org.spongepowered.asm.mixin.injection.Inject(method = "commonOverloaded(La/pkg/A;)V") + private void test() {} + } + """.trimIndent()) shouldBe """ + @org.spongepowered.asm.mixin.Mixin(b.pkg.B.class) + class MixinA { + @org.spongepowered.asm.mixin.injection.Inject(method = "commonOverloaded(Lb/pkg/B;)V") + private void test() {} + } + """.trimIndent() + } + + @Test + fun `remaps qualified method argument without mappings for target`() { + TestData.remap(""" + @org.spongepowered.asm.mixin.Mixin(a.pkg.A.class) + class MixinA { + @org.spongepowered.asm.mixin.injection.Inject(method = "unmappedOverloaded(La/pkg/A;)V") + private void test() {} + } + """.trimIndent()) shouldBe """ + @org.spongepowered.asm.mixin.Mixin(b.pkg.B.class) + class MixinA { + @org.spongepowered.asm.mixin.injection.Inject(method = "unmappedOverloaded(Lb/pkg/B;)V") + private void test() {} + } + """.trimIndent() + } + + @Test + fun `remaps constructor target`() { + TestData.remap(""" + @org.spongepowered.asm.mixin.Mixin(a.pkg.A.class) + class MixinA { + @org.spongepowered.asm.mixin.injection.Inject(method = "<init>()V") + private void test() {} + @org.spongepowered.asm.mixin.injection.Inject(method = "<init>(La/pkg/A;)V") + private void testArg() {} + } + """.trimIndent()) shouldBe """ + @org.spongepowered.asm.mixin.Mixin(b.pkg.B.class) + class MixinA { + @org.spongepowered.asm.mixin.injection.Inject(method = "<init>()V") + private void test() {} + @org.spongepowered.asm.mixin.injection.Inject(method = "<init>(Lb/pkg/B;)V") + private void testArg() {} + } + """.trimIndent() + } + + @Test + fun `remaps method in constant`() { + TestData.remap(""" + @org.spongepowered.asm.mixin.Mixin(a.pkg.A.class) + class MixinA { + private static final String TARGET = "aMethod"; + @org.spongepowered.asm.mixin.injection.Inject(method = TARGET) + private void test1() {} + @org.spongepowered.asm.mixin.injection.Inject(method = TARGET) + private void test2() {} + } + """.trimIndent()) shouldBe """ + @org.spongepowered.asm.mixin.Mixin(b.pkg.B.class) + class MixinA { + private static final String TARGET = "bMethod"; + @org.spongepowered.asm.mixin.injection.Inject(method = TARGET) + private void test1() {} + @org.spongepowered.asm.mixin.injection.Inject(method = TARGET) + private void test2() {} + } + """.trimIndent() + } + + @Test + fun `remaps @At target`() { + TestData.remap(""" + import org.spongepowered.asm.mixin.injection.At; + import org.spongepowered.asm.mixin.injection.Inject; + @org.spongepowered.asm.mixin.Mixin(a.pkg.A.class) + class MixinA { + @Inject(method = "aMethod", at = @At(target = "La/pkg/A;aInterfaceMethod()V")) + private void test() {} + } + """.trimIndent()) shouldBe """ + import org.spongepowered.asm.mixin.injection.At; + import org.spongepowered.asm.mixin.injection.Inject; + @org.spongepowered.asm.mixin.Mixin(b.pkg.B.class) + class MixinA { + @Inject(method = "bMethod", at = @At(target = "Lb/pkg/B;bInterfaceMethod()V")) + private void test() {} + } + """.trimIndent() + } + + @Test + fun `remaps @At target without mappings for target`() { + TestData.remap(""" + import org.spongepowered.asm.mixin.injection.At; + import org.spongepowered.asm.mixin.injection.Inject; + @org.spongepowered.asm.mixin.Mixin(a.pkg.A.class) + class MixinA { + @Inject(method = "aMethod", at = @At(target = "La/pkg/A;unmappedOverloaded(La/pkg/A;)V")) + private void test() {} + } + """.trimIndent()) shouldBe """ + import org.spongepowered.asm.mixin.injection.At; + import org.spongepowered.asm.mixin.injection.Inject; + @org.spongepowered.asm.mixin.Mixin(b.pkg.B.class) + class MixinA { + @Inject(method = "bMethod", at = @At(target = "Lb/pkg/B;unmappedOverloaded(Lb/pkg/B;)V")) + private void test() {} + } + """.trimIndent() + } + + @Test + fun `remaps @At target in constant`() { + TestData.remap(""" + import org.spongepowered.asm.mixin.injection.At; + import org.spongepowered.asm.mixin.injection.Inject; + @org.spongepowered.asm.mixin.Mixin(a.pkg.A.class) + class MixinA { + private static final String TARGET = "La/pkg/A;aInterfaceMethod()V"; + @Inject(method = "aMethod", at = @At(target = TARGET)) + private void test1() {} + @Inject(method = "aMethod", at = @At(target = TARGET)) + private void test2() {} + } + """.trimIndent()) shouldBe """ + import org.spongepowered.asm.mixin.injection.At; + import org.spongepowered.asm.mixin.injection.Inject; + @org.spongepowered.asm.mixin.Mixin(b.pkg.B.class) + class MixinA { + private static final String TARGET = "Lb/pkg/B;bInterfaceMethod()V"; + @Inject(method = "bMethod", at = @At(target = TARGET)) + private void test1() {} + @Inject(method = "bMethod", at = @At(target = TARGET)) + private void test2() {} + } + """.trimIndent() + } +}
\ No newline at end of file diff --git a/src/test/kotlin/com/replaymod/gradle/remap/mapper/mixin/TestMixinOverride.kt b/src/test/kotlin/com/replaymod/gradle/remap/mapper/mixin/TestMixinOverride.kt new file mode 100644 index 0000000..f292fef --- /dev/null +++ b/src/test/kotlin/com/replaymod/gradle/remap/mapper/mixin/TestMixinOverride.kt @@ -0,0 +1,28 @@ +package com.replaymod.gradle.remap.mapper.mixin + +import com.replaymod.gradle.remap.util.TestData +import io.kotest.matchers.shouldBe +import org.junit.jupiter.api.Test + +class TestMixinOverride { + @Test + fun `remaps overridden method`() { + TestData.remap(""" + @org.spongepowered.asm.mixin.Mixin(a.pkg.A.class) + abstract class MixinA extends a.pkg.AParent { + @Override + public a.pkg.AParent aParentMethod() { + return this; + } + } + """.trimIndent()) shouldBe """ + @org.spongepowered.asm.mixin.Mixin(b.pkg.B.class) + abstract class MixinA extends b.pkg.BParent { + @Override + public b.pkg.BParent bParentMethod() { + return this; + } + } + """.trimIndent() + } +}
\ No newline at end of file diff --git a/src/test/kotlin/com/replaymod/gradle/remap/mapper/mixin/TestMixinShadow.kt b/src/test/kotlin/com/replaymod/gradle/remap/mapper/mixin/TestMixinShadow.kt new file mode 100644 index 0000000..4f76c97 --- /dev/null +++ b/src/test/kotlin/com/replaymod/gradle/remap/mapper/mixin/TestMixinShadow.kt @@ -0,0 +1,26 @@ +package com.replaymod.gradle.remap.mapper.mixin + +import com.replaymod.gradle.remap.util.TestData +import io.kotest.matchers.shouldBe +import org.junit.jupiter.api.Test + +class TestMixinShadow { + @Test + fun `remaps shadow method and references to it`() { + TestData.remap(""" + @org.spongepowered.asm.mixin.Mixin(a.pkg.A.class) + abstract class MixinA { + @org.spongepowered.asm.mixin.Shadow + protected abstract a.pkg.A getA(); + private void test() { this.getA(); } + } + """.trimIndent()) shouldBe """ + @org.spongepowered.asm.mixin.Mixin(b.pkg.B.class) + abstract class MixinA { + @org.spongepowered.asm.mixin.Shadow + protected abstract b.pkg.B getB(); + private void test() { this.getB(); } + } + """.trimIndent() + } +}
\ No newline at end of file |