blob: 3f8d55fb468d7aaba469d449f56c038bb83bddfc (
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
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 = "<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()
}
}
|