blob: 7b9750ed377db47cbc5ccbca37932765497f16e8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
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()
}
}
|