From e96738ddc97b4f564a8f783be1b5e5f937bef4a6 Mon Sep 17 00:00:00 2001 From: Jonas Herzig Date: Fri, 12 Nov 2021 15:22:24 +0100 Subject: Move mixin-related tests into their own package --- .../gradle/remap/mapper/TestMixinAccessors.kt | 82 -------- .../gradle/remap/mapper/TestMixinAnnotation.kt | 63 ------ .../gradle/remap/mapper/TestMixinInjections.kt | 232 --------------------- .../gradle/remap/mapper/TestMixinOverride.kt | 28 --- .../gradle/remap/mapper/TestMixinShadow.kt | 26 --- .../remap/mapper/mixin/TestMixinAccessors.kt | 82 ++++++++ .../remap/mapper/mixin/TestMixinAnnotation.kt | 63 ++++++ .../remap/mapper/mixin/TestMixinInjections.kt | 232 +++++++++++++++++++++ .../gradle/remap/mapper/mixin/TestMixinOverride.kt | 28 +++ .../gradle/remap/mapper/mixin/TestMixinShadow.kt | 26 +++ 10 files changed, 431 insertions(+), 431 deletions(-) delete mode 100644 src/test/kotlin/com/replaymod/gradle/remap/mapper/TestMixinAccessors.kt delete mode 100644 src/test/kotlin/com/replaymod/gradle/remap/mapper/TestMixinAnnotation.kt delete mode 100644 src/test/kotlin/com/replaymod/gradle/remap/mapper/TestMixinInjections.kt delete mode 100644 src/test/kotlin/com/replaymod/gradle/remap/mapper/TestMixinOverride.kt delete mode 100644 src/test/kotlin/com/replaymod/gradle/remap/mapper/TestMixinShadow.kt create mode 100644 src/test/kotlin/com/replaymod/gradle/remap/mapper/mixin/TestMixinAccessors.kt create mode 100644 src/test/kotlin/com/replaymod/gradle/remap/mapper/mixin/TestMixinAnnotation.kt create mode 100644 src/test/kotlin/com/replaymod/gradle/remap/mapper/mixin/TestMixinInjections.kt create mode 100644 src/test/kotlin/com/replaymod/gradle/remap/mapper/mixin/TestMixinOverride.kt create mode 100644 src/test/kotlin/com/replaymod/gradle/remap/mapper/mixin/TestMixinShadow.kt (limited to 'src') diff --git a/src/test/kotlin/com/replaymod/gradle/remap/mapper/TestMixinAccessors.kt b/src/test/kotlin/com/replaymod/gradle/remap/mapper/TestMixinAccessors.kt deleted file mode 100644 index 9933606..0000000 --- a/src/test/kotlin/com/replaymod/gradle/remap/mapper/TestMixinAccessors.kt +++ /dev/null @@ -1,82 +0,0 @@ -package com.replaymod.gradle.remap.mapper - -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/TestMixinAnnotation.kt b/src/test/kotlin/com/replaymod/gradle/remap/mapper/TestMixinAnnotation.kt deleted file mode 100644 index 595b65f..0000000 --- a/src/test/kotlin/com/replaymod/gradle/remap/mapper/TestMixinAnnotation.kt +++ /dev/null @@ -1,63 +0,0 @@ -package com.replaymod.gradle.remap.mapper - -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/TestMixinInjections.kt b/src/test/kotlin/com/replaymod/gradle/remap/mapper/TestMixinInjections.kt deleted file mode 100644 index b473dbe..0000000 --- a/src/test/kotlin/com/replaymod/gradle/remap/mapper/TestMixinInjections.kt +++ /dev/null @@ -1,232 +0,0 @@ -package com.replaymod.gradle.remap.mapper - -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 = "()V") - private void test() {} - @org.spongepowered.asm.mixin.injection.Inject(method = "(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 = "()V") - private void test() {} - @org.spongepowered.asm.mixin.injection.Inject(method = "(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/TestMixinOverride.kt b/src/test/kotlin/com/replaymod/gradle/remap/mapper/TestMixinOverride.kt deleted file mode 100644 index 6caaeba..0000000 --- a/src/test/kotlin/com/replaymod/gradle/remap/mapper/TestMixinOverride.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.replaymod.gradle.remap.mapper - -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/TestMixinShadow.kt b/src/test/kotlin/com/replaymod/gradle/remap/mapper/TestMixinShadow.kt deleted file mode 100644 index bc4ebe6..0000000 --- a/src/test/kotlin/com/replaymod/gradle/remap/mapper/TestMixinShadow.kt +++ /dev/null @@ -1,26 +0,0 @@ -package com.replaymod.gradle.remap.mapper - -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 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 = "()V") + private void test() {} + @org.spongepowered.asm.mixin.injection.Inject(method = "(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 = "()V") + private void test() {} + @org.spongepowered.asm.mixin.injection.Inject(method = "(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 -- cgit