diff options
author | Jonas Herzig <jonas@spark-squared.com> | 2021-11-11 16:52:27 +0100 |
---|---|---|
committer | Jonas Herzig <jonas@spark-squared.com> | 2021-11-11 21:38:47 +0100 |
commit | 982982c63027e416bd78ca40708c7238e7eed26b (patch) | |
tree | 509517275b8664157f0cfc58e20675527fcc9ce8 /src/test/kotlin/com/replaymod/gradle/remap/mapper | |
parent | b4462eb6030f8e5a072ad4b6508d7a93d574522f (diff) | |
download | Remap-982982c63027e416bd78ca40708c7238e7eed26b.tar.gz Remap-982982c63027e416bd78ca40708c7238e7eed26b.tar.bz2 Remap-982982c63027e416bd78ca40708c7238e7eed26b.zip |
Fix remapping of qualified inner class reference in Kotlin code
When we used to remap `a.pkg.A.Inner` we would apply both mappings (the one for
the inner class and the one for the outer class) at the same time, resulting in
`b.pkg.B.Inner.Inner`.
The direct cause being that we only checked conflicts for the range of the
respective expression (which is just `A` and `Inner` for Kotlin, and therefore
not conflicting) instead of the parent as we should have.
With that fixed, it now also becomes apparent that we need to apply mappings for
dot qualified expressions back to front (otherwise the outer class takes
priority), so that is the second thing this commit change.
Diffstat (limited to 'src/test/kotlin/com/replaymod/gradle/remap/mapper')
3 files changed, 133 insertions, 0 deletions
diff --git a/src/test/kotlin/com/replaymod/gradle/remap/mapper/kotlin/TestKotlinGenerics.kt b/src/test/kotlin/com/replaymod/gradle/remap/mapper/kotlin/TestKotlinGenerics.kt new file mode 100644 index 0000000..19a3574 --- /dev/null +++ b/src/test/kotlin/com/replaymod/gradle/remap/mapper/kotlin/TestKotlinGenerics.kt @@ -0,0 +1,49 @@ +package com.replaymod.gradle.remap.mapper.kotlin + +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 TestKotlinGenerics { + @Test + fun `remaps generic type argument`() { + TestData.remapKt(""" + val test: List<a.pkg.A> = TODO() + """.trimIndent()) shouldBe """ + val test: List<b.pkg.B> = TODO() + """.trimIndent() + } + + @Test + fun `remaps generic type argument with import`() { + TestData.remapKt(""" + import a.pkg.A + val test: List<A> = TODO() + """.trimIndent()) shouldBe """ + import b.pkg.B + val test: List<B> = TODO() + """.trimIndent() + } + + @Test + fun `remaps generic type`() { + TestData.remapKt(""" + val test: a.pkg.A.GenericA<Int> = TODO() + """.trimIndent()) shouldBe """ + val test: b.pkg.B.GenericB<Int> = TODO() + """.trimIndent() + } + + @Test + fun `remaps generic type with import`() { + TestData.remapKt(""" + import a.pkg.A.GenericA + val test: GenericA<Int> = TODO() + """.trimIndent()) shouldBe """ + import b.pkg.B.GenericB + val test: GenericB<Int> = TODO() + """.trimIndent() + } +}
\ No newline at end of file diff --git a/src/test/kotlin/com/replaymod/gradle/remap/mapper/kotlin/TestKotlinImports.kt b/src/test/kotlin/com/replaymod/gradle/remap/mapper/kotlin/TestKotlinImports.kt new file mode 100644 index 0000000..3193c2f --- /dev/null +++ b/src/test/kotlin/com/replaymod/gradle/remap/mapper/kotlin/TestKotlinImports.kt @@ -0,0 +1,42 @@ +package com.replaymod.gradle.remap.mapper.kotlin + +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 TestKotlinImports { + @Test + fun `remaps simple import`() { + TestData.remapKt(""" + import a.pkg.A + val test: A = TODO() + """.trimIndent()) shouldBe """ + import b.pkg.B + val test: B = TODO() + """.trimIndent() + } + + @Test + fun `remaps outer class of inner class import`() { + TestData.remapKt(""" + import a.pkg.A.Inner + val test: Inner = TODO() + """.trimIndent()) shouldBe """ + import b.pkg.B.Inner + val test: Inner = TODO() + """.trimIndent() + } + + @Test + fun `remaps inner class import`() { + TestData.remapKt(""" + import a.pkg.A.InnerA + val test: InnerA = TODO() + """.trimIndent()) shouldBe """ + import b.pkg.B.InnerB + val test: InnerB = TODO() + """.trimIndent() + } +}
\ No newline at end of file diff --git a/src/test/kotlin/com/replaymod/gradle/remap/mapper/kotlin/TestKotlinTypeAliases.kt b/src/test/kotlin/com/replaymod/gradle/remap/mapper/kotlin/TestKotlinTypeAliases.kt new file mode 100644 index 0000000..0d69341 --- /dev/null +++ b/src/test/kotlin/com/replaymod/gradle/remap/mapper/kotlin/TestKotlinTypeAliases.kt @@ -0,0 +1,42 @@ +package com.replaymod.gradle.remap.mapper.kotlin + +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 TestKotlinTypeAliases { + @Test + fun `remaps simple alias`() { + TestData.remapKt(""" + typealias A = a.pkg.A + val test: A = TODO() + """.trimIndent()) shouldBe """ + typealias A = b.pkg.B + val test: A = TODO() + """.trimIndent() + } + + @Test + fun `remaps outer class of inner class alias`() { + TestData.remapKt(""" + typealias Inner = a.pkg.A.Inner + val test: Inner = TODO() + """.trimIndent()) shouldBe """ + typealias Inner = b.pkg.B.Inner + val test: Inner = TODO() + """.trimIndent() + } + + @Test + fun `remaps inner class alias`() { + TestData.remapKt(""" + typealias InnerA = a.pkg.A.InnerA + val test: InnerA = TODO() + """.trimIndent()) shouldBe """ + typealias InnerA = b.pkg.B.InnerB + val test: InnerA = TODO() + """.trimIndent() + } +}
\ No newline at end of file |