aboutsummaryrefslogtreecommitdiff
path: root/src/test/kotlin/com/replaymod/gradle/remap/pattern/TestNewExpression.kt
blob: 669cffb7b1c4983053115372f74041750cd9239d (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
package com.replaymod.gradle.remap.pattern

import com.replaymod.gradle.remap.util.TestData
import io.kotest.matchers.shouldBe
import org.junit.jupiter.api.Test

class TestNewExpression {
    @Test
    fun `should find regular constructor`() {
        TestData.remap("""
            class Test {
                private void test() {
                    new a.pkg.A(null);
                    new a.pkg.A().new a.pkg.A.Inner();
                    new a.pkg.AParent(null);
                }
            }
        """.trimIndent(), """
            @remap.Pattern
            private a.pkg.A matchNew(a.pkg.A arg) {
                return new a.pkg.A(arg);
            }
        """.trimIndent(), """
            @remap.Pattern
            private b.pkg.B matchNew(b.pkg.B arg) {
                return arg;
            }
        """.trimIndent()) shouldBe """
            class Test {
                private void test() {
                    null;
                    new b.pkg.B().new b.pkg.B.Inner();
                    new b.pkg.BParent(null);
                }
            }
        """.trimIndent()
    }

    @Test
    fun `should find inner class constructor`() {
        TestData.remap("""
            class Test {
                private void test() {
                    new a.pkg.A(null);
                    new a.pkg.A().new Inner();
                    new a.pkg.AParent(null);
                }
            }
        """.trimIndent(), """
            @remap.Pattern
            private a.pkg.A.Inner matchNew(a.pkg.A arg) {
                return arg.new a.pkg.A.Inner();
            }
        """.trimIndent(), """
            @remap.Pattern
            private b.pkg.B matchNew(b.pkg.B arg) {
                return arg;
            }
        """.trimIndent()) shouldBe """
            class Test {
                private void test() {
                    new b.pkg.B(null);
                    new b.pkg.B();
                    new b.pkg.BParent(null);
                }
            }
        """.trimIndent()
    }
}