[Commonizer] Implement ReturnTypeNullabilityCommonizationTest
^KT-48567
This commit is contained in:
committed by
Space
parent
661d89c67f
commit
f56419cbf8
+262
@@ -0,0 +1,262 @@
|
|||||||
|
/*
|
||||||
|
* 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 ReturnTypeNullabilityCommonizationTest : AbstractInlineSourcesCommonizationTest() {
|
||||||
|
|
||||||
|
fun `test two nullable functions`() {
|
||||||
|
val result = commonize {
|
||||||
|
outputTarget("(a, b)")
|
||||||
|
simpleSingleSourceTarget("a", "fun x(): Any?")
|
||||||
|
simpleSingleSourceTarget("b", "fun x(): Any?")
|
||||||
|
}
|
||||||
|
|
||||||
|
result.assertCommonized("(a, b)", "expect fun x(): Any?")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun `test two non-nullable functions`() {
|
||||||
|
val result = commonize {
|
||||||
|
outputTarget("(a, b)")
|
||||||
|
simpleSingleSourceTarget("a", "fun x(): Any")
|
||||||
|
simpleSingleSourceTarget("b", "fun x(): Any")
|
||||||
|
}
|
||||||
|
|
||||||
|
result.assertCommonized("(a, b)", "expect fun x(): Any")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun `test nullable and non-nullable function`() {
|
||||||
|
val result = commonize {
|
||||||
|
outputTarget("(a, b)")
|
||||||
|
simpleSingleSourceTarget("a", "fun x(): Any?")
|
||||||
|
simpleSingleSourceTarget("b", "fun x(): Any")
|
||||||
|
}
|
||||||
|
|
||||||
|
result.assertCommonized("(a, b)", "expect fun x(): Any?")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun `test two nullable properties`() {
|
||||||
|
val result = commonize {
|
||||||
|
outputTarget("(a, b)")
|
||||||
|
simpleSingleSourceTarget("a", "val x: Any? = Unit")
|
||||||
|
simpleSingleSourceTarget("b", "val x: Any? = Unit")
|
||||||
|
}
|
||||||
|
|
||||||
|
result.assertCommonized("(a, b)", "expect val x: Any?")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun `test two non-nullable properties`() {
|
||||||
|
val result = commonize {
|
||||||
|
outputTarget("(a, b)")
|
||||||
|
simpleSingleSourceTarget("a", "val x: Any = Unit")
|
||||||
|
simpleSingleSourceTarget("b", "val x: Any = Unit")
|
||||||
|
}
|
||||||
|
|
||||||
|
result.assertCommonized("(a, b)", "expect val x: Any")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun `test nullable and non-nullable - property`() {
|
||||||
|
val result = commonize {
|
||||||
|
outputTarget("(a, b)")
|
||||||
|
simpleSingleSourceTarget("a", "val x: Any? = Unit?")
|
||||||
|
simpleSingleSourceTarget("b", "val x: Any = Unit")
|
||||||
|
}
|
||||||
|
|
||||||
|
result.assertCommonized("(a, b)", "expect val x: Any?")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun `test different nullability typealias - function`() {
|
||||||
|
val result = commonize {
|
||||||
|
outputTarget("(a, b)")
|
||||||
|
simpleSingleSourceTarget(
|
||||||
|
"a", """
|
||||||
|
typealias X = Any?
|
||||||
|
fun x(): X
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
|
||||||
|
simpleSingleSourceTarget(
|
||||||
|
"b", """
|
||||||
|
typealias X = Any
|
||||||
|
fun x(): X
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
result.assertCommonized(
|
||||||
|
"(a, b)", """
|
||||||
|
expect class X
|
||||||
|
expect fun x(): X
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun `test different nullability typealias chain - function`() {
|
||||||
|
val result = commonize {
|
||||||
|
outputTarget("(a, b)")
|
||||||
|
simpleSingleSourceTarget(
|
||||||
|
"a", """
|
||||||
|
typealias Z = Any
|
||||||
|
typealias Y = Z?
|
||||||
|
typealias X = Y
|
||||||
|
fun x(): X
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
|
||||||
|
simpleSingleSourceTarget(
|
||||||
|
"b", """
|
||||||
|
typealias Z = Any
|
||||||
|
typealias Y = Z
|
||||||
|
typealias X = Y
|
||||||
|
fun x(): X
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
result.assertCommonized(
|
||||||
|
"(a, b)", """
|
||||||
|
typealias Z = Any
|
||||||
|
expect class Y
|
||||||
|
expect class X
|
||||||
|
fun x(): X
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun `test different nullability typealias chain - property`() {
|
||||||
|
val result = commonize {
|
||||||
|
outputTarget("(a, b)")
|
||||||
|
simpleSingleSourceTarget(
|
||||||
|
"a", """
|
||||||
|
typealias Z = Any
|
||||||
|
typealias Y = Z?
|
||||||
|
typealias X = Y
|
||||||
|
val x: X = Unit
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
|
||||||
|
simpleSingleSourceTarget(
|
||||||
|
"b", """
|
||||||
|
typealias Z = Any
|
||||||
|
typealias Y = Z
|
||||||
|
typealias X = Y
|
||||||
|
val x: X = Any
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
result.assertCommonized(
|
||||||
|
"(a, b)", """
|
||||||
|
typealias Z = Any
|
||||||
|
expect class Y
|
||||||
|
expect class X
|
||||||
|
expect val x: X
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun `test property - hierarchically`() {
|
||||||
|
val result = commonize {
|
||||||
|
outputTarget("(a, b)", "(c, d)", "(a, b, c, d)")
|
||||||
|
"a" withSource "val x: Any? = null"
|
||||||
|
"b" withSource "val x: Any = Unit"
|
||||||
|
"c" withSource "val x: Any = Unit"
|
||||||
|
"d" withSource "val x: Any = Unit"
|
||||||
|
}
|
||||||
|
|
||||||
|
result.assertCommonized("(a, b)", "expect val x: Any?")
|
||||||
|
result.assertCommonized("(c, d)", "expect val x: Any")
|
||||||
|
result.assertCommonized("(a, b, c, d)", "expect val x: Any?")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun `test member - property - hierarchically`() {
|
||||||
|
val result = commonize {
|
||||||
|
outputTarget("(a, b)", "(c, d)", "(a, b, c, d)")
|
||||||
|
|
||||||
|
simpleSingleSourceTarget(
|
||||||
|
"a", """
|
||||||
|
class X {
|
||||||
|
val x: Any?
|
||||||
|
}
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
|
||||||
|
simpleSingleSourceTarget(
|
||||||
|
"b", """
|
||||||
|
class X {
|
||||||
|
val x: Any
|
||||||
|
}
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
|
||||||
|
simpleSingleSourceTarget(
|
||||||
|
"c", """
|
||||||
|
class X {
|
||||||
|
val x: Any
|
||||||
|
}
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
|
||||||
|
simpleSingleSourceTarget(
|
||||||
|
"d", """
|
||||||
|
class X {
|
||||||
|
val x: Any
|
||||||
|
}
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
result.assertCommonized("(a, b)", """expect class X()""")
|
||||||
|
result.assertCommonized("(c, d)", """expect class X() { expect val x: Any }""")
|
||||||
|
result.assertCommonized("(a, b, c, d)", """expect class X()""")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun `test member - function - hierarchically`() {
|
||||||
|
val result = commonize {
|
||||||
|
outputTarget("(a, b)", "(c, d)", "(a, b, c, d)")
|
||||||
|
|
||||||
|
simpleSingleSourceTarget(
|
||||||
|
"a", """
|
||||||
|
class X {
|
||||||
|
fun x(): Any?
|
||||||
|
}
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
|
||||||
|
simpleSingleSourceTarget(
|
||||||
|
"b", """
|
||||||
|
class X {
|
||||||
|
fun x(): Any
|
||||||
|
}
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
|
||||||
|
simpleSingleSourceTarget(
|
||||||
|
"c", """
|
||||||
|
class X {
|
||||||
|
fun x(): Any
|
||||||
|
}
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
|
||||||
|
simpleSingleSourceTarget(
|
||||||
|
"d", """
|
||||||
|
class X {
|
||||||
|
fun x(): Any
|
||||||
|
}
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
result.assertCommonized("(a, b)", """expect class X()""")
|
||||||
|
result.assertCommonized("(c, d)", """expect class X() { expect fun x(): Any }""")
|
||||||
|
result.assertCommonized("(a, b, c, d)", """expect class X()""")
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user