From 7d62cd890cb44945e772e18cdb457b1173f4f853 Mon Sep 17 00:00:00 2001 From: Jonas Herzig Date: Wed, 10 Nov 2021 09:34:39 +0100 Subject: Start adding tests --- .../gradle/remap/mapper/TestMixinAccessors.kt | 65 ++++++++++++++ .../gradle/remap/mapper/TestMixinAnnotation.kt | 52 ++++++++++++ .../gradle/remap/mapper/TestMixinInjections.kt | 98 ++++++++++++++++++++++ 3 files changed, 215 insertions(+) create mode 100644 src/test/kotlin/com/replaymod/gradle/remap/mapper/TestMixinAccessors.kt create mode 100644 src/test/kotlin/com/replaymod/gradle/remap/mapper/TestMixinAnnotation.kt create mode 100644 src/test/kotlin/com/replaymod/gradle/remap/mapper/TestMixinInjections.kt (limited to 'src/test/kotlin/com/replaymod/gradle/remap/mapper') diff --git a/src/test/kotlin/com/replaymod/gradle/remap/mapper/TestMixinAccessors.kt b/src/test/kotlin/com/replaymod/gradle/remap/mapper/TestMixinAccessors.kt new file mode 100644 index 0000000..4b9450f --- /dev/null +++ b/src/test/kotlin/com/replaymod/gradle/remap/mapper/TestMixinAccessors.kt @@ -0,0 +1,65 @@ +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() + } +} \ 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 new file mode 100644 index 0000000..1f9a3a2 --- /dev/null +++ b/src/test/kotlin/com/replaymod/gradle/remap/mapper/TestMixinAnnotation.kt @@ -0,0 +1,52 @@ +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() + } +} \ 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 new file mode 100644 index 0000000..856b56e --- /dev/null +++ b/src/test/kotlin/com/replaymod/gradle/remap/mapper/TestMixinInjections.kt @@ -0,0 +1,98 @@ +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() {} + } + """.trimIndent()) shouldBe """ + @org.spongepowered.asm.mixin.Mixin(b.pkg.B.class) + class MixinA { + @$annotation(method = "bMethod") + private void test() {} + } + """.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() + } +} \ No newline at end of file -- cgit