[Commonizer] Implement HierarchicalClassAndTypeAliasCommonizationTest

^KT-45992
^KT-46061
This commit is contained in:
sebastian.sellmair
2021-05-27 14:28:54 +02:00
committed by Space
parent d5200e3688
commit b394dde339
2 changed files with 109 additions and 2 deletions
@@ -0,0 +1,107 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.commonizer.hierarchical
import org.jetbrains.kotlin.commonizer.AbstractInlineSourcesCommonizationTest
import org.jetbrains.kotlin.commonizer.assertCommonized
class HierarchicalClassAndTypeAliasCommonizationTest : AbstractInlineSourcesCommonizationTest() {
fun `test commonization of typeAlias and class`() {
val result = commonize {
outputTarget("(a, b)")
simpleSingleSourceTarget("a", "typealias X = Int")
simpleSingleSourceTarget("b", "class X")
}
result.assertCommonized("(a, b)", "expect class X")
result.assertCommonized("a", "typealias X = Int")
result.assertCommonized("b", "class X")
}
fun `test commonization of typeAlias and class hierarchically`() {
val result = commonize {
outputTarget("((a, b), (c, d))")
simpleSingleSourceTarget("a", "typealias X = Int")
simpleSingleSourceTarget("b", "typealias X = Long")
simpleSingleSourceTarget("c", "class X")
simpleSingleSourceTarget("d", "typealias X = Short")
}
result.assertCommonized("(a, b)", "expect class X")
result.assertCommonized("(c, d)", "expect class X")
result.assertCommonized("((a, b), (c, d))", "expect class X")
}
fun `test following typeAliases`() {
val result = commonize {
outputTarget("(a, b)")
simpleSingleSourceTarget(
"a", """
typealias X = NotX
class NotX(val constructorProperty: Int) {
val property: Int = 42
fun function() = 42
}
""".trimIndent()
)
simpleSingleSourceTarget(
"b", """
class X(val constructorProperty: Int) {
val property: Int = 42
fun function() = 42
}
""".trimIndent()
)
}
result.assertCommonized(
"(a, b)", """
expect class X expect constructor(expect val constructorProperty: Int) {
expect val property: Int
expect fun function(): Int
}
""".trimIndent()
)
}
fun `test following nested typeAliases`() {
val result = commonize {
outputTarget("(a, b)")
simpleSingleSourceTarget(
"a", """
typealias X = NotX
typealias NotX = ReallyNotX
class ReallyNotX(val constructorProperty: Int) {
val property: Int = 42
fun function() = 42
}
""".trimIndent()
)
simpleSingleSourceTarget(
"b", """
class X(val constructorProperty: Int) {
val property: Int = 42
fun function() = 42
}
""".trimIndent()
)
}
result.assertCommonized(
"(a, b)", """
expect class X expect constructor(expect val constructorProperty: Int) {
expect val property: Int
expect fun function(): Int
}
""".trimIndent()
)
}
}
@@ -33,7 +33,7 @@ class HierarchicalTypeAliasCommonizationTest : AbstractInlineSourcesCommonizatio
/**
* See: https://youtrack.jetbrains.com/issue/KT-45992
*/
fun `todo test typealias and class`() {
fun `test typealias and class`() {
val result = commonize {
outputTarget("(a,b)")
simpleSingleSourceTarget("a", """class X """)
@@ -45,7 +45,7 @@ class HierarchicalTypeAliasCommonizationTest : AbstractInlineSourcesCommonizatio
)
}
result.assertCommonized("(a,b)", "expect class X")
result.assertCommonized("(a,b)", "expect class X expect constructor()")
}
fun `test typealias to different classes`() {